| [ Web Proxy ] |
| Viewing: https://commandcode.ai/docs/context | [Back] [Original] |
Every model has a context window - a fixed token budget that has to hold the system prompt, your memory files, tool definitions, skills, and the entire conversation so far. Long sessions fill it. Command Code manages that budget for you: it shows you exactly where tokens are going (/context), automatically compacts the conversation in progressive tiers before the window overflows, recovers on its own when a request comes back "prompt too long", and tracks how many tokens compaction has reclaimed across the session.
This page is the complete reference: the window, the /context breakdown, the auto-compaction tiers, /compact and /compact-mode, savings tracking, automatic recovery, model switches, and the habits that keep context lean in the first place.
Everything the model sees on a request counts against one budget:
AGENTS.md files, across every memory tier that exists.taste.md, when taste learning is on.The window's size depends on the model - switch with /model and the budget changes with it. Command Code reads the active model's limit fresh on every check, so a mid-session switch immediately recalibrates everything below.
You don't have to run a command to know where you stand. The small context indicator next to the input stays hidden while there's plenty of room, then appears once you're within 20 percentage points of the auto-compact threshold (which fires at 90% of the window - see below), as a small bar counting down the percent left. On very large-window models it shows an earlier plain-text token count once usage passes ~180k tokens - a nudge that /compact is worth running for response quality long before a 1M window is at any risk of overflowing.
Run /context at any time for a full accounting of the window:
| Row | What it measures |
|---|---|
| System prompt | The assembled system prompt, measured per-section by the server at prompt-assembly time (falls back to a computed residual on the first turn). |
| Memory | Your memory files. If you've edited an AGENTS.md since the last request, the row is flagged (modified, refreshes next request). |
| Taste | taste.md, when present. |
| System tools | All built-in tool schemas, with a count. |
| MCP | Every connected MCP tool schema, labeled with the server names. |
| Skills | Loaded skill catalog entries. |
| Subagents | Loaded agent definitions. |
| Messages | The conversation itself - with user/assistant message counts. |
/compact before the summarize tier fires, a warning when conversation dominates the window, a note when MCP tool schemas are a big fixed cost, image counts (~1.5k tokens each), or a nudge to start a fresh session after a very long one.Command Code compacts reactively, in progressive tiers, keyed to the fraction of the active model's window the last turn actually used. The check runs before each model call; each tier only engages when the pressure has passed its threshold.
window used fires
0% quiet
40% /context starts warning
50% TIER 1 keep last 20 fast
tool calls only
80% TIER 2 keep last 10 fast
tool calls only
90% TIER 3 summarize always
older turns
100% overflow (never reached)
Tiers 1 and 2 only run when /compact-mode is fast. In the default mode nothing happens until 90%, then Tier 3 summarizes.
| Tier | Fires at | What it does | When it runs |
|---|---|---|---|
| 1 | 50% of the window | Trim the transcript to the last 20 tool calls (only when more than 20 exist) | fast compact mode only |
| 2 | 80% | Trim to the last 10 tool calls | fast compact mode only |
| 3 | 90% | Summarize older messages into a handoff brief | Always, in any compact mode |
The trim tiers are pure and model-free: they remove whole tool_use/tool_result pairs - the oldest first - and nothing else. Your messages and the model's prose survive; only stale tool output (old file reads, old command output) is dropped. These tiers only run when /compact-mode is set to fast; in the default mode Command Code skips straight to summarization at 90%.
At 90%, Command Code makes a real model call that compresses the older part of the conversation into a structured handoff brief - goal, a walk through your turns, in-flight work, pending tasks, files touched, decisions made, errors hit, and the exact resume point. The brief replaces the older messages; you'll see it in the transcript prefixed with "This is an auto-compacted summary of the earlier conversation".
Summarization is deliberately conservative:
Compaction changes what is sent to the model, not what is stored. The session log is append-only: a compaction is recorded as its own entry in the session tree, pointing at the summary and the first kept message. Your full history remains on disk - checkpoint restore, /rewind, and session forking still see everything.
When the summarize tier engages you'll see a status line while it runs, then a feed entry reporting the result:
Compacted conversation. Saved ~41,300 tokens (total ~112,000 this session).
Every compaction event - auto, manual, or model-switch - reports its own savings and the session's running total. The totals are persisted to the session's metadata as they accrue, so they survive a restart: resume with --resume and the "total ~N this session" figure keeps counting from where it left off.
/compact runs the same Tier-3 summarization immediately, without waiting for the 90% threshold. The best time to run it is before auto-compact fires - the /context tips start suggesting it at 50%, and urgently past 80% - because compacting at a moment you choose (a task boundary, right after a conclusion is reached) gives the summarizer a clean story to compress, instead of whatever mid-task state the threshold happens to catch.
After a compact, the reported context usage restarts against the model's window; if there was nothing worth compacting you'll get "Conversation is already compact." A failure reports an error and leaves the conversation untouched.
/compact-mode selects between two auto-compaction strategies (also available in /config; the choice persists in your user config):
| Mode | Behavior |
|---|---|
default | Summarize-only. Nothing happens until 90%, then Tier 3 summarizes. Maximum context fidelity - every tool result stays available until the window genuinely runs out. |
fast | All three tiers. Old tool results start being trimmed at 50% (keep last 20) and 80% (keep last 10), before summarization at 90%. Leaner requests and cheaper turns in long tool-heavy sessions, at the cost of older tool output leaving context earlier. |
The setting is read live - a mid-session switch applies from the next check.
If a request is rejected by the provider as too long - usage estimates drifted, or a single giant tool result blew past the window - Command Code doesn't surface an error and stop. The error is classified, the window is compacted (summarized) on the spot, and the request retried once with the compacted transcript. Only a second consecutive failure surfaces. In practice the reactive tiers fire first and this path stays rare; it exists so the edge case costs you a retry, not a turn.
/model recalibrates - and can pre-trimThe tier thresholds are fractions of the current model's window, re-read on every check, so switching models instantly moves the goalposts:
Compaction is the safety net, not the strategy. The cheapest token is the one that never enters the window:
agent tool (like the built-in Explore agent) burns its own context window reading files and searching, and only its final report enters yours. Sweeping a codebase in the main session can pull tens of thousands of tokens of file contents into your window; the same sweep delegated costs you a few hundred./clear between unrelated tasks: Finished one piece of work and starting another? A fresh conversation beats dragging the old task's tool results along - and beats making a future summary of two unrelated tasks compete for space. Use /clear at real boundaries (memory files and skills are re-loaded; the conversation restarts)./context shows exactly what each is costing; /mcp manages them./compact right after finishing a sub-task produces a better brief than an auto-compact in the middle of the next one./context, /compact, /compact-mode, /clear, and /model./context breakdown.| Web Proxy Viewer | New URL | Original Page |