Skip to content

feat: record Claude Code and Codex compactions; runaway context growth restarts at one - #372

Open
Mark Warren (ZeSnarf) wants to merge 1 commit into
microsoft:mainfrom
PharSideLabs:claude/upstream-agent-compactions
Open

Mark Warren (ZeSnarf) wants to merge 1 commit into
microsoft:mainfrom
PharSideLabs:claude/upstream-agent-compactions

Conversation

@ZeSnarf

@ZeSnarf Mark Warren (ZeSnarf) commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Compactions are only read from Copilot CLI logs today. Claude Code and Codex sessions that compact show no compactions on Context Management. Runaway Context Growth also measures them across the compaction, so a long session that compacted and kept working is flagged as growing without limit.

This PR:

  • Claude Code. Reads system lines with subtype compact_boundary and their compactMetadata (trigger, preTokens, postTokens, durationMs) into request.compaction(s), in the Copilot CLI shape (readCliCompaction, addTurnCompaction). A compaction logged before the first prompt goes to the first request.
  • Codex. Reads compacted lines, compaction response items, context_compacted events and ContextCompaction items. Codex logs no sizes, so the size before is the prompt of the last model call, and the limit is its model_context_window when logged. Codex often writes several records for one compaction; they count once. History that a forked thread inherited adds none.
  • Privacy. Only numbers and enum values are kept, never the summary text.
  • Runaway Context Growth. Counts only the requests after the session's last successful compaction. Sessions that never compacted are measured as before.
  • Context Amnesia Risk. Skips a Claude Code compaction when no context limit was logged. Claude Code logs no window, and an estimate sized from the session's own peak would put every compaction near full.
  • Bumps CACHE_VERSION.

We found this by running the extension on real Claude Code and Codex logs, where long sessions that compacted several times were flagged as runaway context growth.

Related Issues

None filed.

Checklist

  • npm run check passes (typecheck + lint + spellcheck + knip + tests)
  • Changes are covered by tests (parser-claude-compaction.test.ts, parser-codex-compaction.test.ts; context-management.test.ts: runaway growth after a compaction, and amnesia on an estimated Claude Code window)
  • Documentation updated (if applicable): not needed

…h restarts at one

Claude Code compact_boundary lines and Codex compacted / compaction /
context_compacted / ContextCompaction records now fill request.compaction(s)
in the Copilot CLI shape: size before, after and trigger when logged, and
for Codex the limit from model_context_window. Several Codex records for
one compaction count once, and history a forked thread inherited adds none.
Only numbers and enum values are kept, never the summary.

Runaway Context Growth counts only the requests after a session's last
successful compaction; sessions that never compacted are measured as
before. Context Amnesia Risk skips Claude Code compactions when no context
limit was logged, since the estimated window is sized from the session's
own peak and would put every compaction near full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant