Skip to content

feat: native context compaction for Claude and Codex (#1493 E, #318) - #1495

Merged
currentbits merged 2 commits into
mainfrom
coder/1493-e-native-compaction-09db69
Oct 6, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/1493-e-native-compaction-09db69

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Item E of #1493, also #318.

What changed

  • /compact and a new "Compact context" action in the context popover now run the provider's own compaction on a thread with a live session:
    • Claude: a bare /compact turn over stream-json stdin.
    • Codex: app-server thread/compact/start.
  • Fallback: other providers keep fork-to-fresh, and the popover says they can't compact in place.
  • Compaction shows in the transcript. Manual or automatic compaction (Claude system/compact_boundary, Codex contextCompaction items) appends a "Context compacted (27.5k → 5.6k tokens)" event and resets the context ring to the post-compaction size.
  • A native compact goes out bare, without the usual prompt prefix and notes. Claude reads trailing text as summary instructions.
  • The compaction event counts as turn content, so a manual Claude compaction's empty result isn't treated as a phantom result and failed.
  • A manual compaction is its own turn, so it gets the normal end-of-turn checkpoint.

Verified against the real CLIs (worker, scratch dirs only):

  • Claude 2.1.283: 27,495 → 5,562 tokens.
  • Codex 0.159.2: the compaction runs as its own short turn.

Test fixtures are trimmed from that real output.

Verified independently

🤖 Generated with Claude Code

Willem and others added 2 commits October 6, 2026 15:18
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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T13:31:17.083802Z 30a054b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1248 to +1250
const nativeCompact =
Boolean(detail?.thread.sessionId) &&
NATIVE_COMPACT_PROVIDERS.includes(detail?.thread.provider ?? "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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