Help us improve
Share bugs, ideas, or general feedback.
From claude-code-expert
Manages Claude Code context windows with token arithmetic, anchor budget math, compact strategies, progressive loading, and large codebase partitioning.
npx claudepluginhub markus41/claude --plugin claude-code-expertHow this skill is triggered — by the user, by Claude, or both
Slash command
/claude-code-expert:context-budgetingThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Master the art of managing Claude Code's context window for maximum productivity.
Guides managing Claude Code context window with /compact, /clear commands, auto-compaction config, sub-agents, targeted reads, background tasks, and conversation flows for long sessions.
Optimizes Claude Code session context and token usage with compaction (/compact), subagents, MCP audits, and prompt strategies. Use when usage >70%, sessions slow, or budget depleting.
Optimizes Claude Code session context by explaining major consumers like metadata, images, file reads, and bash output, with strategies including screenshot compression, /compact usage, and reduced re-reads.
Share bugs, ideas, or general feedback.
Master the art of managing Claude Code's context window for maximum productivity.
Help users understand exactly where context is consumed, plan sessions that avoid hitting limits, and recover gracefully when context gets tight.
| Model | Context Window | Practical Limit |
|---|---|---|
| Opus 4.6 | 200,000 tokens | ~180,000 usable |
| Sonnet 4.6 | 200,000 tokens | ~180,000 usable |
| Haiku 4.5 | 200,000 tokens | ~180,000 usable |
The ~20k overhead comes from system prompt, tool definitions, and framework messages that are always present.
Every request to Claude includes ALL of the following:
| Component | Loaded When | Typical Size | Cached? |
|---|---|---|---|
| System prompt | Every turn | 3-5k tokens | Yes (after turn 1) |
| CLAUDE.md (all levels) | Every turn | 2-20k tokens | Yes (after turn 1) |
| Rules (unconditional) | Every turn | 1-10k tokens | Yes (after turn 1) |
| Rules (path-scoped) | When matching files opened | 0-5k tokens | Partially |
| Skill descriptions | Every turn | 1-5k tokens | Yes |
| MCP tool schemas | Every turn | 2-15k tokens | Yes |
| Conversation history | Every turn (grows) | 5-150k tokens | Partially |
| Tool results (latest) | Current turn | 0-10k tokens | No |
Context grows with every turn because conversation history accumulates:
Fixed overhead (always loaded):
System prompt ≈ 4,000 tokens
CLAUDE.md files ≈ 5,000 tokens (varies)
Unconditional rules ≈ 3,000 tokens (varies)
Skill descriptions ≈ 2,000 tokens (varies)
MCP tool schemas ≈ 5,000 tokens (varies)
─────────────────────────────────────────────────
Total fixed overhead ≈ 19,000 tokens
Variable (grows with session):
Conversation history = grows per turn
Tool results = per tool call
Loaded skill bodies = when skills activated
Path-scoped rules = when matching files read
Your effective working budget = 200,000 - fixed overhead - safety margin
Anchors are pieces of context you want to survive /compact. Without anchoring, compaction summarizes everything, potentially losing critical state.
Rule of thumb: anchors should consume < 10% of your context window.
Context window: 200,000 tokens
Target anchor budget: 20,000 tokens (10%)
Available for conversation: 180,000 - fixed overhead
Priority anchoring targets:
| Signal | Action |
|---|---|
| Auto-compact triggers (system message) | Let it happen, but consider manual compact first |
| Context utilization > 70% | Good time for proactive compact |
| Shifting to a new sub-task | Compact to clear old context |
| After a long research phase | Compact before implementation |
| After reading many files | Compact to summarize findings |
When compacting, provide a focus to guide summarization:
/compact Focus on the auth middleware refactor: keep the API contract, test failures, and migration plan
Good focus strings:
Bad focus strings:
Skills use progressive loading:
With 30 skills:
@path imports for large documents (loaded but can be excluded)Signs you need to partition:
Main context: task planning, implementation
└── Subagent 1: research existing patterns (Haiku)
└── Subagent 2: explore test coverage (Haiku)
└── Subagent 3: review dependencies (Haiku)
Each subagent gets its own 200k context window. Only summaries return to main context.
| Anti-Pattern | Problem | Fix |
|---|---|---|
| CLAUDE.md > 500 lines | Eats working budget every turn | Split into rules and skills |
| 10+ unconditional rules | High fixed overhead | Path-scope where possible |
| All skills model-invocable | Description tokens add up | Use disable-model-invocation: true for manual-only skills |
| Too many MCP servers | Schema tokens accumulate | Disconnect unused servers (/mcp) |
| No compaction strategy | Hit limit unpredictably | Compact proactively at 70% |
| Reading entire large files | Each read adds thousands of tokens | Use Grep to find specific content |
| Ignoring auto-memory | Re-discovering the same facts each session | Let auto-memory persist findings |
/cost → see current token usage
/compact → manually compact context
/memory → see what CLAUDE.md/rules are loaded
/mcp → see MCP server token costs
/model → check/change current model
| Metric | Target |
|---|---|
| Fixed overhead | < 25k tokens (12.5% of 200k) |
| Working budget | > 150k tokens |
| Compact trigger | 70% utilization |
| Anchor budget | < 20k tokens |
| Skills active at once | ≤ 5 |
| MCP servers connected | ≤ 5 |