[Bug] Claude API Error: Malformed tool-invocation tag with leaked control tokens after context compaction
Bug Description
### Title
Model intermittently emits literal "court" + malformed tool-call tag instead of a valid tool invocation (calls are dropped)
### Environment
- Claude Code: 2.1.186
- OS: macOS (Darwin 25.5.0)
- Model: claude-opus-4-8 (Opus 4.8); also reproduced after switching to Opus 4.8 1M context
- Session id: f0861d81-280a-48ce-8651-4cacd7cf2e68
### Summary
During an agentic session, the assistant intermittently emits a stray literal
text token court immediately followed by a malformed tool-invocation tag
(e.g. <invoke name="Bash"> lacking the correct antml: namespace /
function_calls wrapper) instead of a well-formed tool-call block. The harness
then rejects it with: "Your tool call was malformed and could not be parsed."
### Observed behavior
- The intended tool call (Bash, etc.) is silently dropped — the step does not run.
- The stray court text is visible in the assistant's output, looking like
leaked control tokens.
- It recurs even immediately after the assistant correctly explains the issue
and explicitly tries to avoid it, i.e. the model cannot self-correct within
the session.
### Conditions / frequency
- Frequency increased markedly AFTER a /compact (context compaction) and in a
long-running session.
- Persisted across a model switch (to Opus 4.8 1M context).
- When the same call is emitted correctly, it executes normally (so the command
itself is fine; only the invocation markup is corrupted).
### Impact
- Blocks tool use; the user must repeatedly wait for retries or run commands
manually via the ! prefix.
- No data loss, but it is confusing and resembles prompt injection (it is not —
court does not originate from any user input, repo file, or tool output).
### Expected behavior
The model should always emit a well-formed tool-invocation block, or the harness
should recover gracefully instead of dropping the call.
### Repro notes
Not deterministically reproducible, but reliably recurring in this session after
/compact. Full transcript available via the session id above.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.186
- Feedback ID: 65483a14-bc82-4b90-9a4a-b66447ca8e07
Errors
[]This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗