Feature Request: Expose context window usage percentage to the model

Resolved 💬 6 comments Opened Mar 13, 2026 by tsubasa-rsrch Closed Apr 16, 2026

Summary

When running long-lived Claude Code sessions (hours to days), context window compaction happens without warning to the model. The model has no way to know how much of the context window has been consumed.

Use Case

Long-running AI agent sessions that maintain persistent state (memory files, working context) would benefit from knowing their context utilization. This enables:

  1. Self-managed session lifecycle: At ~80% utilization, the agent can save its state to persistent files and initiate a clean restart, rather than experiencing uncontrolled compaction that degrades information quality.
  1. Proactive context management: The agent can decide which information to keep in-context vs offload to external storage based on remaining capacity.
  1. Better compaction outcomes: Agents can prepare structured summaries before compaction rather than having the system compress an unstructured conversation.

Current Behavior

  • Users see a "Long conversation" warning, but the model does not receive any signal about context utilization.
  • Compaction happens automatically and unpredictably from the model's perspective.
  • Information is lost or degraded during compaction with no opportunity for the model to prepare.

Proposed Solution

Expose context window usage (e.g., as a percentage or token count) via:

  • A system-level field accessible to the model during generation
  • Or a tool/API the model can query

Even a simple threshold notification (e.g., "context is at 80%") would be valuable.

Impact

This would benefit any long-running Claude Code workflow, not just agent-based ones. Developers building persistent assistants, research tools, or autonomous agents would all benefit from models that can self-manage their context lifecycle.

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗