[BUG] Bash tool calls emitted as raw <invoke> text instead of executing
Preflight Checklist
- [x] I have searched existing issues. Similar reports exist (#61122, #61367, #62344, #63616), but this report adds detailed JSONL evidence from one session with 23 malformed Bash calls.
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code available to me (
2.1.158 (Claude Code)currently installed). The affected transcript contains failures on both2.1.156and2.1.158.
What's Wrong?
In a long Claude Code session, intended Bash tool calls were intermittently emitted as ordinary assistant text instead of structured tool_use objects. The UI showed raw invoke text like:
call
<invoke name="Bash">
<parameter name="command">...</parameter>
<parameter name="description">...</parameter>
<parameter name="dangerouslyDisableSandbox">true</parameter>
</invoke>
Because these records are plain text content instead of structured tool_use, Claude Code does not dispatch the Bash command. There is no tool_use_id and no matching tool_result.
This caused repeated false progress in one repo workflow: commits, verification commands, pushes, PR creation, PR merge, and cleanup commands were printed but not actually executed.
Important detail from the JSONL: one affected assistant message has stop_reason = "tool_use", but its content still contains only ordinary text and no tool_use object.
What Should Happen?
When Claude intends to run Bash, Claude Code should receive a structured tool_use object, execute the command, and append a matching tool_result.
If the model emits malformed tool-call text, Claude Code should surface an explicit parsing/tool-call error or reprompt internally. Raw <invoke name="..."> blocks should not be rendered as normal assistant prose or fed back into future context where they may cause cascading failures.
Error Messages/Logs
No shell error is shown, because the command is never dispatched.
Representative malformed JSONL shape:
{
"type": "assistant",
"message": {
"content": [
{
"type": "text",
"text": "...\\n\\ncall\\n<invoke name=\"Bash\">\\n<parameter name=\"command\">MAIN=...\\n...</parameter>\\n<parameter name=\"description\">Pull merged main and verify files</parameter>\\n<parameter name=\"dangerouslyDisableSandbox\">true</parameter>\\n</invoke>"
}
],
"stop_reason": "end_turn"
}
}
There is no tool_use object, no tool_use_id, and no following tool_result.
Steps to Reproduce
This is intermittent, but the affected local transcript provides a concrete session-level reproduction/evidence trail:
- Use Claude Code on macOS with Opus in a long repository workflow involving repeated Bash calls.
- In the affected session, ask Claude to perform normal git/test/PR workflow actions such as commit, verify, push, create PR, merge PR, and cleanup.
- After the session becomes long-context, observe that some intended Bash calls are printed to the conversation as raw text beginning with
calland<invoke name="Bash">. - Inspect the session JSONL and compare normal versus malformed turns:
- Normal:
content[].type = "tool_use",name = "Bash", hasid, followed by matchingtool_result. - Malformed:
content[].type = "text"containing raw<invoke name="Bash">..., notool_use_id, no matchingtool_result.
- Verify downstream state: earlier printed commands had no effect. In this transcript, later turns confirm commit was not made, regression log did not exist, remote branch was absent, PR was not created, PR stayed open, and cleanup was not done.
Concrete analyzed transcript:
- Project:
texas-holdem-poker-recorder - Session id:
1931487f-0ac9-47fe-b759-5ba244821147 - Local JSONL path pattern:
<home>/.claude/projects/-Users-<user>-playground-texas-holdem-poker-recorder/1931487f-0ac9-47fe-b759-5ba244821147.jsonl
JSONL evidence summary:
- Total JSONL lines analyzed: 2,233
- Normal assistant structured tool uses: 347
- Normal tool results: 347
- Malformed raw invoke blocks: 23
- Affected tool:
Bash - All malformed blocks start with stray text
callbefore<invoke name="Bash"> - First malformed block:
2026-05-29T15:22:53.436Z - Last malformed block:
2026-05-30T04:45:09.672Z - Versions:
2.1.156: 22 malformed blocks2.1.158: 1 malformed blockstop_reasonvalues:end_turn: 22tool_use: 1, but still no structuredtool_useobject- Affected turns had very high cache-read tokens, roughly 441k-489k, suggesting long-context state may be related.
Representative affected turns:
| JSONL line | Timestamp UTC | Version | stop_reason | Intended Bash description |
|---:|---|---|---|---|
| 1807 | 2026-05-29T15:22:53.436Z | 2.1.156 | tool_use | Commit temp-player fix |
| 1908 | 2026-05-29T16:16:04.950Z | 2.1.156 | end_turn | Typecheck + component test + build after 2-card placeholder |
| 2038 | 2026-05-29T16:32:17.752Z | 2.1.156 | end_turn | Push branch to origin |
| 2081 | 2026-05-29T16:34:03.745Z | 2.1.156 | end_turn | Create PR with simple body |
| 2115 | 2026-05-29T16:35:29.605Z | 2.1.156 | end_turn | Squash-merge PR #10 |
| 2141 | 2026-05-30T04:35:29.478Z | 2.1.156 | end_turn | Pull merged main and verify files |
| 2181 | 2026-05-30T04:45:09.672Z | 2.1.158 | end_turn | Update local main and verify final state |
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
Unknown. I started seeing this after updating around 2026-05-29. The analyzed transcript shows failures on 2.1.156 and still one occurrence after 2.1.158.
Claude Code Version
2.1.158 (Claude Code) currently installed.
Affected transcript contains:
2.1.156: 22 malformed raw invoke blocks2.1.158: 1 malformed raw invoke block
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other (zsh; terminal app unknown from the JSONL)
Additional Information
Related public issues found before filing:
- #49747: Opus mixes legacy XML tool-use format into JSON tool calls on longer payloads. This appears to be the broader/root issue. Later comments also describe full raw
<invoke>blocks being rendered as visible text, missingtool_usedespitestop_reason = "tool_use", and continued reproduction on Opus 4.8. - #61122: Bash tool call rendered as raw XML instead of executing
- #61367: Intermittent malformed tool calls emitted as plain text instead of structured
tool_use, then cascades via retry - #62344: Malformed tool calls in long sessions due to in-context few-shot poisoning
- #63616: Claude Code fails BASH invocations, reported on
2.1.156
Suggested investigation areas:
- Add a client-side invariant: if
stop_reason = "tool_use", assistant content must contain at least one structuredtool_useobject. - Detect raw
<invoke name="...">blocks in assistant text and treat them as malformed tool calls. - Avoid feeding raw malformed tool-call text back into future context.
- Investigate whether long-context sessions with high cache-read tokens increase the chance of malformed tool-call serialization.
25 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
fix it
hey COME here and fix it
it sucks
please fix this, it sucks
You also encountered this situation, right?
I tried to reproduce and troubleshoot it, but I found that it might be an issue on the model side.
Yes certain convos it happens constantly even on auto mode and it is blocking. It won't stop making the mistake and when prompted, Claude mentioned that it is a problem on the model side and that it can't help itself even though the correct tool call is committed to its memory.
+1 — reproducing the same symptom right now in a long-context session.
Environment
claude-opus-4-8(1M context)Symptom
Across this single session, repeated malformed tool calls with the literal text
countappearing right before<invoke name="...">. Failures cluster onWriteandEditfor large HTML content (130+ lines), and also hitReadafter long free-text preambles. Retries with shorter preambles sometimes succeed, matching the pattern described in #64112.Reproduction trigger (consistent)
Writewith a longcontentparametercount<invoke name="Write">...Workaround that helped (not a fix)
Switching to
claude-opus-4-7mid-session reduced the recurrence, consistent with #64774's finding that 4.7 and Sonnet 4.6 have ~0% failure rate while 4.8 is ~1.5%.Practical impact
Cost me ~30 retries in one session, and forced a full architectural workaround: moving from "assistant writes long HTML via
Write" to "assistant writes short JSON data + a generator script". Effectively gave up on Opus 4.8 for any task with long string parameters.Filing this as an additional data point. Adding the client-side invariant suggested in this issue (assert structured
tool_usewhenstop_reason == "tool_use") would at least surface the failure earlier instead of letting it cascade.it disturbe me too
Happening frequently for me with Fable 5.
In my case, I was using an organization login that had denied all tool calls. Ensure in
/permissionsthere isn't a*under theDenysection. Or something similar. Also beware: Claude code would hallucinate tool outputs in this failure mode!Still there. Can you please fix it? It's ridiculous...
It happens more than 50% of all cmd calls to me, which is extremely annoying. please fix it.
When you first see this mistake, you need to rewind immediately; you cannot let the malformed <invoke> persist in the context window, otherwise the model will enforce this behavior and keep repeating this error.
Hitting this repeatedly with Opus 4.8 — honestly it's getting really frustrating.
A Bash tool call gets emitted as raw
<invoke name="Bash">...</invoke>text in the transcript instead of executing. The command never runs; I have to re-issue it. It's intermittent but frequent enough to break flow during multi-step work (repeated git/gh and pytest calls).Notably, it happened twice in a row while the agent was trying to post this very comment — the
gh issue commenttool call itself leaked as raw<invoke>text and did not execute, both times. So the bug reproduces on the act of reporting the bug.Env:
Matches #67307 (Opus 4.8 specifically). +1 — would appreciate prioritization.
Update — same session, bug fired again (and clustered):
Right after the comment above, the bug misfired again on a
gh pr mergecall — also twice in a row — the tool call leaked as raw<invoke name="Bash">...</invoke>text and the merge didn't run until the third attempt.So in a single session it took multiple retries on two separate commands (posting this comment, then a merge) to get one Bash call to actually execute. The intermittency seems to cluster: once a call misfires, the next one or two tend to misfire too, then it recovers.
Env unchanged: Claude Code 2.1.179 / macOS 26.5.1 (arm64) / Opus 4.8. Same root cause as #67307.
This is happening a lot for me lately!
当持续使用较长上下文后,极容易出现,甚至到了连续失败的情况,只能通过Compact或Clear解决。
help me!
I confirm that these errors happen all the time today.
Another repro, this time it killed a whole session (Linux, Opus 4.8).
Same root cause as my earlier reports: a Bash tool call leaks into the transcript as raw
<invoke name="Bash">...text instead of executing. I went back through the saved session transcript (~/.claude/projects/<proj>/<id>.jsonl) and the failure pattern is very clear.Timeline within one session — 4 malformed-call events, in 2 clusters:
| Time (UTC) | Command being attempted | Outcome |
|---|---|---|
| 06:20:55 |
CI=true python3 -m pytest tests/...| leaked as raw text, retry succeeded || 06:21:19 |
gh pr checks 974 --watch| leaked as raw text, retry succeeded || 08:28:46 |
gh pr create(multi-line body) | leaked as raw text, retry FAILED || 08:29:50 |
gh pr create(retry) | leaked as raw text, retry FAILED → session stuck |The terminal entries in the transcript are literally:
twice in a row, after which the session could no longer make progress.
What the leaked block looks like in the transcript — the tool call is emitted as assistant text, prefixed with a stray token (
call) and truncated mid-stream:Confirms the clustering I reported before: once a call misfires, the next one or two misfire too. Both failure clusters here are pairs of consecutive misfires; in the 06:20 cluster the retry recovered, in the 08:28 cluster it did not and the session was lost.
Common trigger in every misfire here:
gh/ long multi-line Bash commands (pytest pipelines,gh pr checks --watch, and especiallygh pr createwith a multi-line body). Single short commands in the same session were fine.Env:
So this is not macOS-specific — reproduces on Linux too, and is severe enough to end a session (not just cost a retry) when two consecutive
gh pr createcalls both misfire. Same family as #67307.Same here. I’m seeing this frequently with Opus 4.8[1m].
The model seems to intend a tool call, but the tool invocation leaks into the visible text as plain text instead of being emitted as a structured
tool_use. The command is not executed, and the turn simply ends.This happened for me in a long 1M-context session, and sometimes it even appears when the context is very sparse.
My solution is to use the /goal mode.
Seeing what looks like the same root cause (tool-call intent leaking into the
textchannelinstead of a structured
tool_useblock), but with a different failure mode worth adding here.In my case, only the leading
calltoken of the<invoke ...>block leaks — and then itdegenerates into a repetition collapse: a single assistant response emitted
\n\ncall~32,000 times (a ~256 KB
textblock).Environment
tmuxsession, macOSclaude-opus-4-8[1m]Evidence (from the session
.jsonl, code/prose redacted)The
callstring is stored inside thetextfield oftype:"text"blocks (not atool_useblock), same as this issue — just truncated to the first token and then repeated:
Per-turn count of
callinsidetype:"text"blocks, chronological (shows the escalation):Reproduced locally with:
Relationship to this issue
call+<invoke name="Bash">...</invoke>XML leaks as text → not executed.callleaks, then loops into\n\ncall×~32k.Both look like the same underlying problem (legacy XML tool-use format mixing into the JSON
response, cf. #49747), differing only in how much of the block leaks and whether it then collapses
into repetition.
Notes
high cache-read tokens others reported).
callis plain text.Adding a data point: still reproducing on
2.1.196(Opus 4.8 1M), so the regression persists well past the2.1.156/2.1.158transcript above.Environment
2.1.196Bashtool calls)Symptom matches this issue exactly — an intended
Bashtool call is emitted as plain assistant text instead of a structuredtool_use, so nothing executes and the turn stalls. Same leaked shape:Stray-token variant: in my case the leaked prefix token is
count(vs thecall/courtreported here and in #68354). Same failure, different garbled token — consistent with the "adjacent-vocab token selected instead of theantml:invokeopening tag" theory.Trigger correlation: clusters in long, tool-call-heavy sessions — specifically PR-review / merge-gate workflows that chain many
git+ghcommands with&&in a single Bash call. Short/fresh sessions rarely hit it.Workaround that reliably works for me: retry once or twice; if it sticks,
/clearor a new session clears it (the malformed shape does not recover within the same session).Same with ollama and
qwen3.5:9b-q4_K_M.Still reproducing on 2.1.197 with claude-opus-4.8