Open History to see the last commit
1/**
2 * Copy for Claude's resume compaction dialog, shared by the server adapter
3 * (which asks the question) and the web client (which recognizes the
4 * question and its "never" answer in resolved user-input activities to
5 * mirror the dismissal). Both sides must agree on these strings, so they
6 * live here: reword the question or the answer label in this file only.
7 */
8export const CLAUDE_RESUME_COMPACTION_NEVER_ANSWER = "Don't ask again";
9export const CLAUDE_RESUME_COMPACTION_COMPACT_ANSWER = "Compact and continue";
10
11export function formatClaudeResumeCompactionQuestion(input: {
12 readonly ageMinutes: number;
13 readonly estimatedTokens: number;
14}): string {
15 const ageLabel =
16 input.ageMinutes >= 60
17 ? `${Math.floor(input.ageMinutes / 60)}h ${input.ageMinutes % 60}m`
18 : `${input.ageMinutes}m`;
19 return `This session is ${ageLabel} old and uses ${input.estimatedTokens.toLocaleString("en-US")} tokens. Compact it before continuing?`;
20}
21
22const CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN =
23 /^This session is (\d+h \d+m|\d+m) old and uses \d{1,3}(?:,\d{3})* tokens\. Compact it before continuing\?$/u;
24
25export function isClaudeResumeCompactionQuestion(question: string): boolean {
26 return CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN.test(question);
27}
28
29/**
30 * The session age from an answered resume question whose answer was to compact, or null. Answers
31 * are keyed by question id, and the id may itself be the question text.
32 */
33export function claudeResumeCompactionAge(questionAnswer: {
34 readonly questionTextById?: Readonly<Record<string, string>> | undefined;
35 readonly answers: Readonly<Record<string, unknown>>;
36}): string | null {
37 for (const [id, answer] of Object.entries(questionAnswer.answers)) {
38 const age = CLAUDE_RESUME_COMPACTION_QUESTION_PATTERN.exec(
39 questionAnswer.questionTextById?.[id] ?? id,
40 )?.[1];
41 const chosen = Array.isArray(answer) ? answer : [answer];
42 if (age !== undefined && chosen.includes(CLAUDE_RESUME_COMPACTION_COMPACT_ANSWER)) return age;
43 }
44 return null;
45}
46
47/**
48 * Context size below which T3 does not suggest or run a Claude compaction:
49 * the stale-thread Compact chip and idle compaction. Matches Claude Code's
50 * idleCompaction default of 200K.
51 */
52export const COMPACTION_SUGGESTION_MIN_TOKENS = 200_000;