Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(claude): compact old threads before they burn through usage #8144

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 12 commits intomain fromrefs/pull/8144/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Claude threads can resume with hundreds of thousands of old context tokens and burn through usage before the user realizes it. T3 also did not show Claude Code's resume summary prompt or expose an easy compaction control.

This change matches Claude Code's 70-minute and 100,000-token resume conditions, supports its native resume dialog on web and mobile, adds /compact to provider command menus, and puts a compact action in the context meter. Claude provider settings can now set an earlier auto-compaction threshold without shrinking the 1M context window.

Before

Claude thread without an old-context warning

After

Claude thread with an old-context compaction prompt

Claude's native resume summary choices

Claude provider auto-compaction setting

Verified with 142 server tests, 61 contract tests, 26 web tests, and scoped type checks for server, web, mobile, desktop, contracts, and client runtime. Screenshots use synthetic Sonnet 5 conversations and contain no personal thread data.

Built by GPT-5.6 Sol in the Codex harness.


Note

Medium Risk Touches Claude session start, resume dialogs, and user-input/approval cancellation paths; incorrect abort handling or compaction gating could affect live threads, but changes are covered by extensive adapter and UI tests.

Overview Adds Claude context compaction end to end: a configurable Auto-compact after threshold (100000–1000000 tokens) on Claude provider settings, forwarded to the SDK as autoCompactWindow and reflected in thread usage as autoCompactThreshold.

The server Claude adapter wires Claude’s resume_return dialog through onUserDialog and the existing user-input flow (compact / keep history / don’t ask again), registers /compact in slash commands, and fixes abort races by settling AskUserQuestion and tool approval waits when the signal was already aborted before listeners attach. Ultrathink no longer prefixes single-token slash commands like /compact.

The web composer gains Compact context on the context meter and a “Resume with less context” banner when an old Claude session exceeds ~70 minutes and 100k tokens, with gating for drafts, busy state, and compatible Claude instances. Shared copy in @t3tools/shared/claudeCompaction keeps server prompts and client dismissal detection aligned.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dc39e204f31f70eb81573e5060d9ed651a31a5b8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add Claude context compaction UI, autoCompactWindow setting, and resume dialog support

  • Adds a 'Compact context' action to the context window meter and a 'Resume with less context' banner in ChatView.tsx; clicking either injects /compact into the composer via the new ChatComposerHandle.compactContext() method
  • Wires autoCompactWindow (100000–1000000 tokens) through settings.ts → ClaudeAdapter.ts → Claude query settings, and surfaces the threshold in ThreadTokenUsageSnapshot.autoCompactThreshold so the UI can display it
  • The Claude adapter now handles resume_return dialogs through the shared AskUserQuestion flow, returning compact | continue | never; the 'never' answer is shared via CLAUDE_RESUME_COMPACTION_NEVER_ANSWER in claudeCompaction.ts
  • Registers a built-in /compact slash command in ClaudeProvider.ts and fixes model.ts so ultrathink effort no longer prefixes slash commands like /compact, which would break them
  • Behavioral Change: AskUserQuestion and tool-approval flows in makeClaudeAdapter now immediately resolve as cancelled if the abort signal was already aborted before listener registration, preventing hangs; ChatComposerProps replaces activeThreadActivities with activeContextWindow — existing consumers must update
Macroscope summarized dc39e20.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: af46b8d6-ea93-46eb-ad83-f81b058d3753

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.4 KiB13.3 KiB−117 B (−0.9%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB−4 B (−0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.4 KiB−113 B (−1.7%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.0 KiB55.6 KiB+602 B (+1.1%)66.4 KiB✅
      CodexLive turn messages1611−5 (−31.3%)21✅
      ClaudeTotal thread wire13.4 KiB13.4 KiB−95 B (−0.7%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB+8 B (+0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.5 KiB−103 B (−1.5%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded55.8 KiB56.4 KiB+620 B (+1.1%)66.4 KiB✅
      ClaudeLive turn messages1611−5 (−31.3%)21✅

      Baseline: 9996038 · PR result: dc39e20 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. One consistency finding in the changed web UI: the new resume-compaction notice is a hand-rolled banner inside the composer glass shell instead of the existing composer banner/drawer surface contract. Details inline.

      Posted via Macroscope — UI Consistency
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This introduces a cross-layer Claude compaction workflow, including SDK configuration, resume-session dialogs, new context-meter/banner controls, and slash-command behavior. The new user-facing flow and its effect on session processing warrant human review.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. UI consistency review of the web changes. The resume-compaction notice now uses the shared ComposerBannerStack contract, which resolves the earlier finding. Two smaller consistency/interaction points remain, both inline.

      Posted via Macroscope — UI Consistency
    7. One finding on the new compaction affordances: the shared compactDisabled flag silently deadens both new controls, which departs from how every neighbouring composer/banner action communicates an unavailable state. Details inline.

      Posted via Macroscope — UI Consistency
    8. One finding: the new composer draft-content gate re-implements a shared predicate instead of reusing it. The previously flagged hover-popover grace period (closeDelay) and the banner action's button treatment both look resolved.

      Posted via Macroscope — UI Consistency
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      This hand-rolls the draft-content predicate again instead of using the shared one. composerDraftHasUserContent (composerDraftStore.ts) is the canonical version used by the sidebar rows and the new-thread flows, and this file already carries an identical inline copy (composerHasDraftContent, declared before compactDisabled uses it) for the branch-mismatch gate. Two local copies of the same concept drift from the shared contract: both omit persistedAttachments, so a draft that is still rehydrating (persisted attachments present, images not yet restored) reads as empty and compactDisabled will not block the Compact action, which overwrites the draft prompt with /compact and sends.

      Suggest reusing the shared helper (or the existing composerHasDraftContent) so all gates move together:

      -  const composerHasUnsentContent = useComposerDraftStore((store) => {
      -    const draft = store.getComposerDraft(composerDraftTarget);
      -    return Boolean(
      -      draft &&
      -      (draft.prompt.trim().length > 0 ||
      -        draft.images.length > 0 ||
      -        draft.terminalContexts.length > 0 ||
      -        draft.elementContexts.length > 0 ||
      -        draft.previewAnnotations.length > 0 ||
      -        draft.reviewComments.length > 0),
      -    );
      -  });
      +  const composerHasUnsentContent = useComposerDraftStore((store) =>
      +    composerDraftHasUserContent(store.getComposerDraft(composerDraftTarget)),
      +  );

      This needs composerDraftHasUserContent added to the existing ../composerDraftStore import.

      Posted via Macroscope — UI Consistency
    9. Follow-up on the disabled-reason handling added in d803371: the reason is now delivered only through aria-label on a disabled Button. buttonVariants sets disabled:pointer-events-none and a disabled <button> is out of the tab order, so that name is unreachable by hover, focus, or AT — sighted users still see a dead control with no explanation — while it also overrides the visible label when the button is enabled. The repo already has a disabled-reason contract (DisabledReasonTooltip in RightPanelTabs.tsx, CloudLinkSwitch in ConnectionsSettings.tsx: Tooltip + TooltipTrigger render={<span className="inline-flex">…</span>}), and the sibling composer-banner actions encode state in visible text (Stopping..., Waking..., Restoring...). Two inline notes below.

      Posted via Macroscope — UI Consistency
    10. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d8033710bb6d64cd9ed446cab9d1c9d3b7c12a99. Configure [here](https://www.cursor.com/dashboard/bugbot).
    11. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Fixed in 7dcf3f17b. Compaction and branch-mismatch visibility now share composerDraftHasUserContent, including attachments that are still rehydrating.

    12. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

Sign in to join this conversation.