The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 18:00 UTC
feat(web): compact-before-send is a chip that shows the token count (#17127)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 8, 2026 at 02:01 UTC
0647c481017f25ddff2ec1dff68ef3944489b6db
4 files changed
+104
-97
apps/web/src/components/ChatView.tsx
+24
-15
@@ -7672,9 +7672,9 @@ export default function ChatView(props: ChatViewProps) {
7672
: "Compacting is unavailable right now"
7673
: null;
7674
// Tokens a stale Claude session would re-read on its next turn. While set,
7675
- // Enter compacts first and the composer's send button says so; "Send with
7676
- // full history" in its menu skips that once. Held queues and multi-model
7677
- // sends never compact first, so the offer hides for them.
7675
+ // the composer shows a Compact chip and Enter compacts first; turning the
7676
+ // chip off sends the next message with full history. Held queues and
7677
+ // multi-model sends never compact first, so the offer hides for them.
7678
const resumeCompactionTokens =
7679
activeContextWindow &&
7680
!resumeCompactionPermanentlyDismissed &&
@@ -7690,17 +7690,25 @@ export default function ChatView(props: ChatViewProps) {
7690
})
7691
? activeContextWindow.usedTokens
7692
: null;
7693
- // Set only for the synchronous span of a "Send with full history" submit;
7694
- // onSend reads it before its first await.
7695
- const keepFullHistoryOnceRef = useRef(false);
7696
- const sendWithFullHistory = useCallback((send: () => void) => {
7697
- keepFullHistoryOnceRef.current = true;
7698
- try {
7699
- send();
7700
- } finally {
7701
- keepFullHistoryOnceRef.current = false;
7702
- }
7693
+ // Threads whose Compact chip is turned off. A send that starts its turn
7694
+ // clears its thread's entry; a failed send keeps it for the retry.
7695
+ const [fullHistoryThreadKeys, setFullHistoryThreadKeys] = useState<ReadonlySet<string>>(
7696
+ () => new Set(),
7697
+ );
7698
+ const keepFullHistory = fullHistoryThreadKeys.has(routeThreadKey);
7699
+ const setKeepFullHistory = useCallback((threadKey: string, keep: boolean) => {
7700
+ setFullHistoryThreadKeys((current) => {
7701
+ if (current.has(threadKey) === keep) return current;
7702
+ const next = new Set(current);
7703
+ if (keep) next.add(threadKey);
7704
+ else next.delete(threadKey);
7705
+ return next;
7706
+ });
7707
}, []);
7708
+ const toggleKeepFullHistory = useCallback(
7709
+ () => setKeepFullHistory(routeThreadKey, !keepFullHistory),
7710
+ [keepFullHistory, routeThreadKey, setKeepFullHistory],
7711
+ );
7712
const handleRestoreThreadBranch = useCallback(() => {
7713
if (!canWriteSourceControl) return;
7714
if (gitStatusQuery.data?.hasWorkingTreeChanges) {
@@ -8652,7 +8660,6 @@ export default function ChatView(props: ChatViewProps) {
8660
},
8661
) => {
8662
e?.preventDefault();
8655
- const keepFullHistory = keepFullHistoryOnceRef.current;
8663
// Typed out in full rather than picked from the menu. Attachments or contexts
8664
// mean the user is sending a prompt, so those go through as usual.
8665
if (
@@ -9896,6 +9903,7 @@ export default function ChatView(props: ChatViewProps) {
9903
failure = startResult;
9904
} else {
9905
turnStartSucceeded = true;
9906
+ setKeepFullHistory(routeThreadKey, false);
9907
// The turn is under way and will spend quota, so that thread's limits
9908
// snapshot is stale. Uploads may have outlasted a navigation, so only
9909
// the sending thread's panel clears.
@@ -11559,7 +11567,8 @@ export default function ChatView(props: ChatViewProps) {
11567
}
11568
bannerItems={composerBannerItems}
11569
resumeCompactionTokens={resumeCompactionTokens}
11562
- onSendWithFullHistory={sendWithFullHistory}
11570
+ keepFullHistory={keepFullHistory}
11571
+ onToggleKeepFullHistory={toggleKeepFullHistory}
11572
// With attachments or contexts aboard the pick just inserts the
11573
// text, so it sends as a prompt like the typed path would.
11574
onUsageLimitsCommand={
apps/web/src/components/chat/ChatComposer.tsx
+15
-14
@@ -1391,7 +1391,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
1391
compactDisabled: boolean;
1392
compactDisabledReason: string | null;
1393
compactBeforeSendTokens: number | null;
1394
- onSendWithFullHistory: () => void;
1394
+ keepFullHistory: boolean;
1395
+ onToggleKeepFullHistory: () => void;
1396
}) {
1397
return (
1398
<>
@@ -1431,7 +1432,8 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
1432
onInterrupt={props.onInterrupt}
1433
onImplementPlanInNewThread={props.onImplementPlanInNewThread}
1434
compactBeforeSendTokens={props.compactBeforeSendTokens}
1434
- onSendWithFullHistory={props.onSendWithFullHistory}
1435
+ keepFullHistory={props.keepFullHistory}
1436
+ onToggleKeepFullHistory={props.onToggleKeepFullHistory}
1437
/>
1438
</>
1439
);
@@ -1551,10 +1553,12 @@ export interface ChatComposerProps {
1553
sendDisabledReason: string | null;
1554
isPreparingWorktree: boolean;
1555
bannerItems: readonly ComposerBannerStackItem[];
1554
- /** Tokens Enter compacts before sending; null when the next send keeps full history. */
1556
+ /** Tokens a stale session would re-read; null when the thread is not offered compaction. */
1557
resumeCompactionTokens: number | null;
1556
- /** Runs `send` as a one-off send that keeps full history instead of compacting first. */
1557
- onSendWithFullHistory: (send: () => void) => void;
1558
+ /** The Compact chip is off, so the next send keeps full history. */
1559
+ keepFullHistory: boolean;
1560
+ /** Flips the Compact chip for the active thread. */
1561
+ onToggleKeepFullHistory: () => void;
1562
/** Picking /usage-limits from the menu is the action itself; the draft keeps nothing of it. */
1563
onUsageLimitsCommand?: (() => void) | undefined;
1564
environmentUnavailable: {
@@ -3016,7 +3020,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3020
(!composerSendState.hasSendableContent && !showResumeAction);
3021
const collapsedComposerPrimaryActionLabel = showResumeAction
3022
? "Resume thread"
3019
- : props.resumeCompactionTokens !== null
3023
+ : props.resumeCompactionTokens !== null && !props.keepFullHistory
3024
? "Open composer to compact and send"
3025
: "Send message";
3026
const showMobilePendingAnswerActions =
@@ -4271,11 +4275,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
4275
},
4276
[phase, settings.followUpBehavior, submitComposer],
4277
);
4274
- const { onSendWithFullHistory } = props;
4275
- const sendWithFullHistory = useCallback(
4276
- () => onSendWithFullHistory(() => submitComposer()),
4277
- [onSendWithFullHistory, submitComposer],
4278
- );
4278
const submitCitationAndSend = useCallback(() => {
4279
submitComposer(
4280
undefined,
@@ -6896,8 +6895,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6895
onClick={(event) => {
6896
event.stopPropagation();
6897
if (showResumeAction) onResume();
6899
- // Compacting first is only sent from the labeled button, so expand to show it.
6900
- else if (props.resumeCompactionTokens !== null) expandMobileComposer();
6898
+ // Compacting first only sends from the expanded composer, where the chip shows it.
6899
+ else if (props.resumeCompactionTokens !== null && !props.keepFullHistory)
6900
+ expandMobileComposer();
6901
else submitComposer();
6902
}}
6903
>
@@ -7615,7 +7615,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
7615
onInterrupt={handleInterruptPrimaryAction}
7616
onImplementPlanInNewThread={handleImplementPlanInNewThreadPrimaryAction}
7617
compactBeforeSendTokens={props.resumeCompactionTokens}
7618
- onSendWithFullHistory={sendWithFullHistory}
7618
+ keepFullHistory={props.keepFullHistory}
7619
+ onToggleKeepFullHistory={props.onToggleKeepFullHistory}
7620
compactDisabled={
7621
compactDisabled || noProviderAvailable || isSendBusy || isConnecting
7622
}
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+61
-64
@@ -1,5 +1,5 @@
1
import { memo, type MouseEventHandler, type PointerEventHandler } from "react";
2
-import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, PlayIcon } from "lucide-react";
2
+import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, Minimize2Icon, PlayIcon } from "lucide-react";
3
import { CornerUpRight, ListPlus } from "lucide";
4
import { MorphIcon } from "~/components/MorphIcon";
5
import { useEnvironmentIdentificationMode } from "~/hooks/useSettings";
@@ -51,9 +51,11 @@ interface ComposerPrimaryActionsProps {
51
onPreviousPendingQuestion: () => void;
52
onInterrupt: () => void;
53
onImplementPlanInNewThread: () => void;
54
- /** Tokens a stale session would re-read. When set, Enter compacts first and the button says so. */
54
+ /** Tokens a stale session would re-read. When set, a Compact chip shows the count and Enter compacts first. */
55
compactBeforeSendTokens?: number | null;
56
- onSendWithFullHistory?: () => void;
56
+ /** The Compact chip is turned off, so the next send keeps full history. */
57
+ keepFullHistory?: boolean;
58
+ onToggleKeepFullHistory?: () => void;
59
}
60
61
const formatPendingPrimaryActionLabel = (input: {
@@ -108,7 +110,8 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
110
onInterrupt,
111
onImplementPlanInNewThread,
112
compactBeforeSendTokens = null,
111
- onSendWithFullHistory,
113
+ keepFullHistory = false,
114
+ onToggleKeepFullHistory,
115
}: ComposerPrimaryActionsProps) {
116
const pointerFocusProps = preserveComposerFocusOnPointerDown
117
? { onPointerDown: preventPointerFocus }
@@ -266,68 +269,24 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
269
}
270
271
const showResume = canResume && !hasSendableContent && !isEditingQueuedMessage;
269
- const sendBlocked = isSendBusy || isSendDisabled || isConnecting || isEnvironmentUnavailable;
272
271
- if (compactBeforeSendTokens !== null && !showResume && !isEditingQueuedMessage) {
272
- const tokens = formatContextWindowTokens(compactBeforeSendTokens);
273
- return (
274
- <div data-chat-composer-compact-send="true" className="flex items-center justify-end">
275
- <Tooltip>
276
- <TooltipTrigger
277
- render={
278
- <button
279
- type="submit"
280
- className={cn(
281
- messageActionPillClassName,
282
- "h-9 rounded-r-none sm:h-8",
283
- compact ? "px-3" : "px-4",
284
- )}
285
- {...pointerFocusProps}
286
- onClick={onSubmitMessage}
287
- disabled={sendBlocked || !hasSendableContent}
288
- />
289
- }
290
- >
291
- {isConnecting || isSendBusy ? "Sending..." : "Compact and send"}
292
- </TooltipTrigger>
293
- <TooltipPopup>Summarize {tokens} tokens of history, then send</TooltipPopup>
294
- </Tooltip>
295
- <Menu>
296
- <MenuTrigger
297
- render={
298
- <button
299
- type="button"
300
- className={cn(
301
- messageActionPillClassName,
302
- "h-9 rounded-l-none border-l border-message-action-foreground/20 px-2 sm:h-8",
303
- )}
304
- aria-label="Send options"
305
- {...pointerFocusProps}
306
- disabled={sendBlocked || !hasSendableContent}
307
- />
308
- }
309
- >
310
- <ChevronDownIcon className="size-3.5" />
311
- </MenuTrigger>
312
- <MenuPopup align="end" side="top" {...composerFloatingLayerProps}>
313
- <MenuItem disabled={sendBlocked} onClick={onSendWithFullHistory}>
314
- Send with full history ({tokens} tokens)
315
- </MenuItem>
316
- </MenuPopup>
317
- </Menu>
318
- </div>
319
- );
320
- }
273
+ const compactTokens =
274
+ compactBeforeSendTokens !== null && !showResume && !isEditingQueuedMessage
275
+ ? formatContextWindowTokens(compactBeforeSendTokens)
276
+ : null;
277
+ const compactsBeforeSend = compactTokens !== null && !keepFullHistory;
278
279
const submitLabel = showResume
280
? "Resume thread"
281
: isEditingQueuedMessage
282
? "Update queued message"
326
- : isQueuing
327
- ? "Queue message"
328
- : isRunning
329
- ? "Steer message"
330
- : "Submit message";
283
+ : compactsBeforeSend
284
+ ? "Compact and send"
285
+ : isQueuing
286
+ ? "Queue message"
287
+ : isRunning
288
+ ? "Steer message"
289
+ : "Submit message";
290
const submitStatus = isEnvironmentUnavailable
291
? "Environment disconnected"
292
: (sendDisabledReason ??
@@ -342,9 +301,11 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
301
: null));
302
const submitTooltip =
303
submitStatus ??
345
- (isRunning && !isEditingQueuedMessage
346
- ? `Click to ${followUpBehavior}, Ctrl/⌘-click${alternateShortcutLabel ? ` or ${alternateShortcutLabel}` : ""} to ${alternateAction}`
347
- : submitLabel);
304
+ (compactsBeforeSend
305
+ ? `Summarize ${compactTokens} tokens of history, then send`
306
+ : isRunning && !isEditingQueuedMessage
307
+ ? `Click to ${followUpBehavior}, Ctrl/⌘-click${alternateShortcutLabel ? ` or ${alternateShortcutLabel}` : ""} to ${alternateAction}`
308
+ : submitLabel);
309
310
const sendButton = (
311
<button
@@ -393,10 +354,46 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
354
</button>
355
);
356
396
- return (
357
+ const submit = (
358
<Tooltip key="submit">
359
<TooltipTrigger render={<span className="inline-flex" />}>{sendButton}</TooltipTrigger>
360
<TooltipPopup>{submitTooltip}</TooltipPopup>
361
</Tooltip>
362
);
363
+ if (compactTokens === null) return submit;
364
+
365
+ return (
366
+ <div data-chat-composer-compact-send="true" className="flex items-center gap-2">
367
+ <Tooltip>
368
+ <TooltipTrigger
369
+ render={
370
+ <button
371
+ type="button"
372
+ className={cn(
373
+ "flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-full border px-2.5 text-xs tabular-nums outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-64 [&_svg]:pointer-events-none [&_svg]:size-3.5",
374
+ keepFullHistory
375
+ ? "border-border text-muted-foreground hover:text-foreground"
376
+ : "border-warning/40 text-warning hover:bg-warning/8",
377
+ )}
378
+ {...pointerFocusProps}
379
+ aria-pressed={!keepFullHistory}
380
+ aria-label={`Compact ${compactTokens} tokens of history before sending`}
381
+ disabled={!canOperateThread}
382
+ onClick={onToggleKeepFullHistory}
383
+ />
384
+ }
385
+ >
386
+ <Minimize2Icon aria-hidden="true" />
387
+ {keepFullHistory ? "Full" : "Compact"}
388
+ <span>{compactTokens}</span>
389
+ </TooltipTrigger>
390
+ <TooltipPopup>
391
+ {keepFullHistory
392
+ ? `Next send keeps all ${compactTokens} tokens. Click to compact first`
393
+ : `Next send compacts ${compactTokens} tokens first. Click to keep full history`}
394
+ </TooltipPopup>
395
+ </Tooltip>
396
+ {submit}
397
+ </div>
398
+ );
399
});
docs/user/providers-claude.md
+4
-4
@@ -50,10 +50,10 @@ window. Leave it empty for Claude Code's default.
50
51
You can also send `/compact` in an existing conversation. Web and desktop offer
52
**Compact context** from the context meter. When you return to a large thread
53
-after more than an hour, the send button changes to **Compact and send**: Enter
54
-summarizes the history first, then sends your message. To keep the full history
55
-for that message, open the menu next to the button and choose **Send with full
56
-history**. See [commands and skills](./composer.md#commands-and-skills) for using
53
+after more than an hour, a **Compact** chip with the thread's token count shows
54
+next to the send button. While it is on, Enter summarizes the history first, then
55
+sends your message. Click the chip to switch it to **Full** and keep the full
56
+history for that message. See [commands and skills](./composer.md#commands-and-skills) for using
57
composer commands.
58
59
## Usage limits