Session rename mid-server-tool-call injects a turn that permanently corrupts the transcript (400 on every future prompt)
Summary
Renaming a session (custom title) while a server_tool_use call (e.g. the built-in advisor tool) is in flight injects a system-reminder as a synthetic user turn in the transcript, landing it between the server_tool_use block and its matching advisor_tool_result block. Because server-tool call + result must live in the same API message, this splits them across two messages on the next resume/request, and the Anthropic API rejects the entire history with a 400 on every subsequent turn — permanently breaking the session until the transcript file is hand-edited.
Reproduction
- Start a session and trigger a server-side tool call that returns asynchronously (in our case, the
advisortool). - While the call is in flight, rename the session (set a custom title) — e.g. via whatever UI/flow assigns
customTitle/agent-name. - Let the tool call resolve and continue the conversation, then send further prompts.
- Every subsequent prompt now fails with:
API Error: 400 messages.N.content.0: unexpected `tool_use_id` found in `advisor_tool_result` blocks: srvtoolu_XXXX. Each `advisor_tool_result` block must have a corresponding `server_tool_use` block before it.
Root cause (confirmed by inspecting the session .jsonl)
In the broken transcript, the three lines around the failure were:
{"type":"assistant", ..., "uuid":"4320b59f-...", "message":{"content":[{"type":"server_tool_use","id":"srvtoolu_01YZBP7b9c3YoD3NXiLgXsVb","name":"advisor","input":{}}]}}
{"type":"user","isMeta":true, "parentUuid":"4320b59f-...", "message":{"role":"user","content":"<system-reminder>\nThe user named this session \"...\". This may indicate the session's focus or intent.\n</system-reminder>"}}
{"type":"assistant", "parentUuid":"<the user line above>", "message":{"content":[{"type":"advisor_tool_result","tool_use_id":"srvtoolu_01YZBP7b9c3YoD3NXiLgXsVb", ...}]}}
When the harness replays/merges the transcript into the API messages array, consecutive same-role entries are folded into one logical message (confirmed by other server_tool_use/advisor_tool_result pairs in the same file that have no interruption and work fine). The injected isMeta user turn breaks that fold here, producing:
- message A (assistant):
[..., server_tool_use] - message B (user):
[system-reminder text] - message C (assistant):
[advisor_tool_result, ...]
advisor_tool_result in message C no longer has its server_tool_use in the same message → 400 from the API → every future turn in the session fails identically, since the full (corrupted) history is resent each time.
Impact
- Session becomes permanently unusable for every future prompt, not just the one where the race happened.
- No user-facing recovery path — we had to manually locate the offending lines in
~/.claude/projects/<project>/<session>.jsonl, delete the injectedisMetasystem-reminder line, and repoint the following message'sparentUuidto restore a valid chain, then re-verify the merged message structure by hand.
Suggested fix
- Don't inject
system-reminder(or any synthetic) user turns while a server-side tool call is awaiting its result — queue the reminder and deliver it only once the current turn (tool_use + its result) is fully closed. - Defensively, on session load/resume, detect and either coalesce or drop any zero-content-value synthetic turn that would split a
server_tool_use/matching result pair, rather than sending it to the API and hard-failing.
Happy to share the (redacted) transcript snippet if useful.
Full disclosure: I maintain cozempic.
The forensic detail here is unusually clear — you've traced the exact injected line (isMeta system-reminder between server_tool_use and advisor_tool_result), confirmed the failure mechanism, and already done the repair manually. Worth knowing that cozempic doctor has an orphaned-tool-results check targeting exactly this structural break: a tool_result block (or advisor_tool_result) that no longer has a corresponding tool_use in the same API message context.
cozempic doctor
Running it on the broken session file should detect the orphaned result automatically and walk through the repair rather than requiring manual JSONL surgery. There's also a doctor --fix unresumable-session path that targets sessions the API rejects on every turn — which is exactly the state your session ended up in.
It won't prevent the race condition (that's CC's fix to ship), but it covers the recovery step you had to do by hand. Worth trying before editing session files manually in future occurrences.
Ran into the same failure mode and wanted to leave a recovery recipe for anyone whose session is already 400-bricked, since there's no in-product path yet.
Confirming your root cause on my side. I reconstructed your three-line pattern (the server_tool_use, the injected isMeta system-reminder user turn, and the advisor_tool_result) alongside an uninterrupted healthy pair in the same file, and the failure is exactly the fold break you describe: the isMeta turn between the server_tool_use and its result forces the result into a separate messages entry, so on replay the advisor_tool_result has no server_tool_use in the same message → 400 unexpected tool_use_id. The healthy pair with no interruption folds fine, which is the tell.
Automated recovery. This does what you did by hand — finds an isMeta user turn that sits between a server_tool_use and its matching result, drops it, and repoints the result's parentUuid back to the server_tool_use line. It only touches a turn that actually splits a matching pair, so uninterrupted pairs and ordinary isMeta reminders are left alone.
import json, sys
def load(p): return [json.loads(l) for l in open(p, encoding="utf-8") if l.strip()]
def ctypes(e):
c = e.get("message", {}).get("content", [])
return [b.get("type") for b in c if isinstance(b, dict)] if isinstance(c, list) else []
def ids(e, kind):
c = e.get("message", {}).get("content", [])
return [b.get("id") or b.get("tool_use_id") for b in c
if isinstance(b, dict) and b.get("type") == kind] if isinstance(c, list) else []
entries = load(sys.argv[1])
by = {e.get("uuid"): e for e in entries}
drop, fixes = set(), []
RESULTS = ("advisor_tool_result", "web_search_tool_result", "code_execution_tool_result", "tool_result")
for i, e in enumerate(entries):
if e.get("type") == "user" and e.get("isMeta") is True:
parent = by.get(e.get("parentUuid"))
if not (parent and "server_tool_use" in ctypes(parent)):
continue
su = set(ids(parent, "server_tool_use"))
for j in range(i + 1, len(entries)):
nxt = entries[j]
if nxt.get("parentUuid") == e.get("uuid"):
res = set(rid for k in RESULTS for rid in ids(nxt, k))
if su & res:
drop.add(e.get("uuid"))
nxt["parentUuid"] = parent.get("uuid")
fixes.append((e.get("uuid"), nxt.get("uuid"), parent.get("uuid")))
break
if not fixes:
print("No contamination found; file left untouched.")
else:
for d, r, p in fixes:
print(f"Removed injected isMeta {d}; repointed result {r} -> parent {p}")
with open(sys.argv[1] + ".fixed", "w", encoding="utf-8") as f:
for e in entries:
if e.get("uuid") not in drop:
f.write(json.dumps(e, ensure_ascii=False) + "\n")
print("Wrote", sys.argv[1] + ".fixed")
Usage (back up first): cp session.jsonl session.jsonl.bak && python3 repair.py ~/.claude/projects/<project>/<session>.jsonl then swap in the .fixed file. On my reconstruction it removed only the contaminated turn, restored the chain so every *_tool_result again shares a message with its server_tool_use, and left the healthy pair byte-for-byte. Caveat: I validated against the reconstructed pattern from your report, not your actual file — verify the .fixed output before replacing.
Detection before it bricks the session. The same match condition works as a SessionStart check that scans ~/.claude/projects/**/<session>.jsonl for an isMeta turn splitting a server_tool_use/result pair and warns with the offending line, so you can repair before the next prompt 400s instead of discovering it mid-work.
Agree the real fix is on the harness side — either queue the system-reminder until the in-flight tool turn closes (your first suggestion), or coalesce/drop any zero-value synthetic turn that would split a server_tool_use/result pair on load. Detection + repair only limits the blast radius after the fact.
@yurukusa that recovery script is excellent — you arrived at the exact same structural diagnosis independently, which validates the root cause. The three-line pattern you reconstructed (server_tool_use → injected isMeta → advisor_tool_result separated across message boundaries) is precisely what the repair needs to target.
For what it's worth, cozempic ships an auto-repair for this same break: cozempic doctor --fix unresumable-session detects an advisor_tool_result or server_tool_result whose matching server_tool_use isn't in the same message context, and repairs the parentUuid chain — which is structurally the same thing your script does. It idle-gates on mtime (won't race a live write), and the guard daemon runs it automatically on session start before the first prompt can 400.
Your SessionStart detection hook idea is also the same approach our guard uses — scan the JSONL at session start, warn before the bad turn triggers, repair if it can. Nice to see two independent implementations converge on the same design.
The repair script you posted is a solid standalone option if someone doesn't want to install anything — good to have it documented in this thread for people who find it later.
Confirming the same failure independently, third report converging on the identical root cause.
Hit this today: advisor() in flight, session got auto-named ("The user named this session ...") mid-call, and every subsequent turn 400'd with the exact error. Inspecting the transcript found the identical three-line pattern already documented here:
line N assistant server_tool_use (advisor) uuid=A
line N+1 user <system-reminder> session named… parentUuid=A
line N+2 assistant advisor_tool_result parentUuid=(line N+1's uuid)
One data point worth adding: the repair did not require dropping the injected reminder line or rewriting the file into a .fixed copy — re-pointing only the advisor_tool_result record's parentUuid directly to the server_tool_use record's own uuid (leaving the injected reminder line in place, just no longer on the path between the pair) was sufficient. Verified before/after with a script that walks every server_tool_use/advisor_tool_result pair in the file and asserts result.parentUuid == server_tool_use.uuid: 1 broken pair found, 0 after the one-field edit, all 8 other pairs in the same session untouched.
Adds confidence to the suggested fix direction: the harness only needs to avoid letting a zero-content synthetic turn sit on the path between a server_tool_use and its result — it doesn't need to be excluded from the transcript entirely, just not injected as an intervening parent while that pair is open.
Hit this again today, independent confirmation of the root cause and fix already documented here.
advisor() call in flight, session got auto-titled mid-call, every prompt after that 400'd with the exact unexpected tool_use_id found in advisor_tool_result blocks error.
Transcript matched the documented pattern, but with one extra wrinkle: the injected content wasn't a single isMeta user line, it was three lines — two "type":"system" framing entries plus the user system-reminder itself, all sitting between the pair:
assistant server_tool_use (advisor) uuid=A
system (framing) parentUuid=A
system (framing) parentUuid=<framing1>
user <system-reminder> session named… parentUuid=<framing2>
assistant advisor_tool_result parentUuid=<reminder>
A single-field patch (repoint advisor_tool_result.parentUuid straight to server_tool_use.uuid, per @jcfernandez-890825) isn't quite enough here on its own: the line that originally followed the result (the next assistant turn) still points its parentUuid at the result. If you only fix the one field, that next turn is left pointing at a parentUuid that's still mid-chain instead of at the new tail, forking the tree into two children at that node instead of a linear chain.
Full repair that worked: move the result so it's an immediate child of server_tool_use, then chain the framing/reminder lines after it in their original relative order, then repoint the turn that used to follow the result so it now follows the last framing/reminder line instead. Net effect: same three-field reparenting, just generalized to N intervening lines instead of assuming exactly one.
+1 for the harness-side fix — queue/defer the system-reminder (and any framing it carries) until the in-flight server-tool turn is fully closed. This is at least 4 independent reports of the same race now, and the "exactly one isMeta line" assumption in the manual/scripted repairs floating in this thread won't hold for every occurrence.
Still reproducing on 2.1.220 (npm latest as of 2026-07-30), and the trigger does not require a user-initiated rename.
Two independent sessions on the same machine bricked within 24h. In both, the injected records were isMeta user records carrying the "The user named this session ..." system-reminder — but in one of them the name was never changed by the user: it was set once at session start, and the harness re-asserted the identical value repeatedly (52 custom-title / 61 agent-name records over the session). The reminder pair still landed mid-flight.
- Case A:
server_tool_useat T+0 → two identical reminders at T+95s (1 ms apart) →advisor_tool_resultat T+106s - Case B:
server_tool_useat T+0 → two identical reminders at T+73s (1 ms apart) →advisor_tool_resultat T+112s
In both cases the call and the result share the same message.id, so the pair ends up split across two persisted assistant records with the reminder records in between, and every later request fails identically:
API Error: 400 messages.N.content.0: unexpected tool_use_id found in advisor_tool_result blocks: srvtoolu_...
Deterministic: retry, a different prompt and /compact all fail the same way, since the same history is resent every turn.
Notes that may help others hitting this:
- Offline repair works: delete the intervening records and re-point the result record's
parentUuidat the call record'suuid. Anchor on uuid, not line numbers — the file keeps being appended to while you work. - The running process holds the corrupted history in memory, so the session must be stopped before repairing — and stopped again if it auto-respawned between the stop and the repair.
claude --resume <id> --fork-session -p ...verifies the repaired history without touching the real session.- Scanning 107 transcripts on this machine: 117 advisor call/result pairs, 3 bricked sessions in 24h.
Is buffering injected reminders until the server-tool turn completes (the way pause_turn resumption already requires the assistant message to be replayed unchanged) viable? The call/result pair looks like it has to be persisted atomically.
Same race, different server tool: tool_search_tool_regex → tool_search_tool_result. Every report in this thread so far is advisor(); this machine has never called advisor — 183/183 server_tool_use records across 223 transcripts are tool_search_tool_regex — so the defect is in the shared injection/fold path rather than anything advisor-specific, and it reaches the tool-loading calls the harness issues on its own initiative.
Occurrence (2.1.220, macOS 25.4.0, CLI, user-initiated rename):
line 22 assistant msg_011CdZYDxp… server_tool_use srvtoolu_016Xj1WA… 04:55:17.839 uuid=29af3dfb
line 23 user isMeta:true <system-reminder> The user named this… 04:55:18.631 parentUuid=29af3dfb
line 24 assistant msg_011CdZYDxp… tool_search_tool_result srvtoolu_016X… 04:55:19.709 parentUuid=<line 23>
Lines 22 and 24 carry the same message.id — the fold the API requires is exactly the one the reminder breaks. Every subsequent prompt then fails with:
API Error: 400 messages.3.content.0: unexpected `tool_use_id` found in `tool_search_tool_result`
blocks: srvtoolu_016Xj1WA…. Each `tool_search_tool_result` block must have a corresponding
`server_tool_use` block before it.
Exposure window was ~1.9s (call → result); the reminder landed 0.8s in.
The repair scripts posted in this thread miss this variant. @yurukusa's matcher keys on
RESULTS = ("advisor_tool_result", "web_search_tool_result", "code_execution_tool_result", "tool_result")
tool_search_tool_result is not in that tuple, so it prints "No contamination found; file left untouched." on a file that is bricked. Suggest matching any *_tool_result block whose tool_use_id starts with srvtoolu_ instead of an allowlist of names — server tools will keep being added, and the allowlist silently fails closed-eyed on each new one.
Otherwise the shape matches the original report exactly: a single isMeta: true user record, no type:"system" framing lines (so @alies-dev's three-line variant is not universal). Minimal repair sufficed — drop the injected record, repoint the result record's parentUuid to the server_tool_use record's uuid — verified by asserting that no non-assistant record sits between any server_tool_use and its matching result, swept across all 223 transcripts on the machine: 1 broken pair before, 0 after, every other pair untouched.
Base rate here: 223 transcripts, 183 server-tool call/result pairs, 1 split by an injected reminder → 1 permanently bricked session.
Correction: the repair script I posted above does nothing on the exact case @ungeism reported.
Both of those cases have two identical reminders (1 ms apart) between the server_tool_use and the advisor_tool_result. My script walks forward from an isMeta turn but inspects only the first record whose parentUuid matches, then breaks. With two chained reminders that first record is the second reminder, not the result — no id match, loop exits, nothing repaired. It only ever worked for a single injected turn, which is the shape I reconstructed from the original report. So anyone who ran it on a session bricked this way got "No contamination found" on a genuinely contaminated file.
Fixed by anchoring on the pair instead of on the reminder: walk server_tool_use ids, find the record carrying the matching result id, and drop what is between them only if every intervening record is an isMeta user turn. Any number of reminders is handled; anything else in between is left for a human instead of being silently deleted.
import json, sys
RESULTS = ("advisor_tool_result", "web_search_tool_result",
"code_execution_tool_result", "tool_result")
def blocks(e):
c = e.get("message", {}).get("content", [])
return [b for b in c if isinstance(b, dict)] if isinstance(c, list) else []
def ids(e, kind):
return [b.get("id") or b.get("tool_use_id") for b in blocks(e) if b.get("type") == kind]
entries = [json.loads(l) for l in open(sys.argv[1], encoding="utf-8") if l.strip()]
drop, fixes, pending = set(), [], {}
for i, e in enumerate(entries):
for sid in ids(e, "server_tool_use"):
pending[sid] = i
for kind in RESULTS:
for rid in ids(e, kind):
if rid not in pending:
continue
j = pending.pop(rid)
between = entries[j + 1:i]
if not between:
continue # healthy pair, untouched
if not all(b.get("type") == "user" and b.get("isMeta") is True for b in between):
continue # something else in between: leave it
for b in between:
drop.add(b.get("uuid"))
e["parentUuid"] = entries[j].get("uuid")
fixes.append((rid, len(between)))
if not fixes:
print("No split pair found; file left untouched.")
else:
for rid, n in fixes:
print(f"Rejoined {rid}: dropped {n} injected isMeta turn(s)")
with open(sys.argv[1] + ".fixed", "w", encoding="utf-8") as f:
for e in entries:
if e.get("uuid") not in drop:
f.write(json.dumps(e, ensure_ascii=False) + "\n")
print("Wrote", sys.argv[1] + ".fixed")
What I verified, and what I could not. I synthesised the Case A/B shape (call → N identical reminders → result) in a file that also contains an uninterrupted pair and an ordinary isMeta reminder splitting nothing, then ran both versions:
| injected reminders | old | new |
|---|---|---|
| 1 | repairs | repairs |
| 2 (Case A/B) | does nothing | repairs |
| 3 | does nothing | repairs |
The new one leaves the healthy pair's parentUuid unchanged, keeps the non-splitting isMeta, and drops exactly the injected turns.
I could not test against a real corrupted transcript. Scanning this machine found 819 session files, 240 server_tool_use/result pairs, and zero with anything between a call and its result — it has never fired here, and I don't rename sessions, which fits @ungeism's point that the reminder storm is what puts a pair at risk. So this is verified against the reported shape, not against a live brick: check the .fixed output before swapping it in.
Still reproducing on 2.1.223 (7 Aug 2026), one week past the 2.1.220 confirmation above. Adding this case because the injected block was a third shape, and because it breaks the forward-walking repair in a way @yurukusa's correction predicts.
This case: three interposed records, not one or two. Trigger was an explicit /rename while advisor() was in flight. That wrote two system / local_command records plus the isMeta reminder:
line 39 assistant server_tool_use (advisor) id=srvtoolu_01BnW...
line 40 system local_command <command-name>/rename</command-name>
line 41 system local_command <local-command-stdout>Session renamed to: ...</local-command-stdout>
line 42 user isMeta:true "<system-reminder>The user named this session ...</system-reminder>"
line 43 assistant advisor_tool_result tool_use_id=srvtoolu_01BnW...
So the injected run is now documented at one record, two chained reminders, and three mixed system + isMeta records. Any repair that counts or walks the injected records has to handle all three.
A repair that is invariant to the count. Rather than walking forward from the injected record, set the advisor_tool_result record's parentUuid to the uuid of the server_tool_use record. Whatever was injected drops out of the replayed chain in one edit, regardless of how many records it was or what types they were:
line 43 "parentUuid":"070ce9c0-..." -> "parentUuid":"c0161067-..." (the server_tool_use record)
This relies on the same-msg_-id fold the issue body already establishes. In the affected file, 26 of 44 assistant messages were stored split across multiple records sharing one msg_ id, so the fold is the normal storage shape and not an edge case. After the edit the four records sharing msg_011CdnLrVr... reassemble as server_tool_use → advisor_tool_result → thinking → tool_use, and the session resumed cleanly.
Verification worth running before resuming, since a bad repair looks identical to a good one until the next turn: confirm every record still parses, that the chain shortened by exactly the number of injected records (237 → 234 here), and that every tool_use/tool_result pair in the chain resolves — including a control case on a known-good pair, otherwise a pairing check that silently matches nothing reads as a pass.
Two notes for anyone hitting this:
- Typing ahead during a server tool call is not a trigger. The queued text is stored as a
queue-operationrecord with nouuid, so it never enters the parent chain. Only chain-writing events (slash commands, auto-titling, and per @jameschien87 whatever else shares that injection path) can split the pair. - Writes into
~/.claude/projects/are refused by the permission classifier, via both the Bash and the file-edit tools. Claude Code cannot repair its own transcript, so the fix has to be run by the user directly.
@matthendrix — your three-record case is the one my correction predicted, so here is the rewrite that stops predicting and just handles it.
The bug in both of my earlier versions was the same: they counted. The first walked one record forward, the second I never generalised. Any fix shaped as "skip the reminder, then look" breaks the moment the interposed block is a different length or a different type — which is exactly what this thread keeps producing (1 record, then 2 identical ones 1 ms apart, now 2 system local_command entries plus the isMeta reminder).
So: don't count. Walk the parentUuid chain forward from the server_tool_use until a *_tool_result shows up, whatever is in between.
def heal(path):
recs = [json.loads(l) for l in open(path, encoding='utf-8') if l.strip()]
children = {}
for i, r in enumerate(recs):
if r.get('parentUuid'):
children.setdefault(r['parentUuid'], []).append(i)
def types(r):
c = (r.get('message') or {}).get('content')
return [b.get('type') for b in c if isinstance(b, dict)] if isinstance(c, list) else []
fixes = []
for r in recs:
if not any(t.endswith('_tool_use') for t in types(r) if t):
continue
frontier, seen, depth = list(children.get(r['uuid'], [])), set(), 0
while frontier and depth < 50: # depth cap, not a count of records
nxt = []
for j in frontier:
if j in seen:
continue
seen.add(j)
child = recs[j]
if any(t.endswith('_tool_result') for t in types(child) if t):
if child.get('parentUuid') != r['uuid']:
fixes.append((j, child['parentUuid'], r['uuid'], depth))
break
nxt.extend(children.get(child.get('uuid'), []))
else:
frontier, depth = nxt, depth + 1
continue
break
return fixes # (line index, current parent, correct parent, records interposed)
Measured against the three shapes reported in this thread, reconstructed as synthetic transcripts:
| interposed records | detected | reported depth |
|---|---|---|
1 (isMeta reminder — original report) |
yes | 1 |
| 2 (identical reminders, 1 ms apart — @ungeism) | yes | 2 |
3 (2 × system local_command + isMeta — @matthendrix) |
yes | 3 |
| 0, healthy pair (control) | no | — |
The control row is the part I'd check first in anyone's version of this. A repair that walks chains will happily "fix" a pair that was never broken if the match condition is loose, and an over-repair is harder to notice than a missed one — the session keeps working, the parent chain is just quietly wrong.
Two notes on the suffix matching. It keys on _tool_use / _tool_result rather than advisor_*, because @jameschien87's tool_search_tool_regex case is the same fold break with a different tool, and hardcoding advisor would miss it. And the depth cap of 50 is a runaway guard, not a statement about how many records can be interposed — if the chain is longer than that, something else is wrong and I'd rather bail than rewrite parents blindly.
I have not reproduced the trigger on 2.1.223 — my box is on 2.1.220 and I only have the transcripts from when it happened here in July. What I verified is the repair, against the shapes documented above.
Still reproducing on 2.1.227 (11 Aug 2026), four days past the 2.1.223 confirmation above. Three things here are new to the thread: a fourth interposed shape, timing that rules out "the rename raced the in-flight call", and a second unpaired call in the same file that every repair posted here walks straight past.
The occurrence (2.1.227, macOS 26.5.2, Anthropic API, CLI, /remote-control attached):
line 37 assistant msg_011CdwLD… tool_use (client-side) 17:11:08.017 uuid=20ae7007
line 38 assistant msg_011CdwLD… server_tool_use (advisor) srvtoolu_011ZE5… 17:11:08.092 uuid=28c00741 <- never gets a result
line 39 user tool_result (for line 37) 17:11:10.797 parent=20ae7007
… custom-title / agent-name records written here (no timestamp on them)
line 47 assistant msg_011CdwLG… thinking 17:11:13.419 uuid=ee1eb24e
line 48 assistant msg_011CdwLG… server_tool_use (advisor) srvtoolu_0142ZC… 17:11:13.442 uuid=05cf1526
line 49 system bridge_status "/remote-control is active · Continue here…" 17:12:00.904 parent=05cf1526
line 50 user isMeta:true "<system-reminder> The user named this session …" 17:12:03.744 parent=301976b6
line 51 assistant msg_011CdwLG… advisor_tool_result srvtoolu_0142ZC… 17:12:25.875 parent=f89ea3a8
Lines 48 and 51 share message.id — the fold the API requires, broken by the two records between them. Every prompt afterwards fails identically; three attempts are recorded ~10 hours later, all the same 400.
1. A fourth interposed shape: system / bridge_status
The thread so far documents one isMeta record, two chained reminders 1 ms apart, and two system local_command records plus the reminder. This one is a remote-control status banner plus the reminder. Another vote for @yurukusa's don't-count-walk-the-chain repair, and it shows the remote-control path reaches the same injection site as an explicit /rename.
2. The rename had already finished ~50 s before the reminder landed
This is the part I would most like a maintainer to look at, because it changes where the guard has to go.
The custom-title and agent-name records are written between the two advisor calls — file ordering puts them after 17:11:10.797 and before 17:11:13.419 (those record types carry no timestamp, so position is the evidence). Unlike @ungeism's case these are the first records in the file carrying that title, so this is the rename itself and not a re-assertion. The reminder it generates is not injected until 17:12:03.744: about 50 seconds later, and about 50 seconds into a different, later call.
So this occurrence is not a rename racing an in-flight call. The rename completed cleanly in a gap between two calls; the reminder was queued and flushed at the next available turn boundary, which happened to fall inside the next server-tool call. A fix guarded on "is a server tool in flight at rename time" would not have caught this one — the guard belongs at the injection/flush site, not at the rename.
It also explains why long-running server tools dominate these reports: the second call was open for 72 seconds (17:11:13 → 17:12:25), wide enough to swallow almost any queued reminder.
3. Same file, a second break: an unpaired server_tool_use with no result at all
srvtoolu_011ZE5… at line 38 is an advisor call with no advisor_tool_result anywhere in the file. It was emitted in the same assistant message as a client-side tool_use (line 37, same message.id), and that tool's result must come back as a user turn — line 39 — so the message is split before the advisor result could ever be appended. The result simply never appears.
Two consequences:
- For the repair scripts in this thread: they all anchor on a pair, walking from a
server_tool_useto the record carrying its matching result id. An unpaired call gives that walk nothing to anchor on. I have not run any of them against this file, so I am making the structural point only, not predicting their output — but a healed-file check that asserts everyserver_tool_useid has a matching result would cover the shape. - Unverified, deliberately: I did not test whether the orphan alone still 400s. The reported error names only the split pair's id, and this session was abandoned rather than repaired, so the file is intact but the repair path was never exercised. Offering it as a shape a fix should handle, not as a proven second failure mode.
Environment: 2.1.227 at the time of corruption (2.1.228 now), macOS 26.5.2, Anthropic API, Opus, CLI entrypoint, /remote-control attached.
Still reproducing on 2.1.234 (18 Aug 2026), six days and seven releases past the 2.1.227 confirmation above. The interposed run here is the single isMeta record from the original issue body, so that first shape is still live alongside the later ones.
The occurrence (2.1.234, macOS 26.5.2, Anthropic API, CLI, custom CLAUDE_CONFIG_DIR). Times are offsets from the server_tool_use record:
line 53 attachment T-10.884
line 55 custom-title (no uuid, no timestamp)
line 56 agent-name (no uuid, no timestamp)
line 57 assistant msg_011CeAJm… thinking T-00.008 uuid=f515457f
line 58 assistant msg_011CeAJm… server_tool_use (advisor) srvtoolu_01TR… T+00.000 uuid=605500e8
line 59 user isMeta:true "<system-reminder>The user named this session …" T+87.319 parent=605500e8
line 60 assistant msg_011CeAJm… advisor_tool_result srvtoolu_01TR… T+148.071 parent=69849eca
Lines 57, 58, 60 and 61 share msg_011CeAJm…. A second advisor pair in the same file (lines 197/198, nothing interposed) never failed, which gives a same-session control for the fold.
The rename finished before the call started, not during it
The timing point in the 2.1.227 report above reproduces here with a tighter bound. The custom-title and agent-name records carry no timestamp, so position is the only evidence, but position puts them in the 10.9 second window before the thinking record, and the advisor call does not start until 8 ms after that. The rename was complete before the call existed. The reminder it generated was not injected until 87 seconds into that call, which stayed open for 148 seconds.
So this occurrence contains no in-flight race at all. The reminder is queued at rename time and flushed at whatever turn boundary comes next, and when a server tool is open at that moment it lands inside the pair. A guard conditioned on "is a server tool in flight when the rename happens" would not have caught this one. The guard has to sit at the flush site, as the 2.1.227 report argued. The title's "mid-server-tool-call" describes the injection, not the rename.
The write block is not scoped to ~/.claude
Confirming the 2.1.223 note that the permission classifier refuses transcript writes, with one extension. This session ran with a CLAUDE_CONFIG_DIR outside ~/.claude, and writes to <CLAUDE_CONFIG_DIR>/projects/….jsonl were refused through both Bash and the file-write tool, while a write to the session scratchpad went through. The classifier keys on the transcript path shape rather than on the default home, so Claude Code cannot repair its own transcript under a custom config dir either. The user has to run the repair.
One trap worth fixing in every repair script here, mine included
Before finding this thread I wrote a narrower repair: drop user records interposed between the server_tool_use and the same-msg_-id continuation, then reparent the survivors. It healed this file. It would have silently missed the system local_command shape reported above, so the suffix-walk repair posted earlier in the thread is the shape to use.
The part I would change in all of them is the no-op message. After a successful heal, a second run prints nothing to fix. An unrecognised interposed shape also prints nothing to fix. I hit exactly that: the script ran and healed the file, then a second run printed nothing to fix, which read as a failure. The only thing separating the two readings was the .bak the first run had already written.
Report the inspection, not only the repairs: 4 server_tool_use records, 3 paired and contiguous, 1 repaired tells a healthy file apart from a shape the matcher does not recognise. A silent pass and an unmatched shape should not print the same line.
Still reproducing on 2.1.275 (2026-09-18, macOS, Anthropic API, CLI), a month and ~40 releases past the 2.1.234 confirmation above. The interposed run is the original single-record shape from the issue body: one isMeta user record carrying the "The user named this session …" reminder. Four things in this specimen are new to the thread.
The occurrence. Times are offsets from the server_tool_use record. The session was a background (sessionKind: bg) session with a custom title set at start; no /rename was typed.
assistant thinking T-00.0
assistant server_tool_use (advisor) srvtoolu_01K2hgswqYbWkHCayA2DV3w8 T+00.0
user isMeta <system-reminder> The user named this session "<title>" … T+47.6
assistant advisor_tool_result tool_use_id=srvtoolu_01K2hgswqYbWkHCayA2DV3w8 T+104.7
On disk the pair is complete and on the active parentUuid branch. There is no compaction record anywhere in the file.
1. The in-flight turn survived; the next turn did not. After the advisor_tool_result the same turn made five more successful API calls (tool_use / tool_result round-trips, then a final text message). The first 400 came on the first user prompt of the next turn, and every prompt after that:
API Error: 400 messages.3.content.0: unexpected `tool_use_id` found in `advisor_tool_result` blocks: srvtoolu_01K2hgswqYbWkHCayA2DV3w8. Each `advisor_tool_result` block must have a corresponding `server_tool_use` block before it.
So the in-memory history used during the turn tolerated the interposed record; the history rebuilt at the turn boundary did not.
2. messages.3 is the literal fold break, not condensation. Index 3 is exactly the four-message replay [user prompt, assistant(thinking + server_tool_use), user(reminder), assistant(advisor_tool_result)]. The reminder forces the result into its own assistant message, which is the mechanism in the issue body. This discriminates against the compaction theories in #60523 / #95074 for this shape: nothing was summarised away.
3. /advisor off does not recover an already-broken session. Sequence after the first 400: /compact (wrote a local_command record and no compaction record; the next prompt still 400'd at the same index), then /advisor → "Advisor disabled", then a prompt → same 400, then /advisor back on → same 400. #95074 (filed today) reports /advisor off as the escape; on 2.1.275 it is not, at least once the orphan is in the replayed history. The advisor toggle changes whether new calls happen, not what is replayed.
4. Cross-ref to #90771. An away_summary system record sits between the last good turn and the first 400, with no compaction record, which is that issue's exact discriminator. #90771 also found the transcript consistent on disk with both blocks present. That is what this issue's mechanism produces, so #90771 may be the same bug observed from the away/return side rather than a separate re-assembly path.
Trigger note, echoing @ungeism: no deliberate rename happened. The title was set once at session start and the reminder still landed mid-flight 47 s after the server_tool_use.
Still reproducing on 2.1.278, and a correction to my one-field repair above: on this version it is not enough when the split message also carries a client tool_use.
Trigger. /mcp was run while an advisor() call was in flight ("MCP dialog dismissed"). Two system / local_command records landed between the pair, the shape in #92509:
line N assistant msg_011CfGTr… server_tool_use (advisor) srvtoolu_01H4… 10:56:31 uuid=682ffb3c
line N+1 system local_command <command-name>/mcp</command-name> 10:56:54 parent=682ffb3c
line N+2 system local_command <local-command-stdout>MCP dialog dismissed 10:56:54 parent=<N+1>
line N+3 assistant msg_011CfGTr… advisor_tool_result srvtoolu_01H4… 10:59:41 parent=<N+2>
line N+6 assistant msg_011CfGTr… tool_use (Bash)
Every prompt afterwards failed with 400 messages.27.content.0: unexpected tool_use_id found in advisor_tool_result blocks.
The one-field repair did not hold. Re-pointing the result's parentUuid at the server_tool_use record, as I described in July, left the parentUuid walk clean, and the next resume failed with the identical 400 at the identical index.
Why, from the 2.1.278 bundle. After buildConversationChain walks parentUuid back from the newest record, a parallel tool-result recovery pass (it reports tengu_chain_parallel_tr_recovered) runs for every assistant message that contains a client tool_use. For each record sharing that message.id, it collects off-chain child runs of attachment, non-compact_boundary system and isMeta user records, and splices them back into that message's segment in what reads as file order (I did not decode the sort key). This message also ran Bash, so the two /mcp records, by then a dead side branch hanging off the server_tool_use, were recovered and put back between the call and its result; the identical 400 at the identical messages.27 after the one-field edit is the measurement that they landed there. This looks newer than 2.1.223: @matthendrix's case above had a client tool_use in the same message and three interposed records of these types, and the one-field edit resumed cleanly there. I did not check which release introduced the pass.
Repair that worked on 2.1.278. Delete the interposed records (matched by uuid, not by line number) and re-point the result's parentUuid at the server_tool_use record. After that the session resumed, answered, ran four tool calls and completed a new advisor call with no 400.
Checker note. A check that only walks parentUuid reads the half-repaired file as clean. To catch this case, also flag any off-chain child of a record in the same message.id group as a server_tool_use whose type is attachment, system other than compact_boundary, or isMeta user. Here that flagged 1 before the deletion and 0 after.
Environment: Claude Code 2.1.278 (read from the affected records), Linux, CLI, /remote-control attached. The affected transcript holds 791 server_tool_use records; this was the only one with a slash-command record interposed.
Please note that to prevent your issue from auto-closing you would need to collect at least 10 thumbs up, or comment every time before the 14 days stale interval expires. See https://github.com/anthropics/claude-code/issues/87647 for details, and consider upvoting that issue for visibility.