[BUG] tool_use input intermittently malformed — emits literal "court"/"<invoke>" text instead of a valid tool call
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?
During a long coding session, the assistant intermittently emits a malformed
tool call. Instead of a valid tool-use block, the literal text court followed
by an XML-style <invoke name="Edit">...</invoke> block appears in the
assistant's visible message as plain text. The tool never executes.
It happens most often when the assistant writes explanatory prose immediately
before a tool call (e.g. "Now I'll edit X:" followed by an Edit call). Tool
calls placed as the first element of a reply, with little or no preceding
prose, succeed reliably. The same Edit, retried with minimal preceding text,
then goes through.
Net effect: the edit silently does not apply, the user sees raw <invoke>
markup in chat, and the assistant must detect the failure and retry — often
several times — which wasted a large part of a long session.
What Should Happen?
Every tool call the assistant intends to make should be emitted as a valid,
executable tool-use block, regardless of how much prose precedes it in the
same message. A tool call must never leak into the visible message as literalcourt / <invoke> text.
Error Messages/Logs
No stack trace — the failure is silent. The symptom is literal text in the
assistant's reply, e.g.:
court
<invoke name="Edit">
<parameter name="replace_all">false</parameter>
<parameter name="file_path">/path/to/file.php</parameter>
<parameter name="old_string">...</parameter>
<parameter name="new_string">...</parameter>
</invoke>
This text appears as part of the rendered markdown message; no Edit is
performed and no error is returned.
Steps to Reproduce
Hard to reproduce deterministically (intermittent), but the pattern:
- Start a long coding session with many sequential Edit/Read tool calls
(observed in a session with 50+ tool calls editing a Laravel codebase).
- Have the assistant make Edit calls that are preceded in the same message
by a sentence or two of explanation ("Now I'll change X:", "Pozriem ...").
- After many turns, some Edit calls are emitted as literal
court/
<invoke> text instead of executing.
- Retrying the SAME edit with no/minimal preceding prose succeeds.
Correlation observed: malformed calls had explanatory prose before them;
successful calls were the first element of the reply.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.143 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
- Environment: Claude Code running inside the VS Code native extension.
- The session involved hundreds of file edits across a PHP/Laravel + React
repo; the malformed-call rate rose as the session grew longer.
- Workaround that reliably avoids it: emit the tool call as the first element
of the reply, one tool call per message, with explanation moved AFTER the
tool result rather than before the call.
- Impact: significant — repeated silent edit failures + retries consumed a
large portion of a long working session and surfaced raw <invoke> markup
to the user.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗