Context Management
Git status snapshot, CLAUDE.md auto-discovery, and per-conversation context caching.
Git status snapshot
Section titled “Git status snapshot”At session start, if the working directory is a git repo:
- Run
git status --short,git log --oneline -n 5,git config user.name - Capture branch, default branch, and user name
- Truncate status to 2000 characters if output exceeds limit
- Format and cache for session duration
Truncation message: If status exceeds 2k chars:
... (truncated because it exceeds 2k characters. If you need more information, run "git status" using BashTool)Reasons for truncation:
- Prevent context bloat in large repos with many changes
- Reduce token usage
- Users can run
git statusmanually if needed
Example output
Section titled “Example output”This is the git status at the start of the conversation. Note that this status is a snapshot in time, and will not update during the conversation.Current branch: feature/docsMain branch (you will usually use this for PRs): mainGit user: Alice ZennerStatus:M docs/Sessions/README.md M src/context.ts?? new-file.ts
Recent commits:a1b2c3d Fix context cachingb2c3d4e Add session lifecycle docsc3d4e5f Initial session systemWhen git status is excluded
Section titled “When git status is excluded”Git status is not included if:
- Working directory is not a git repo
shouldIncludeGitInstructions()returns false (disabled via settings)NODE_ENV === 'test'- Error occurs during git commands (logged, skipped gracefully)
CLAUDE.md auto-discovery
Section titled “CLAUDE.md auto-discovery”At session start, Claude Code looks for ~/.claude/CLAUDE.md:
- Read file from user’s home directory
- Filter for potentially sensitive content (API keys, credentials)
- Cache as string for conversation lifetime
- Inject into system context on each turn
Disabling auto-discovery
Section titled “Disabling auto-discovery”Auto-discovery is skipped if:
CLAUDE_CODE_DISABLE_CLAUDE_MDSenv var set--bareCLI flag passed- File not readable (permission denied, not found)
Per-conversation context caching
Section titled “Per-conversation context caching”Context functions are memoized for the duration of a single conversation:
getSystemContext() → cachedgetUserContext() → cachedMemoization details:
- Input: Current working directory (cwd)
- Output: Formatted system/user context strings
- Lifetime: Entire conversation (from session start to
/exit) - Cache cleared on:
setSystemPromptInjection()called
Benefits:
- Avoid re-reading CLAUDE.md on every turn
- Avoid re-running git commands repeatedly
- Consistent context across turns
Cache invalidation
Section titled “Cache invalidation”Manually clear context cache:
setSystemPromptInjection(value) // Clears both cachesThis is used internally for ephemeral debugging state (ant-only feature).
Context includes
Section titled “Context includes”Each turn’s system prompt includes (in order):
- Model instructions (from Claude Code)
- Git status (if in repo and enabled)
- CLAUDE.md contents (if found and not disabled)
- Recent commands/hooks context
- Session-specific instructions (e.g.,
--baremode disables #2 and #3)
Total size before compaction: typically 1–5k tokens.