Agent intermittently emits malformed tool-call delimiters (literal "course"/"invoke") in long sessions

Open 💬 0 comments Opened Jun 21, 2026 by ken-jo

Summary

During a long Claude Code session, the agent (Opus 4.8) repeatedly produced malformed tool calls. The CLI rejected each with Your tool call was malformed and could not be parsed. Please retry. and the turn ended without performing any action. This happened ~10+ times in a single session, each time forcing the user to manually say "continue / retry".

Symptom

Instead of the tool-invocation syntax, the model emitted literal text in place of the opening delimiter token — e.g. the word course, court, or a bare invoke / parameter — so the parser never recognized a tool call. The corrupted shape looked roughly like:

course
invoke name="Bash"
parameter name="command" ...

instead of a valid function-call block. Re-sending the exact same Edit/Bash/Read on the next turn with correct delimiters succeeded every time, which confirms the parameters/content were fine and only the invocation delimiter was corrupted.

When it happened

  • Very long session: hundreds of successive tool calls, many near-identical Edit / Bash / Read in tight succession (iterating on a UI with screenshot checks).
  • Failure frequency rose as the session/context grew; clustered in the later, high-iteration portion.
  • Intermittent/probabilistic — a careful "retry" sometimes still reproduced it 2–3 times before a clean call landed.

Impact

  • ~10+ wasted turns; each ends with no action and needs a manual nudge.
  • Specifically degrades the long, many-small-edits agent workflow.

Environment

  • Claude Code: 2.1.185
  • Model: claude-opus-4-8
  • Platform: Linux

Hypothesis

Looks like model-side corruption of the special tool-call delimiter token (not a content or escaping problem), more likely under long context + many repetitive tool calls. Separately, a single different failure was a JSON-escaping error in a hand-built structured tool input (unicode-escaped non-ASCII text) — likely a distinct root cause.

Approximate repro

  1. Run a long session with many consecutive small Edit/Bash/Read tool calls (e.g. iterating on a component, screenshotting between edits).
  2. Observe intermittent tool call was malformed and could not be parsed, turn ends; re-issuing the identical call works.

View original on GitHub ↗