[Bug] Stray token "count" injected before tool calls causes parse failure in Claude Code
Bug Description
---
フィードバック文(日本語)
【バグ】ツール呼び出しの直前に余計なトークンが混入し parse 失敗する(Claude Code / Opus 4.8 1M)
症状:アシスタントがツールを呼ぶ際「Your tool call was malformed and could not be parsed」が頻発。1セッションで8回以上、本番DB操作の途中でも発生し、作業が再三停止した。
再現条件(重要):
- アシスタントが説明文(日本語)を数行書いた直後にツール呼び出し(MCP execute_sql / Bash / Write 等)を出すと、呼び出しブロックの直前に余計な単語「count」が1つ漏れて出力され、構文が壊れて parse 失敗する。
- 説明文を書かずメッセージ先頭でツール呼び出しを出すと発生しない(現状これが唯一の回避策)。
- 同じ呼び出しをリトライしても高確率で再発。
影響:作業停止・強いストレス。フックでは防げない(parse より手前で壊れるため、PreToolUse 等が発火しない)。
要望:①パーサを寛容にして呼び出し直前の不正トークンを無視する、②または出力段で stray token をサニタイズする等の、ハーネス側ガード。「先頭でツール呼び出し」という回避に頼らせない形を希望。
---
Feedback (English)
[Bug] A stray token is emitted right before a tool call, causing "tool call malformed and could not be parsed" (Claude Code / Opus 4.8 1M)
Symptom: Tool calls frequently fail with "Your tool call was malformed and could not be parsed." Occurred 8+ times in a single session, including mid production-DB operations, repeatedly halting work.
Reproduction (key):
- When the assistant writes a few lines of prose and then immediately makes a tool call (MCP execute_sql / Bash / Write, etc.), a stray token — literally the word "count" — leaks onto the line immediately before the tool-call block, corrupting the syntax so it fails to parse.
- It does NOT happen when the assistant leads the message with the tool call (no preceding prose). This is currently the only reliable workaround.
- Retrying the same call reproduces it with high probability.
Impact: Work stops; extremely frustrating. Hooks cannot prevent it (the failure happens before the parse stage, so PreToolUse/UserPromptSubmit hooks never fire).
Request: Add a harness-side guard — (1) make the parser tolerant and ignore an invalid stray token immediately before a tool-call block, or (2) sanitize stray tokens at the output stage. Users shouldn't have to rely on "lead with the tool call" as a workaround.
---
Environment Info
- Platform: darwin
- Terminal: ghostty
- Version: 2.1.158
- Feedback ID: d720ccaa-5237-4938-adac-1bcf1fa47995
Errors
[]This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗