# Context Budget Discipline

> Use when sessions run long, adding subagents, fetching large files, or planning context-heavy work. SELECT/WRITE/COMPRESS/ISOLATE discipline.

- **Type:** Skill
- **Install:** `agentstack add skill-redtropig-harness-anchor-context-budget-discipline`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Redtropig](https://agentstack.voostack.com/s/redtropig)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Redtropig](https://github.com/Redtropig)
- **Source:** https://github.com/Redtropig/harness-anchor/tree/main/skills/context-budget-discipline

## Install

```sh
agentstack add skill-redtropig-harness-anchor-context-budget-discipline
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Context Budget Discipline

Context is a finite resource. Every token competes for the model's attention. The "lost-in-the-middle" phenomenon is real — content buried in 50% of the window position is least attended.

This skill applies four operations to keep the budget sane.

## The Four Operations

```
SELECT     load context just-in-time, not all-at-once
WRITE      persist to disk; let the filesystem remember, not chat
COMPRESS   summarize older turns when window fills
ISOLATE    delegate so child work doesn't pollute parent context
```

### SELECT — pull, don't push

Default behaviour: don't preemptively load files. Wait until they're needed.

- ❌ "Let me read all 30 .cpp files to understand the project."
- ✅ "I'll consult PROJECT-TOC.md first, then read only the 2 files the task touches."

### WRITE — disk is cheap, context is expensive

Anything reusable across turns should live on disk:

- Active feature → `feature_list.json`
- Decisions / rationale → `progress.md` or `docs/decisions/`
- "What I just did" → `session-handoff.md`

Anti-pattern: re-explaining the same plan/decision in every reply.

### COMPRESS — summarize old turns when window pressure rises

When context usage > 70% of model window, mid-session compaction can help. But per [Anthropic Nov 2025](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents):

> "Compaction preserves continuity, but doesn't give the agent a clean slate. Context anxiety can still persist."

**Flush before you compress.** Before compaction/reset — or when the PostToolUse watermark fires (T1 "Context is filling" = flush now; T2 "Context is heavily filled" = wrap up via /session-end + fresh session) — write chat-only durable memory to disk first: golden-rule stubs
(`capturing-golden-rules`), feature status, a milestone `progress.md` entry. After a compaction,
do NOT backfill memory from the summary: reconstruct from on-disk evidence (git diff, test
output, progress.md) and state uncertainty where evidence is missing.

If compaction isn't enough → use `/session-end` to write a rich handoff, then suggest the user start a **fresh context** (context reset > compaction for long runs).

### ISOLATE — child work doesn't bleed up

Subagents (`/verify`, `cpp-build-doctor`, etc.) run in **fresh context**. They:
- Don't inherit conversational baggage
- Return a fixed-structure result (diagnosis / evidence / recommendation)
- Don't dump their working notes into your context

If you delegate a noisy task, ask for a SUMMARY back, not a transcript.

## Token Budget Reference

| Tier | Budget | Source |
|---|---|---|
| Tier 1 (always loaded) | ~3000 tokens cap; measured at v0.10.0: generic ≈1160 t, C/C++ ≈1580 t | SessionStart hook injection (hard-capped 12000 chars, meta-skill injected slimmed; `${CLAUDE_PLUGIN_ROOT}/scripts/measure-context.sh` re-measures both baselines) |
| System prompt + tools | Model-defined | Outside your control |
| Working context | Most of remaining window | Your edits + reads accumulate here |

## State-file budgets

Hot state files carry fixed budgets. The SessionStart banner warns (warn-only) when one is
exceeded; `/session-end` offers deterministic archival via `state-archive.mjs`.

| File | Hot window | Sentinel |
|---|---|---|
| `progress.md` | newest 20 sections | 64KB |
| `feature_list.json` | live features + 10 newest `pass` | 32KB |
| `golden-rules.md` | prune — never archived | 8KB |
| `AGENTS.md` | keep it a map (~80 lines) | 8KB |
| `session-handoff.md` | overwritten each session | 4KB |

Archives (`progress-archive.md`, `feature_archive.json`) are grep-only — never load whole.

## When to invoke this skill

- A session has been going for >2 hours
- You notice your replies summarizing already-discussed content (you're losing focus)
- About to read a large file (>500 lines) — ask: do I need ALL of it?
- About to dispatch a subagent — confirm it returns summary, not log
- Context monitor / Claude Code warns about token usage

## Practical moves

When budget pressure rises:

1. **Stop and write handoff.** Run `/session-end` if features are in flight.
2. **Hard-truncate reads.** Prefer `head -50`, `grep -A 5`, line range in Read tool — over reading whole files.
3. **Drop tool definitions.** If you have many MCP tools loaded and none are relevant to current work, that's overhead — but you can't control this from inside the session.
4. **Consider context reset.** A fresh session with rich handoff often outperforms continuing a stale one.

## Calibrated estimates

You can roughly estimate context use by:

- 1 token ≈ 4 chars (English) or 1-2 chars (Chinese)
- A 200-line code file ≈ 1500-2500 tokens
- A medium SKILL.md ≈ 1000-2000 tokens
- Your own multi-paragraph replies ≈ 200-500 tokens each

When the user asks "how much room do we have?", be honest about the estimate.

## Looking up context engineering research

For specific patterns (e.g., compaction algorithms, attention windowing, RAG indexing strategies) — invoke the `docs-lookup` skill. Pattern names evolve fast in this area; don't rely on memory.

Typical entry query: `context engineering 2026` or ` llm`.

## Related

- `using-harness-anchor` — Tier 1 injection budget reference
- `feature-state-keeper` — what to write to disk
- `project-indexing` — TOC as compressed file index

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Redtropig](https://github.com/Redtropig)
- **Source:** [Redtropig/harness-anchor](https://github.com/Redtropig/harness-anchor)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-redtropig-harness-anchor-context-budget-discipline
- Seller: https://agentstack.voostack.com/s/redtropig
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
