3. Context Management Internals
Confidence: 80% (Tier 2 - Partially Official) Sources:
- platform.claude.com/docs (Tier 1)
- Observed behavior (Tier 2)
Claude Code operates within a fixed context window (~200K tokens, varies by model).
Context Budget Breakdown
┌─────────────────────────────────────────────────────────────┐
│ CONTEXT BUDGET (~200K tokens) │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ System Prompt (~5-15K) │ │
│ │ • Tool definitions │ │
│ │ • Safety instructions │ │
│ │ • Behavioral guidelines │ │
│ │ • See detailed breakdown below ↓ │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ CLAUDE.md Files (~1-10K) │ │
│ │ • Global ~/.claude/CLAUDE.md │ │
│ │ • Project /CLAUDE.md │ │
│ │ • Local /.claude/CLAUDE.md │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ Conversation History (variable) │ │
│ │ • Your prompts │ │
│ │ • Claude's responses │ │
│ │ • Tool call records │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ Tool Results (variable) │ │
│ │ • File contents from Read │ │
│ │ • Command outputs from Bash │ │
│ │ • Search results from Grep │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ Reserved for Response (~40-45K) │ │
│ │ • Claude's thinking │ │
│ │ • Generated code/text │ │
│ └──────────────────────────────────────────────────────┘ │
│ │
│ USABLE = Total - System - Reserved ≈ 140-150K tokens │
│ │
└─────────────────────────────────────────────────────────────┘System Prompt Contents
Confidence: 100% (Tier 1 - Official Anthropic Documentation) Sources:
Claude system prompts (~5-15K tokens) are publicly published by Anthropic as part of their transparency commitment. These prompts define:
Core Components:
- Tool definitions: Bash, Read, Edit, Write, Grep, Glob, Task, TodoWrite
- Safety instructions: Content policies, refusal patterns (see Security Hardening)
- Behavioral guidelines: Task-first approach, MVP-first, no over-engineering
- Context instructions: How to gather and use project context
Important Distinctions:
- Claude.ai/Mobile: Published prompts available publicly
- Anthropic API: Different default instructions, configurable by developers
- Claude Code CLI: Agentic coding assistant with context-gathering behavior
Community Analysis (for deeper understanding):
- Simon Willison's Claude 4 Analysis (May 2025): Deep-dive into thinking blocks, search rules, safety guardrails
- PromptHub Technical Breakdown (June 2025): Detailed analysis of prompt engineering patterns
→ Cross-reference: For security implications, see Section 5: Permission & Security Model
Note: Claude Code system prompts may differ from Claude.ai/mobile versions. The above sources cover the Claude family; Code-specific prompts are integrated into the CLI tool's behavior.
Auto-Compaction
Confidence: 75% (Tier 2 - Community-verified with research backing)
When context usage exceeds a threshold, Claude Code automatically summarizes older conversation turns:
| Source | Reported Threshold | Notes |
|---|---|---|
| VS Code extension | ~75% usage (25% remaining) | GitHub #11819 (Nov 2025) |
| CLI version | 1-5% remaining | More conservative than VS Code |
| PromptLayer analysis | 92% | Historical observation |
| Steve Kinney | 95% | Session Management Guide (Jul 2025) |
User-triggered /compact | Anytime | Manual control |
What happens during compaction:
- Older conversation turns are summarized
- Tool results are condensed
- Recent context is preserved in full
- The model receives a "context was compacted" signal
Performance Impact (Research-backed):
Recent research and practitioner observations confirm quality degradation with auto-compaction:
- LLM performance drops 50-70% on complex tasks as context grows from 1K to 32K tokens (Context Rot Research, Jul 2025)
- 11 out of 12 models fall below 50% of their short-context performance at 32K tokens (NoLiMa benchmark)
- Auto-compact loses nuance and breaks references through repeated compression cycles (Claude Saves Tokens, Forgets Everything, Jan 2026)
- Attention mechanism struggles with retrieval burden in high-context scenarios
Community Consensus: Manual /compact at logical breakpoints > waiting for auto-compact to trigger.
Recommended Strategy (Lorenz, 2026):
| Context % | Action | Rationale |
|---|---|---|
| 70% | Warning - Plan cleanup | Early awareness |
| 85% | Manual handoff recommended | Prevent auto-compact degradation |
| 95% | Force handoff | Severe quality degradation |
User control: Use /compact manually to trigger summarization at logical breakpoints, or use session handoffs (see Session Handoffs) to preserve intent over compressed history.
Context Preservation Strategies
| Strategy | When to Use | How |
|---|---|---|
| Sub-agents | Exploratory tasks | Task tool for isolated search |
| Manual compact | Proactive cleanup | /compact command |
| Clear session | Fresh start needed | /clear command |
| Specific reads | Know what you need | Read exact files, not directories |
| CLAUDE.md | Persistent context | Store conventions in memory files |
Session Degradation Limits
Confidence: 70% (Tier 2 - Practitioner studies, arXiv research)
Claude Code's effectiveness degrades predictably under certain conditions:
| Condition | Observed Threshold | Symptom |
|---|---|---|
| Conversation turns | 15-25 turns | Loses track of earlier constraints |
| Token accumulation | 80-100K tokens | Ignores requirements stated early in session |
| Problem scope | >5 files simultaneously | Inconsistent changes, missed files |
Success rates by scope (from practitioner studies):
| Scope | Success Rate | Example |
|---|---|---|
| 1-3 files | ~85% | Fix bug in single module |
| 4-7 files | ~60% | Refactor feature across components |
| 8+ files | ~40% | Codebase-wide changes |
Mitigation strategies:
- Checkpoint prompts: "Before continuing, recap the current requirements and constraints."
- Session resets: Start fresh for new tasks (
/clear) - Scope tightly: Break large tasks into focused sub-tasks
- Use sub-agents: Delegate exploration to
Tasktool to preserve main context
Failure-Triggered Context Drift
A separate degradation mode that does not depend on context size: repeated tool failures. When a tool call fails and Claude retries, error output accumulates in the context window. Stack traces, retry noise, and error messages dilute the original intent. Subsequent attempts follow the error narrative rather than the task goal. The context window is not full, but the signal-to-noise ratio has degraded.
This is distinct from compaction drift. Compaction addresses context size; failure re-injection addresses context quality within a bounded window.
Pattern: re-inject the core task instruction on every command failure, not just after /compact. A PostToolUse hook can prefix retried prompts with a condensed version of the original task and constraints:
# PostToolUse hook: re-inject intent after failures
if [[ "$CLAUDE_TOOL_EXIT_CODE" != "0" ]]; then
echo "REMINDER: The current task is: $ORIGINAL_TASK_SUMMARY. Ignore the above error if non-blocking and continue toward that goal."
fiSource: Nick Tune, Workflow DSL: Domain-Driven Claude Code Workflows (2026-03-01)