Repository navigation
feat: native context compaction for Claude and Codex (#1493 E, #318) - #1495
Conversation
A bare /compact on a Claude or Codex thread with a session now runs the provider's own compaction instead of a normal turn. Claude gets /compact on stdin; Codex swaps turn/start for thread/compact/start. Both the manual and auto paths post a "Context compacted (pre → post tokens)" event and reset the ring's contextTokens to the post size. Claude's compact result is an empty success, so compact_boundary now counts as turn content or the phantom-result guard would fail the run. Fixtures are trimmed from claude 2.1.283 and codex-cli 0.159.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a Claude or Codex thread with a live session, /compact and the new Compact context button in the context popover send /compact as a turn, which the runner turns into the provider's own compaction. Other providers keep the fresh-context fork, and the popover says they can't compact in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30a054bad7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const nativeCompact = | ||
| Boolean(detail?.thread.sessionId) && | ||
| NATIVE_COMPACT_PROVIDERS.includes(detail?.thread.provider ?? ""); |
There was a problem hiding this comment.
Exclude ejected sessions from native compaction
When a Claude or Codex thread has been ejected, its sessionId is intentionally retained for the external CLI, but sessionIdForResume() refuses to resume it. This check therefore treats the ejected thread as native-compactable and sends /compact; the runner similarly strips the replay/prefix based on the stale ID, then starts a fresh session where /compact becomes an ordinary turn instead of thread/compact/start. The user loses the expected fork/replay behavior and the thread is silently attached to a new, context-free session, so nativeCompact must also require that the thread is not ejected.
Useful? React with 👍 / 👎.
Item E of #1493, also #318.
What changed
/compactand a new "Compact context" action in the context popover now run the provider's own compaction on a thread with a live session:/compactturn over stream-json stdin.thread/compact/start.system/compact_boundary, CodexcontextCompactionitems) appends a "Context compacted (27.5k → 5.6k tokens)" event and resets the context ring to the post-compaction size.Verified against the real CLIs (worker, scratch dirs only):
Test fixtures are trimmed from that real output.
Verified independently
vite buildpasses.🤖 Generated with Claude Code