[Bug] claude-opus-4-7: Malformed tool calls with stray text prefix in extended MCP sessions
Open 💬 7 comments Opened Jun 14, 2026 by AgentGymLeader
Summary
In extended sessions (150k+ context tokens) with heavy MCP tool usage, claude-opus-4-7 occasionally prefixes tool call XML with stray text tokens (observed: court\n immediately before <invoke>), causing the runtime to reject the call as malformed.
Reproduction context
- Model:
claude-opus-4-7(claude-sonnet-4-6 does NOT reproduce) - Session length: ~150k+ tokens, multi-hour session
- Tool density: 10+ MCP tool calls in the session (Gmail, Linear, Bash, Read, etc.)
- Language: Japanese-language responses with inline tool calls
- Frequency: ~5–6 occurrences in a single session (not every call, but clustered in later turns)
Symptom
Tool calls are emitted with a stray text prefix, e.g.:
court
<invoke name="mcp__gmail__search_threads">
<parameter name="query">...</parameter>
</invoke>
Runtime error: Your tool call was malformed and could not be parsed
Impact
- Tool call silently fails; model must retry
- In a long session this happened 5–6 times, each requiring a manual retry by the user
- Disruptive for workflows that depend on reliable MCP tool execution
Workaround
Switching to claude-sonnet-4-6 eliminates the issue entirely.
Notes
- The stray token (
court) appears to be a fragment leaking from the model's internal reasoning/narration before the tool call XML - Does NOT appear to be a prompt injection or hook issue — the stray text originates from model generation, not from injected context
- CLAUDE.md / hooks cannot structurally prevent this since the error occurs at generation time, before any hook can intercept
Environment
- Claude Code CLI (latest)
- macOS darwin 25.5.0
- MCP servers: Gmail, Linear, Bash, Read (standard tools)
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗