Two-file setup that surfaces Claude Code's context window usage as a status line in your terminal and writes it to /tmp so the agent itself can read it.
| File | Location |
|---|---|
~/.claude/settings.json |
Claude Code settings — enables the status line |
~/.claude/statusline-command.sh |
Script that parses and renders context usage |
For you: The status line shows context percentage used, remaining, current model, and working directory — color-coded by urgency (green → yellow → red).
For Claude: The script writes current context usage to /tmp/claude-context-percentage.txt on every update. This means the agent can read its own context state and act on it.
Claude Code's default autocompaction threshold kicks in late — by that point you're often in the "stupid zone": context rot has already degraded response quality, even if the session hasn't hit the hard limit.
This is particularly useful for autonomous runs, e.g. software implementation from specifications.
By giving the agent visibility into its own context usage, you can:
- Instruct Claude (via
CLAUDE.mdor system prompt) to autocompact earlier than the default threshold - Have Claude warn you proactively before quality degrades
- Have Claude suggest starting a new session at a sensible cutoff
- Have Claude adjust verbosity as the window fills, conserving tokens
- Copy
statusline-command.shto~/.claude/statusline-command.sh - Make it executable:
chmod +x ~/.claude/statusline-command.sh - Merge the
statusLineblock into your~/.claude/settings.json - Update the path in
settings.jsonif your username isn'tcaptivus
Add something like this to your CLAUDE.md:
## Context Management
Check /tmp/claude-context-percentage.txt to monitor context usage.
- Above 50%: be concise, avoid unnecessary elaboration
- Above 65%: suggest a compact or new session if the task allows
- Above 80%: strongly recommend compacting before continuingjq— for parsing the JSON status input- Claude Code with status line support (recent versions)