[FEATURE] Add context window usage to agent's environment info block
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
The agent receives an environment block (working
directory, platform, shell, etc.) but has zero
visibility into context window usage. This makes
CLAUDE.md rules like "save state at 75%"
unenforceable — the agent can't evaluate thresholds
it can't observe.
Existing tools don't help the agent:
- StatusLine shows
used_percentageto the
user, not the agent
- PreCompact hook stdout isn't injected into
agent context
- SessionStart compact matcher only helps
after the damage is done
Proposed Solution
Add 2 lines to the existing env block:
Context usage: 73% (145,800 / 200,000 tokens)
Auto-compact threshold: 95%
Why this approach: Zero new APIs (StatusLine
already has this data), zero new tools, backward
compatible. Users can then write CLAUDE.md
threshold rules:
```markdown
## Context Management
- At 75%: save progress to .claude/plans/
- At 85%: suggest /compact while summary quality is
still high
Real-world impact
I maintain a large codebase with .claude/plans/ and
.claude/explorations/ to survive auto-compact.
Despite detailed CLAUDE.md save rules, agent
compliance is low — it can't know when it's urgent.
My workaround (PreCompact→file→SessionStart relay)
handles recovery but not prevention.
Related issues
#23457 (Closed/locked), #24320 (Closed), #13521
(Open/stale), #16510, #16255, #7627, #5942 — all
closed, duped, or too broad. This focuses on the
smallest change with the most value.
Alternative Solutions
_No response_
Priority
High - Significant impact on productivity
Feature Category
Performance and speed
Use Case Example
_No response_
Additional Context
_No response_
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗