[BUG] Bash tool calls emitted as raw <invoke> text instead of executing

Open 💬 25 comments Opened May 30, 2026 by atwoodwang

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 both 2.1.156 and 2.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:

  1. Use Claude Code on macOS with Opus in a long repository workflow involving repeated Bash calls.
  2. 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.
  3. After the session becomes long-context, observe that some intended Bash calls are printed to the conversation as raw text beginning with call and <invoke name="Bash">.
  4. Inspect the session JSONL and compare normal versus malformed turns:
  • Normal: content[].type = "tool_use", name = "Bash", has id, followed by matching tool_result.
  • Malformed: content[].type = "text" containing raw <invoke name="Bash">..., no tool_use_id, no matching tool_result.
  1. 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 call before <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 blocks
  • 2.1.158: 1 malformed block
  • stop_reason values:
  • end_turn: 22
  • tool_use: 1, but still no structured tool_use object
  • 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 blocks
  • 2.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, missing tool_use despite stop_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 structured tool_use object.
  • 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.

View original on GitHub ↗

25 Comments

github-actions[bot] · 1 month ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/61367
  2. https://github.com/anthropics/claude-code/issues/62344
  3. https://github.com/anthropics/claude-code/issues/60584

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

jwlim94 · 1 month ago

fix it

TIANQIAN1238 · 1 month ago

hey COME here and fix it

it sucks

szichedelic · 1 month ago

please fix this, it sucks

TIANQIAN1238 · 1 month ago
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.

szichedelic · 1 month ago
> 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.

Sora-bluesky · 1 month ago

+1 — reproducing the same symptom right now in a long-context session.

Environment

  • Model: claude-opus-4-8 (1M context)
  • Claude Code (Cowork mode / Code tab)
  • Session: ~200k+ tokens of cached context (long article-writing workflow)

Symptom
Across this single session, repeated malformed tool calls with the literal text count appearing right before <invoke name="...">. Failures cluster on Write and Edit for large HTML content (130+ lines), and also hit Read after long free-text preambles. Retries with shorter preambles sometimes succeed, matching the pattern described in #64112.

Reproduction trigger (consistent)

  1. Long session (cache-read tokens high)
  2. Assistant generates a several-sentence preamble explaining intent
  3. Assistant then attempts a Write with a long content parameter
  4. The tool call is emitted as raw text starting with count<invoke name="Write">...
  5. Harness returns "Your tool call was malformed and could not be parsed. Please retry."
  6. Once it happens, it tends to recur within the same session (consistent with the in-context few-shot poisoning hypothesis in #62344)

Workaround that helped (not a fix)
Switching to claude-opus-4-7 mid-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_use when stop_reason == "tool_use") would at least surface the failure earlier instead of letting it cascade.

amber-lzz · 1 month ago

it disturbe me too

novacoole · 1 month ago

Happening frequently for me with Fable 5.

teastburn · 1 month ago

In my case, I was using an organization login that had denied all tool calls. Ensure in /permissions there isn't a * under the Deny section. Or something similar. Also beware: Claude code would hallucinate tool outputs in this failure mode!

qoosdd89382 · 1 month ago

Still there. Can you please fix it? It's ridiculous...

wenqihuang · 1 month ago

It happens more than 50% of all cmd calls to me, which is extremely annoying. please fix it.

hooyao · 29 days ago
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.

axisrow · 29 days ago

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 comment tool 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:

  • Claude Code 2.1.179
  • macOS 26.5.1 (arm64)
  • Model: Opus 4.8

Matches #67307 (Opus 4.8 specifically). +1 — would appreciate prioritization.

axisrow · 29 days ago

Update — same session, bug fired again (and clustered):

Right after the comment above, the bug misfired again on a gh pr merge call — 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.

manssorr · 28 days ago

This is happening a lot for me lately!

huohuli008 · 28 days ago

当持续使用较长上下文后,极容易出现,甚至到了连续失败的情况,只能通过Compact或Clear解决。

keinn51 · 28 days ago

help me!

xstreamka · 28 days ago

I confirm that these errors happen all the time today.

axisrow · 24 days ago

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:

The model's tool call could not be parsed (retry also failed).

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:

TEXT:call
<invoke name="Bash">
<parameter name="command">cd <project-dir>
CI=true python3 -m pytest tests/tes      <-- cut off here

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 especially gh pr create with a multi-line body). Single short commands in the same session were fine.

Env:

  • Claude Code 2.1.183
  • Linux 5.15.0 (x86_64)
  • Model: Opus 4.8

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 create calls both misfire. Same family as #67307.

yuzeguitarist · 24 days ago

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.

eldkqmfhf123 · 23 days ago

Seeing what looks like the same root cause (tool-call intent leaking into the text channel
instead of a structured tool_use block), but with a different failure mode worth adding here.

In my case, only the leading call token of the <invoke ...> block leaks — and then it
degenerates into a repetition collapse: a single assistant response emitted \n\ncall
~32,000 times (a ~256 KB text block).

Environment

  • Claude Code (CLI), inside a tmux session, macOS
  • Model: Opus 4.8 (1M context)claude-opus-4-8[1m]
  • Long multi-turn coding session with many consecutive Edit/Read/Bash tool calls

Evidence (from the session .jsonl, code/prose redacted)

The call string is stored inside the text field of type:"text" blocks (not a tool_use
block), same as this issue — just truncated to the first token and then repeated:

"type":"text","text":"<redacted prose>\n\ncall\n\ncall\n\ncall\n\ncall ... (repeated ~32000 times)"

Per-turn count of call inside type:"text" blocks, chronological (shows the escalation):

3, 1, 3, 31977, 1, 1, 1, 1, 1, 1, 1, 2

Reproduced locally with:

grep -o '"type":"text","text":"[^"]*"' <session>.jsonl | grep call

Relationship to this issue

  • #63870: the full call + <invoke name="Bash">...</invoke> XML leaks as text → not executed.
  • This variant: only the leading call leaks, 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

  • Correlates with long context (the collapse happened deep into a long session, consistent with the

high cache-read tokens others reported).

  • No tool was mis-executed and no data was corrupted — the call is plain text.
  • No project source code is needed to reproduce; all code/prose redacted above.
KoichiroHatsuse · 16 days ago

Adding a data point: still reproducing on 2.1.196 (Opus 4.8 1M), so the regression persists well past the 2.1.156/2.1.158 transcript above.

Environment

  • Claude Code 2.1.196
  • Model: Opus 4.8 (1M context)
  • Windows 11 Pro / PowerShell (primary shell; failures occur on Bash tool calls)

Symptom matches this issue exactly — an intended Bash tool call is emitted as plain assistant text instead of a structured tool_use, so nothing executes and the turn stalls. Same leaked shape:

count
<invoke name="Bash">
<parameter name="command">cd "...worktrees/review-pr-270" && git branch --show-current && gh pr view 270 ... </parameter>
<parameter name="description">...</parameter>
</invoke>

Stray-token variant: in my case the leaked prefix token is count (vs the call/court reported here and in #68354). Same failure, different garbled token — consistent with the "adjacent-vocab token selected instead of the antml:invoke opening tag" theory.

Trigger correlation: clusters in long, tool-call-heavy sessions — specifically PR-review / merge-gate workflows that chain many git + gh commands 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, /clear or a new session clears it (the malformed shape does not recover within the same session).

docentYT · 9 days ago

Same with ollama and qwen3.5:9b-q4_K_M.

glzlaohuai · 2 days ago

Still reproducing on 2.1.197 with claude-opus-4.8