Overview
Context tracking displays how much of your context window is remaining, helping you monitor when you’re approaching the limit.Requires jq for JSON parsing. This feature will not work without jq installed.
What You See
- 🧠 Brain emoji indicating context usage
- Percentage of context window remaining
- Visual progress bar (10 characters)
- Color-coded warning levels
How It Works
Data Source
Context information comes directly from Claude Code’s native JSON input—no external tools needed:Calculation Logic
Frombash-generator.ts:162-199:
Token calculation breakdown
Token calculation breakdown
The context usage is calculated from three components:
- input_tokens: Regular input tokens from your conversation
- cache_creation_input_tokens: Tokens used to create prompt cache entries
- cache_read_input_tokens: Tokens read from the prompt cache
Total = input + cache_creation + cache_readThis total is then compared against the context window size (typically 200,000 tokens for Claude Sonnet).Color-Coded Warnings
The context display uses dynamic colors based on remaining percentage:| Remaining % | Color | ANSI Code | Meaning |
|---|---|---|---|
| 0-20% | Coral Red | 38;5;203 | ⚠️ Critical - approaching limit |
| 21-40% | Peach | 38;5;215 | ⚡ Warning - significant usage |
| 41-100% | Mint Green | 38;5;158 | ✅ Healthy - plenty of space |
bash-generator.ts:187-193:
Progress Bar Visualization
The progress bar provides a quick visual indicator of remaining context:Progress Bar Function
Fromfeatures/usage.ts:145-151:
How the progress bar works
How the progress bar works
- Input validation: Ensures percentage is 0-100
- Calculate segments: Determines how many filled (
=) and empty (-) characters - Render bar: Uses
printfandtrto create the visual representation - Fixed width: Always 10 characters wide for consistency
Display Implementation
Frombash-generator.ts:237-240:
Configuration
Fromcli/prompts.ts:27:
Example Scenarios
- Fresh Conversation
- Mid Conversation
- Warning Level
- Critical Level
Fallback Behavior
Without jq, context tracking is unavailable:Requirements
| Requirement | Purpose | Install Command |
|---|---|---|
| jq | JSON parsing | brew install jq (macOS)apt-get install jq (Ubuntu) |
| Claude Code | Data source | Already installed |
Performance
- Execution time: ~5-10ms with jq
- Data source: Native Claude Code JSON (no external API calls)
- Overhead: Minimal - single jq invocation
Troubleshooting
Shows 'TBD' instead of percentage
Shows 'TBD' instead of percentage
Cause: jq is not installed or not in PATHSolution:
Shows 0% or incorrect percentage
Shows 0% or incorrect percentage
Cause: Claude Code JSON format may have changedDebug steps:
- Enable logging: Re-run
cc-statusline initand enable debug logging - Check
.claude/statusline.logfor the raw JSON input - Verify the
context_windowobject exists in the JSON - Report issue if JSON structure has changed
Context never changes
Context never changes
Cause: May be in a conversation that hasn’t used significant context yetNormal behavior: Context usage only increases as you:
- Have longer conversations
- Include more code context
- Use tools extensively
Next Steps
Cost Monitoring
Track costs and burn rates alongside context
Session Timer
Monitor time until usage reset