You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trace: record context window usage and compactions in AI coding session evidence #3637
The CHAINLOOP_AI_CODING_SESSION evidence does not record how full the model context window was during the session. data.usage has only session totals. The cache-read total adds the context of every turn, so it does not show the context size.
Today, a consumer must walk raw_session.*[].message.usage and add input_tokens + cache_read_input_tokens + cache_creation_input_tokens for each turn. The evidence does not record the window size, so the consumer cannot calculate a percentage. For example, the model ID claude-opus-5-5 does not show whether the session used a 200K or a 1M window.
Example session (sha256:3a0250e44d4b4a2ca0744c5203e8707f4c668b38c5941f5275cbbf0fb5239fd5): the main transcript peaks at 134,778 tokens and the Explore subagent at 60,594 tokens. That is about 67% of a 200K window or 13% of a 1M window. The evidence cannot tell which one is correct.
Proposal
Investigate how each Trace provider (Claude Code, Cursor, OpenCode, Pi, Codex) can supply this data. Then add it to the evidence schema:
context_window_tokens: the window size that the agent used.
context_peak_tokens and context_peak_pct: the largest context of a turn in the session.
context_final_tokens and context_final_pct: the context of the last turn.
compaction_count: the number of times the agent compacted the context. If possible, record the turn of each compaction.
The same fields for each subagent.
Why
With these fields, policies can do these checks without a walk of the raw transcript:
Warn when a session ends above a context threshold, for example 80%.
Warn when a session makes a large change (ai_lines_added above a limit) after a compaction.
The AI Session Score can also use the fields as a signal for context quality.
Related observation
In the same session, git_context.commit_start and commit_end are both 76c8c508, the commit that the session made. commit_start is probably the parent commit. Examine this at the same time.
🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri
Activity