Skip to main content

Anatomy of Context Management

0–80%+ usage playbook, auto-compact, memory strategies, reset rituals.

Context Management

The 0–80%+ usage playbook for Claude Code β€” auto-compact tuning, memory strategies, and reset rituals that keep your AI teammate sharp.


TL;DR​

  • Context = everything Claude remembers right now (messages, files, tool outputs, thoughts).
  • The window is finite. When it fills, quality drops and the session breaks.
  • Watch the meter: 0–60 % work normally Β· 60–80 % compact Β· 80 %+ reset.
  • Auto-compact is your best friend β€” tune it in .claude/settings.json.
  • Memory strategies: ephemeral, summaries, project (CLAUDE.md), session, vector.
  • Reset rituals: soft (compact + summarize) and hard (/clear + reload essentials).

Why this matters​

Think of context as RAM for your AI teammate. Stuff too much in, and everything slows down, hallucinates, and crashes. Curate it like a senior engineer curates their desk: only what you need, where you need it, when you need it.

Bottom line: Context is your most precious resource. Manage it deliberately.


The Big Picture​

Bottom line: Sources fill β†’ meter rises β†’ compact, summarize, or reset.


What Is Context, Really?​

Context is the live working memory of the session. It includes:

SourceWhat it containsImpact
User messagesYour prompts & clarificationsLow–Med
Loaded filesFiles read or @-referencedπŸ”΄ High
Tool outputsBash, Grep, MCP, web fetchπŸ”΄ High
Search results / webPage content pulled in🟠 Med–High
Claude's thoughtsReasoning trace🟑 Med
System prompts & rulesCLAUDE.md, settingsLow (but always loaded)
Long outputs / diffs / logsLogs, stack tracesπŸ”΄ High

πŸ’‘ Tip: Load only what you need. Summarize the rest. Drop irrelevant.


Context Usage Meter β€” What the Numbers Mean​

ZoneRangeWhat it meansWhat to do
🟒 Green0–60 %Plenty of headroomWork normally, add details freely
🟑 Yellow60–80 %Time to compactStart auto-compact, remove stale info
🟠 Orange80–90 %High riskModels get forgetful, errors creep in
πŸ”΄ Red90 %+CriticalContext overflow risk β†’ RESET NOW

πŸ’‘ Tip: Watch the meter in the status bar. Don't wait for problems.


Auto-Compact β€” Your Best Friend​

Auto-compact watches usage and automatically summarizes and prunes older content when thresholds are hit. Tune it in .claude/settings.json:

{
"env": {
"MAX_THINKING_TOKENS": "100000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50",
"NO_COLOR": "1"
},
"features": {
"autoCompact": true,
"autoCompactMode": "balanced",
"autoCompactMinPct": "50",
"autoCompactMaxPct": "75"
}
}

Settings reference​

SettingWhat it does
MAX_THINKING_TOKENSUpper bound for thinking/output tokens
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEStart compacting when usage hits this %
autoCompactEnable automatic summarization & pruning
autoCompactModeaggressive Β· balanced Β· conservative
autoCompactMinPctNever compact below this %
autoCompactMaxPctHard ceiling that forces compact

πŸ’‘ Tip: A 50 % override is the sweet spot for most teams. Aggressive only if you regularly hit 80 %.

Mode trade-offs​

ModeProsCons
aggressiveLong sessions, low costMore fidelity loss
balanced ⭐Default recommendedPredictable trade-off
conservativeMaximum fidelityRuns out of context faster

Memory Strategies β€” Keep What Matters​

Different facts deserve different homes:

TypeWhat it isLifetimeWhere
Ephemeral (short-term)Active task chatterSession onlyContext window
SummariesCondensed long threadsSession or docsIn-session or docs/sessions/
Project memoryConventions, decisions, patternsPermanentCLAUDE.md
Session summariesEnd-of-session capturePermanentdocs/sessions/YYYY-MM-DD.md
Vector memoryLong-term semantic recallPermanentVector DB or filesystem

πŸ’‘ Tip: Right-size memory β€” active (window) β†’ medium (summaries) β†’ durable (project).

The memory hierarchy in code​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ACTIVE CONTEXT (window) β”‚ ← 0-80% target
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ SESSION SUMMARIES (docs/) β”‚ ← persisted on /clear
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ CLAUDE.md (project memory) β”‚ ← always loaded
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ VECTOR DB / search index β”‚ ← retrieved on demand
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What to Keep vs. Drop​

Reduce noise without losing value:

StrategyWhen to useExample
SummarizeLong exchanges"Summarize our work so far."
ExtractKey facts, decisions, actions"List decisions & action items."
CollapseLong outputsReplace with placeholder: <large log collapsed>
ArchiveReference laterMove details to docs/notes/2026-05-12.md
Chunk & IndexRecall laterStore in vector memory
FocusNarrow scope"Focus mode: next 3 steps only."

πŸ’‘ Tip: Compress early, not late. Small compactions beat giant ones.


Reset Rituals β€” Clean Breaks That Unlock Quality​

Soft Reset (Lighten the Load) β€” 5 steps​

Use when 60–80 %. Keeps the thread alive.

  1. Summarize current work in one paragraph.
  2. Archive details to docs/sessions/<date>.md.
  3. Clear irrelevant context (close files, drop outputs).
  4. Re-state the goal in one sentence.
  5. Continue with a leaner window.

Hard Reset (Start Fresh) β€” 5 steps​

Use at 80 %+ or when quality has clearly degraded.

  1. /clear β€” wipe session.
  2. Restate the goal in one sentence.
  3. Re-load only essential files.
  4. Re-attach key context (links to docs, decisions).
  5. Rebuild from a clean slate.

πŸ’‘ Tip: When quality drops, reset. Don't fight a dirty context.


Step-by-Step Setup​

1. Enable auto-compact in .claude/settings.json​

{
"env": { "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50" },
"features": {
"autoCompact": true,
"autoCompactMode": "balanced",
"autoCompactMinPct": "50",
"autoCompactMaxPct": "75"
}
}

2. Add session-end summarizer hook​

"hooks": {
"SessionEnd": [
{ "matcher": "*",
"hooks": [{ "type": "command", "command": "./scripts/save-summary.sh" }] }
]
}

scripts/save-summary.sh:

#!/usr/bin/env bash
DATE=$(date +%Y-%m-%d)
mkdir -p docs/sessions
echo "# Session $DATE" > "docs/sessions/$DATE.md"
echo "_Auto-saved by Claude Code_" >> "docs/sessions/$DATE.md"

3. Add a /status slash command​

.claude/commands/status.md:

---
description: Show current context usage & session stats
usage: /status
---
Report:
- Context usage % and zone (green/yellow/orange/red)
- Window tokens used / total
- Auto-compact state & last compact age
- Files loaded
- Tool calls so far
- Memories active
- Session age
- Suggested next ritual (none / soft / hard reset)

4. Add a /memory slash command​

.claude/commands/memory.md:

---
description: Inspect memory & session summaries
usage: /memory
---
Show:
- Active context window items (top consumers)
- Recent session summaries (docs/sessions/)
- Project memory entries (CLAUDE.md)
- Vector memory hits (if enabled)

5. Make /status a muscle-memory habit​

Run it every ~10 minutes during long sessions.


Monitoring & Tools​

ToolPurpose
Status barLive % usage & mode
/statusDetailed context stats
/memoryInspect memory & summaries
/clearWipe current session context
Logs (.claude/logs/)Historical usage trace
HooksAuto-compact & alerts

Example /status output​

Context Usage: 68% (YELLOW)
Window Tokens: 68,340 / 100,000
Auto-Compact: ON (trigger 50%)
Files Loaded: 12
Tool Calls: 43
Memories: 3
Last Compact: 2m ago
Session Age: 47m
Next Ritual: ⚠️ Consider soft reset

Variants for Different Team Settings​

πŸ‘€ Solo developer​

Keep it light. autoCompactMode: balanced + /status every 15 min.

{ "features": { "autoCompact": true, "autoCompactMode": "balanced" } }

πŸ‘₯ Small team (2–10)​

Standardize session-end summaries so handoffs work.

"hooks": {
"SessionEnd": [{ "matcher": "*",
"hooks": [{ "type": "command", "command": "./scripts/save-summary.sh" }] }]
}

Commit docs/sessions/ so the team sees the trail.

🏒 Enterprise / regulated​

  • Cap costs: lower MAX_THINKING_TOKENS, set autoCompactMode: aggressive.
  • Audit memory: log every compact + reset to SIEM.
  • PII discipline: never persist sensitive context to disk.
{
"env": { "MAX_THINKING_TOKENS": "50000", "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "40" },
"features": { "autoCompactMode": "aggressive" }
}

🌍 Open-source / community​

  • Document the team's context conventions in CONTRIBUTING.md.
  • Provide a /onboard command that loads only the essentials.
  • Use vector memory for the codebase index so context stays lean.

Bottom line: Same playbook, escalating discipline.


Anatomy of a Single Reset β€” Soft Reset, Zoomed In​

Step 1 β€” Summarize:
"We refactored auth flow. Tests green. PR open."

Step 2 β€” Archive:
Save the summary + key decisions to:
docs/sessions/2026-06-26.md

Step 3 β€” Clear:
Drop loaded files: legacy/auth-old.ts, old logs
Keep: src/auth/*.ts, CLAUDE.md

Step 4 β€” Re-state goal:
"Ship auth refactor PR #421 by EOD."

Step 5 β€” Continue:
Next 3 steps: review feedback, update docs, request review.

Common Patterns & Recipes​

Pattern 1 β€” "Summarize and continue" prompt​

Summarize what we've done so far in 5 bullets.
Save decisions to docs/sessions/<date>.md.
Then continue with: <next goal>.

Pattern 2 β€” Drop heavy artifacts​

Drop the contents of legacy/old-service.ts from context.
Replace with: "<archived, see git log>".

Pattern 3 β€” Focus mode​

Focus mode: only consider files under src/auth/.
Ignore tests and docs for the next 3 steps.

Pattern 4 β€” Auto-compact override mid-session​

/config set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40

Pattern 5 β€” Session checkpoint​

Checkpoint: save current state, key files, and goal to
docs/sessions/checkpoint-<timestamp>.md so I can resume tomorrow.

Pattern 6 β€” Vector memory recall​

Search project memory for "auth decision rationale 2026".
Load only the top 3 results.

Habits That Keep You in the Green​

  1. 🎯 Define the goal early β€” and keep it visible.
  2. πŸ“‚ Load files just-in-time β€” not all at once.
  3. πŸ“ Summarize frequently β€” small > large compactions.
  4. πŸ—„οΈ Archive details to docs/ or memory.
  5. πŸ” Ask for focused outputs β€” "the 3 most important issues".
  6. βš™οΈ Use auto-compact and tune the threshold.
  7. πŸ” Reset when quality drops (don't be stubborn).
  8. βœ… Review what matters β€” not everything.

πŸͺ™ Golden Rule: Curate ruthlessly. Keep context small, relevant, and current.


Anti-Patterns ❌ (Context Killers)​

  • πŸ—‘οΈ Dumping entire codebases into context.
  • πŸ’€ Keeping solved threads alive for sentimental reasons.
  • πŸ’¬ Long chats with no value β€” every turn is tokens.
  • πŸ“œ Massive logs inline β€” collapse them.
  • πŸ™ˆ Ignoring the usage meter until it's red.
  • πŸ›‘ Never resetting β€” fighting a dirty context.
  • πŸ—―οΈ Verbose outputs β€” ask Claude to be concise.
  • πŸ€” Trusting questions over signals β€” believe the meter.

⚠️ These lead to hallucinations, slowdowns, and session failures.


Troubleshooting​

SymptomCauseFix
Slow responsesWindow > 70 %Compact or soft reset
Hallucinations / wrong factsStale contextHard reset + reload essentials
Repeating itselfLost focusRe-state goal in one sentence
Forgets file you mentionedAuto-compacted it outRe-attach with @file
Cost spikeHigh MAX_THINKING_TOKENSLower cap, enable auto-compact
Auto-compact too aggressiveMode too tightSwitch to balanced
Session crashes at 100 %No auto-compactEnable + lower threshold

Quick Checklist (before any long session)​

  • βœ… Goal restated in one sentence
  • βœ… Only needed files loaded
  • βœ… Recent decisions captured in CLAUDE.md
  • βœ… Irrelevant info dropped
  • βœ… Summaries updated
  • βœ… Next steps clear
  • βœ… Usage < 60 %

πŸ’‘ Tip: Run this checklist when you feel Claude slowing down.


Getting Started (6 steps)​

  1. Watch your usage meter (stay < 60 %).
  2. Define the goal in one sentence.
  3. Load only essential files.
  4. Summarize & compact regularly.
  5. Persist important info to CLAUDE.md.
  6. Reset when quality drops.

Minimal Starter Config​

{
"env": {
"MAX_THINKING_TOKENS": "100000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
},
"features": {
"autoCompact": true,
"autoCompactMode": "balanced",
"autoCompactMinPct": "50",
"autoCompactMaxPct": "75"
},
"hooks": {
"SessionEnd": [
{ "matcher": "*",
"hooks": [{ "type": "command", "command": "./scripts/save-summary.sh" }] }
]
}
}

Glossary​

  • Context window β€” Total tokens Claude can "see" right now.
  • Auto-compact β€” Automatic summarization to free space.
  • Soft reset β€” Compact + archive + continue.
  • Hard reset β€” /clear + reload essentials.
  • Ephemeral memory β€” Lives only in the session.
  • Project memory β€” Persisted in CLAUDE.md.
  • Vector memory β€” Semantic search over long-term knowledge.
  • Session summary β€” Compact record of what happened.
  • Compaction threshold β€” The % usage at which auto-compact triggers.

Further Reading​

  • Search: "Claude Code context window management"
  • Search: "LLM context compression techniques"
  • Search: "retrieval augmented generation memory strategies"
  • Search: "long-running AI agent session design"

πŸͺ™ Remember​

Context is your most precious resource.

  • 🧹 Keep it lean
  • 🎯 Keep it relevant
  • πŸ“… Keep it current
  • πŸ”„ Compact often
  • πŸ†• Reset fearlessly
  • πŸ“ Measure always
  • πŸš€ Deliver better