beautiful2674 (Discord): after updating from a 0.1.17xx to a 0.1.18xx, Usage's total over All was ~200M tokens lower, with the same filters. Sincef4762e921(v0.1.1803) a Claude Code file whose last message another file holds is a copy, and statsRead left every file of the copy's key out. Claude Code 2.1.312's `--resume --fork-session` (and /branch) copies only the conversation along its last message, so that dropped spent tokens no other file holds: - the subagents the first session ran: their files stay in the first session's subagents folder only (a sandbox run of 2.1.312 against a fake API: the fork's folder has none); - what came before a compaction, when the branch was made after /compact (it starts from the summary) and went on while the session didn't: the session is then the copy, and its whole pre-compaction history was dropped; - messages /rewind left on another branch, and sidechain messages an older Claude Code wrote into the session's file. Part of the drop is right: before 1803 the copied messages were counted in both files. A copy now adds to the session it is kept in: its subagents' files whole, and its own file read for the user and assistant messages the keeper's file doesn't hold (ccRest, kept while neither file changes). A copy that is a copy through and through adds nothing, as before. Fixtures: testdata/claude-forks/subagent*.jsonl are Claude Code 2.1.312's own files from a sandbox HOME with a fake API (a session whose first prompt ran a subagent, and a --fork-session of it with a prompt of its own), cut to user and assistant lines, paths rewritten to /w/proj. The compaction case cuts compacted.jsonl before "rw prompt eight", as it was when compacted-branch-on.jsonl's branch was made. Run (mote) at this tree on efb55b5c9; rebased on96d4715c6(routing groups in gateway, provider, cli and the GUI between; nothing in internal/sessions or its callers' stats paths), internal/sessions ran again there: ok. gofmt -l clean; GOOS=darwin, linux and windows go vet -tags nogui ./internal/sessions ./internal/gui ./internal/cli ./internal/tui ok; go test -tags nogui -count=1 -timeout 45m ./internal/sessions ./internal/gui ./internal/cli ./internal/tui ./internal/usage all ok. Broken by hand, each red: stats.go as on origin/main (4000 in, want 5000; 20 in, want 80); the copy's subagent files and its rest left out (the same two). Not changed: the Sessions row of the session a copy is kept in still leaves out the copy's subagents and its pre-compaction messages (#4054). Not tried: the reporter's own files; how much of their 200M was double counting before 1803 and how much this gives back is not known.
3 lines
1.5 KiB
JSON
3 lines
1.5 KiB
JSON
{"parentUuid":null,"isSidechain":true,"promptId":"7315a976-8075-40b7-a409-b8f05da1026f","agentId":"a889d0f781e3c8503","type":"user","message":{"role":"user","content":"say hi"},"uuid":"a4ffe3c8-7a77-4890-b5c6-e27631fecce9","timestamp":"2026-10-28T10:53:34.798Z","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"cdf0c391-6ae3-4273-b9be-7c5532e57d7c","version":"2.1.312","gitBranch":"HEAD"}
|
|
{"parentUuid":"31b4a173-dc11-4606-9ef9-40e92db04d21","isSidechain":true,"agentId":"a889d0f781e3c8503","message":{"id":"msg_e7923dea5b174f649355","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"ok 072f08"}],"stop_reason":"end_turn","usage":{"input_tokens":1000,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":100,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"inference_geo":"","iterations":[],"speed":"standard","fallback_credit":null},"stop_details":null},"apiBlockIndex":0,"requestRef":"ae23dd29-bc06-480a-bf36-7db28afdbd71","requestedModel":"claude-opus-5-5","attributionAgent":"general-purpose","type":"assistant","uuid":"f8a4c326-8d33-491f-af04-523e7fe0114a","timestamp":"2026-10-28T10:53:34.811Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"cdf0c391-6ae3-4273-b9be-7c5532e57d7c","version":"2.1.312","gitBranch":"HEAD"}
|