Expose context usage to the model via tool or system reminder
Problem
I capture discussion with Claude for documentation and history preservation purposes. Generally, I'd like to use my custom skill to summarize and append to a discussion document before compaction happens. When working on long sessions, context compaction happens automatically without warning. The model has no visibility into how full the context is, which means it can't proactively preserve important discussion details before they're lost to summarization.
Currently:
- Users can run
/contextto see usage stats - The model cannot query this information
- Compaction happens silently, losing design rationale, alternatives considered, and other valuable context
Proposed Solution
Expose context usage to the model in one of these ways (in order of preference):
1. System reminder at thresholds
Inject a system reminder when context hits configurable thresholds (e.g., 60%, 75%, 90%):
<system-reminder>
Context usage: 75% (150k/200k tokens). Consider archiving important discussion details.
</system-reminder>
2. Built-in ContextInfo tool
A tool the model can call to query current usage:
{
"model": "claude-opus-4-5-20251101",
"tokens_used": 150000,
"tokens_max": 200000,
"percentage": 75,
"autocompact_buffer": 45000
}
3. MCP-accessible endpoint
Expose context stats via a local endpoint that custom MCP servers can query, enabling user-built solutions.
Use Case
I maintain project-specific skills that document design decisions and conversation summaries. The skill is meant to be invoked proactively before compaction to preserve discussion details. However, without visibility into context usage, the model can't reliably trigger this — it gets caught up in implementation work and compaction happens unexpectedly.
With context visibility, the model could:
- Check usage after completing major tasks
- Proactively archive discussions when approaching thresholds
- Warn users before important context is lost
Alternatives Considered
- Tie documentation to commits: Works for code changes, but misses valuable discussions that don't result in commits
- User manually triggers: Puts burden on user to remember; defeats purpose of proactive archival
- External polling: No way for external tools to query Claude Code's internal state
Additional Context
The /context command already computes this information — the request is simply to make it accessible to the model.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗