Skip to main content

Module agent_context_usage

Module agent_context_usage 

Source
Expand description

Where a running Claude CLI will auto-compact, from its own answer.

The context meter’s countdown used to assume the CLI’s default (window − 33K). The real point moves with CLAUDE_CODE_AUTO_COMPACT_WINDOW, the autoCompactWindow setting and CLAUDE_CODE_DISABLE_1M_CONTEXT, and auto-compaction can be off altogether. The CLI says which: the get_context_usage control request (detail: "summary", answered locally with no inference call) returns autoCompactThreshold (absent when off), isAutoCompactEnabled, maxTokens (the auto-compact window) and the model. Verified on CLI 2.1.288: docs/reports/REPORT_AGENT_PANE_CONTEXT_METER_2026_10_05.md §9.1.

Asked at the same points as get_settings (agent_runtime.rs): at spawn and at every turn boundary, of a control-protocol process only. Published as the persisted per-pane agentcontextusage event.

Structs§

AgentContextUsage
What the CLI reported about auto-compaction for its current model.
AgentContextUsageEvent
The agentcontextusage event’s payload (mps_events::AgentContextUsageChanged). An unknown value is null, not omitted.

Constants§

CONTEXT_USAGE_REQUEST_PREFIX
Prefix of the request_id of our get_context_usage requests, so the answer can be told from the answers to anything else.

Functions§

agent_context_usage_event
The agentcontextusage event data for one pane.
context_usage_from_control_response
The usage in a get_context_usage answer, or None for any other frame, an error answer (a CLI without the request) or one missing isAutoCompactEnabled. Shape: {type: control_response, response: {subtype: success, request_id, response: {model, maxTokens, autoCompactThreshold?, isAutoCompactEnabled, ...}}}.
context_usage_request_line
The get_context_usage request. summary is answered from local state; full would call the token-count API.
count 🔒
A positive count no larger than any real window (100M), else None.
publish_agent_context_usage
Publish it, persisted, so a pane that mounts later still gets the latest.