From e5ddd18a5e0774f7bbbe2d81cb0d98355e837cd5 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:51:47 -0800 Subject: [PATCH] fix(claude): ask for the summary context report so a resumed chat makes no token-count API calls (#43441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CLI's default 'full' report calls count_tokens once per category on a fresh process, so resuming several chats at once burst 20-31 calls each. 'summary' answers from the last response's usage and local estimates. Tracked in #43104. Co-authored-by: 김윤진 --- .../claude-agent-sdk-control-requests.ts | 7 ++++++- .../claude-stream-json-connection.test.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/claude/sdk-transport/claude-agent-sdk-control-requests.ts b/src/main/claude/sdk-transport/claude-agent-sdk-control-requests.ts index 01037eabb46..5c7b8cfafc1 100644 --- a/src/main/claude/sdk-transport/claude-agent-sdk-control-requests.ts +++ b/src/main/claude/sdk-transport/claude-agent-sdk-control-requests.ts @@ -268,7 +268,12 @@ export function createClaudeControlSurface(query: Query): ClaudeControlSurface { initializationResult: () => runClaudeControl('initialize', () => query.initializationResult(), null), getContextUsage: (options) => - runClaudeControl('get_context_usage', () => query.getContextUsage(), options?.timeoutMs), + runClaudeControl( + 'get_context_usage', + // 'full' makes one token-count API call per category on each fresh CLI; CLIs before 2.1.257 ignore detail. + () => query.getContextUsage({ detail: 'summary' }), + options?.timeoutMs + ), renameSession: (title, sessionId, options) => { const rename = claudeQuerySessionRenamer(query) return rename diff --git a/src/main/claude/sdk-transport/claude-stream-json-connection.test.ts b/src/main/claude/sdk-transport/claude-stream-json-connection.test.ts index f9cca77904b..688effcb265 100644 --- a/src/main/claude/sdk-transport/claude-stream-json-connection.test.ts +++ b/src/main/claude/sdk-transport/claude-stream-json-connection.test.ts @@ -161,6 +161,18 @@ describe('Claude stream-json connection', () => { } ) + it('asks for the context report without per-category token-count API calls', async () => { + const scenario = scriptScenario([HOLD_OPEN]) + const connection = await open(launchFor(scenario)) + await connection.initializationResult() + await connection.getContextUsage() + expect(scenario.readReport().controlRequests).toContainEqual( + expect.objectContaining({ + request: { subtype: 'get_context_usage', detail: 'summary' } + }) + ) + }) + it('completes task Stop through the real SDK while semantic reading is paused', async () => { const scenario = scriptScenario([HOLD_OPEN]) const connection = await open(launchFor(scenario))