Files
magpie/internal/sessions/testdata/claude-forks/subagent-fork.jsonl
T
yetone b3edcabf29 sessions: a Claude copy's subagents and what only it holds count in the usage stats
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.

Since f4762e921 (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 on 96d4715c6 (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.
2026-10-28 19:01:27 +08:00

9 lines
8.7 KiB
JSON

{"parentUuid":null,"isSidechain":false,"promptId":"ed7bc818-a87d-4feb-9bbd-f73543b3db44","type":"user","message":{"role":"user","content":"SPAWN a subagent please"},"uuid":"fc8f4b1e-9484-444c-ac6b-2662c0baacdc","timestamp":"2026-10-28T10:53:34.773Z","permissionMode":"bypassPermissions","promptSource":"sdk","turnOrigin":"sdk","turnPosition":{"promptIndex":0,"turnIndex":1},"userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"dbf10382-49ff-4048-b9b1-e3956672a29d","isSidechain":false,"message":{"id":"msg_634201dd0c84495c99f8","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"tool_use","id":"toolu_c21b3913662848a7aac0","name":"Agent","input":{"description":"look","prompt":"say hi","subagent_type":"general-purpose"}}],"stop_reason":"tool_use","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":"f9aad217-dc33-41eb-92b2-7d36e538a959","requestedModel":"claude-opus-5-5","type":"assistant","uuid":"ebabeaae-c4ac-4a90-8152-c6e10c4fb064","timestamp":"2026-10-28T10:53:34.794Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"ebabeaae-c4ac-4a90-8152-c6e10c4fb064","isSidechain":false,"promptId":"ed7bc818-a87d-4feb-9bbd-f73543b3db44","type":"user","message":{"role":"user","content":[{"tool_use_id":"toolu_c21b3913662848a7aac0","type":"tool_result","content":[{"type":"text","text":"Async agent launched successfully. (This tool result is internal metadata — never quote or paste any part of it, including the agentId below, into a user-facing reply.)\nagentId: a889d0f781e3c8503 (internal ID - do not mention to user. Use SendMessage with to: 'a889d0f781e3c8503', summary: '<5-10 word recap>' to continue this agent.)\nThe agent is working in the background. You will be notified automatically when it completes. You know nothing about its results until that notification arrives — do not report, assume, or predict them; continue other work or respond to the user in the meantime.\nDo not duplicate this agent's work — avoid working with the same files or topics it is using.\noutput_file: /tmp/claude-501/-w-proj/cdf0c391-6ae3-4273-b9be-7c5532e57d7c/tasks/a889d0f781e3c8503.output\nDo NOT Read or tail this file via the shell tool — it is the full subagent JSONL transcript and reading it will overflow your context. If the user asks for progress, say the agent is still running; you'll get a completion notification."}]}]},"uuid":"2561d611-4c79-4f93-8a4c-72f58a41d8df","timestamp":"2026-10-28T10:53:34.802Z","toolUseResult":{"isAsync":true,"status":"async_launched","agentId":"a889d0f781e3c8503","description":"look","resolvedModel":"claude-opus-5-5","prompt":"say hi","outputFile":"/tmp/claude-501/-w-proj/cdf0c391-6ae3-4273-b9be-7c5532e57d7c/tasks/a889d0f781e3c8503.output","canReadOutputFile":true,"canContinueAgent":true},"sourceToolAssistantUUID":"ebabeaae-c4ac-4a90-8152-c6e10c4fb064","permissionDecision":{"decision":"accept","source":"config","reasonType":"mode"},"userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"d2a971e9-4ad3-4f0e-b274-663c4b9e97db","isSidechain":false,"message":{"id":"msg_cb55aacfcb8c4e058061","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"ok 72b289"}],"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":"d9dab881-1138-4ff3-ba99-cd49d0a7a68b","requestedModel":"claude-opus-5-5","type":"assistant","uuid":"4ea70380-b441-46d0-83e4-61e6aaa4ed23","timestamp":"2026-10-28T10:53:34.833Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"4ea70380-b441-46d0-83e4-61e6aaa4ed23","isSidechain":false,"promptId":"ed7bc818-a87d-4feb-9bbd-f73543b3db44","type":"user","message":{"role":"user","content":"<task-notification>\n<task-id>a889d0f781e3c8503</task-id>\n<tool-use-id>toolu_c21b3913662848a7aac0</tool-use-id>\n<output-file>/tmp/claude-501/-w-proj/cdf0c391-6ae3-4273-b9be-7c5532e57d7c/tasks/a889d0f781e3c8503.output</output-file>\n<status>completed</status>\n<summary>Agent \"look\" finished</summary>\n<note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note>\n<result>ok 072f08</result>\n<usage><subagent_tokens>1102</subagent_tokens><tool_uses>0</tool_uses><duration_ms>29</duration_ms></usage>\n</task-notification>"},"uuid":"faec5eef-f529-482c-ba14-09749b0b244d","timestamp":"2026-10-28T10:53:34.837Z","permissionMode":"bypassPermissions","origin":{"kind":"task-notification","runId":"0mvrzxubz-746aaf0a","producer":"session-task"},"promptSource":"system","turnOrigin":"task_notification","turnPosition":{"promptIndex":0,"turnIndex":2},"queueSkipAttachments":true,"userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"faec5eef-f529-482c-ba14-09749b0b244d","isSidechain":false,"message":{"id":"msg_422ef33ff6024b659255","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"ok ad3a9c"}],"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":"71bff5f1-d553-4139-b469-5507f430fd42","requestedModel":"claude-opus-5-5","type":"assistant","uuid":"e79cc412-4dde-45c2-a5ae-c7e9315d0c14","timestamp":"2026-10-28T10:53:34.842Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"e79cc412-4dde-45c2-a5ae-c7e9315d0c14","isSidechain":false,"promptId":"ed7bc818-a87d-4feb-9bbd-f73543b3db44","type":"user","message":{"role":"user","content":"go on"},"uuid":"48711b8a-1ea8-4156-82a3-1db36d5156e2","timestamp":"2026-10-28T10:53:44.810Z","permissionMode":"bypassPermissions","promptSource":"sdk","turnOrigin":"sdk","turnPosition":{"promptIndex":0,"turnIndex":3},"userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}
{"parentUuid":"18145ec0-abbf-4abe-85b2-de61fb6ed186","isSidechain":false,"message":{"id":"msg_484495ca86984b0e8c86","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"ok c0819d"}],"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":"4bd3cd2c-8e76-4c85-b406-d573498d2c69","requestedModel":"claude-opus-5-5","type":"assistant","uuid":"5558f11b-8abc-421a-89c6-7dd2eecaf46a","timestamp":"2026-10-28T10:53:44.831Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/w/proj","sessionId":"3a87a3d2-c7ee-4d3c-b559-ff8bdbac43a5","version":"2.1.312","gitBranch":"HEAD"}