Bug: Tool call intermittently emitted in a malformed envelope ("court" + bare <invoke>), so it never executes
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Bug: Tool call intermittently emitted in a malformed envelope ("court" + bare <invoke>), so it never executes
Summary
Intermittently, instead of a well-formed tool/function call, the assistant emits a
malformed envelope: a stray literal token court followed by a bare<invoke name="...">...</invoke> block that is missing the function_calls
wrapper and the antml: namespace prefix. The harness parser does not recognize
it as a tool call, renders it as literal text, and nothing executes — the turn
appears to hang / "crash".
Expected
The tool call is emitted in the canonical structured format and executed.
Actual
Output contains literal court + an unnamespaced/unwrapped <invoke>; no tool runs.
Re-sending sometimes works (the same session also produced many correct calls).
Likely root cause (observed, internals not visible)
Corruption of the tool-call control-token serialization:
antml:namespace prefix dropped (antml:invoke→invoke)function_callswrapper omitted- a spurious literal
courtinserted at the opening-tag position
Unrelated to command content / Docker / DB / project — purely the call envelope.
Repro conditions (correlated)
- Long conversation / large context
- Many tool calls in quick succession
- Right after the assistant described tool-call syntax in prose
Impact
Work stalls; user must resend. No data/code corruption (output-format only).
Suggested mitigations
- Model: validate/regenerate the tool-call envelope; self-repair malformed ones
- Harness: detect near-miss envelopes (e.g.
court+ bare<invoke>) and either
auto-correct or return an explicit "malformed tool call" error instead of
silently passing it through as text
Environment
- Claude Code (VS Code extension), model: Opus 4.8 (1M context)
What Should Happen?
The tool/function call should be emitted in the correct envelope (proper function_calls / invoke with the antml: namespace) and executed by the harness. Instead it is sometimes rendered as literal text — a stray court token followed by a bare <invoke> that is missing the wrapper and namespace — so nothing runs.
Error Messages/Logs
Steps to Reproduce
Note: this is intermittent/probabilistic — no deterministic minimal repro found.
- Use Claude Code (VS Code extension) in a long session with many tool calls.
- Have the assistant make several tool calls in quick succession (shell commands, repeated file edits, etc.).
- Occasionally, instead of executing a tool call, the reply prints it as literal text:
a stray court token followed by a bare <invoke name="...">...</invoke>
(missing the function_calls wrapper and the antml: namespace).
- The tool does not run and the turn appears to stall. Re-sending sometimes yields a correct call.
Observed correlates: long context; many rapid tool calls; right after the assistant
described tool-call syntax in prose. Model: Opus 4.8 (1M context). Claude Code 2.1.177.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.177
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_