Context & Compaction

Code CLI manages a context window that includes your conversation, file contents, tool outputs, and system instructions. As the context fills, compaction strategies keep the session productive.

How Context Works

On session start, Code CLI loads:

  • CLAUDE.md or CODECLI.md — Project instructions
  • .gitignore — File exclusion rules
  • Package files — Dependencies and project structure
  • Recent files — Recently modified files in the project

As you interact, the agent reads files, executes tools, and accumulates context.

Auto-Compaction

Compaction runs automatically when context usage crosses configurable thresholds:

ThresholdStrategyWhat Happens
50%Light pruneRemove old tool outputs, compress summaries
65%MicrocompactCompress older conversation turns
75%Aggressive pruneStrip non-essential context, keep active files
85%Preemptive compactFull context summarization
95%EmergencyMaximum compression to prevent overflow
codecli.json
json
"compaction": {
"auto": true,
"prune": true,
"microcompact": true,
"microcompact_age_ms": 300000,
"protected_tail": 4,
"progressive": true,
"thresholds": {
"light_prune": 0.50,
"microcompact": 0.65,
"aggressive_prune": 0.75,
"preemptive_compact": 0.85,
"emergency": 0.95
}
}

Manual Compaction

Use /compact or set --compact-threshold 0.5 to control when compaction triggers.

PreviousPermissionsNextCommands