#10074·pi

Anthropic tool calls: corrupted non-ASCII edit arguments are silently accepted (dropped `u` in `\\uXXXX` → `\b`/`\f` control chars)

Author: hoonysisCreated Sep 26, 2026Updated Sep 28, 2026

What happened?

With Claude models, edit calls on files containing Korean text fail very often, and occasionally corrupt a file. I have been tracking this for about three weeks. It keeps coming back and costs a lot of retries.

There are two symptoms, usually in the same sessions:

  1. Control characters instead of Korean. The arguments contain C0 control characters where Korean characters were intended.
  2. Garbage calls. An edit whose oldText is a few meaningless characters that exist nowhere in the file. Several in a row can occur.

Both usually fail safely as "Could not find ... oldText". Once, a corrupted newText was written to a file and had to be repaired by hand.

The pattern behind symptom 1

It points to a \\\uXXXX escape whose u is missing in the tool-input JSON. When the next hex digit happens to be b or f, the result is still valid JSON: \b / \f followed by the remaining three hex digits. JSON.parse accepts it, so the tool runs with wrong strings instead of returning an error.

Illustration (synthetic): intended \ub0b4 → emitted \b0b4 → parsed as U+0008 + 0b4.

Evidence

Automated scan of my local session logs (edit arguments only, no file contents):

Model edit calls errors error rate args with C0 control chars
openai-codex/gpt-6-astra 398 9 2.3% 0
openai-codex/gpt-6-sol 82 5 6.1% 0
xai/grok-4.7 27 3 11% 0
anthropic/claude-opus-5-5 212 86 40.6% 15
anthropic/claude-opus-5 34 20 58.8% 8
anthropic/claude-fable-5-1 20 8 40% 2
  • All control characters found in Claude edit arguments are U+0008 (\b) or U+000C (\f). 848 of 873 are followed by exactly three hex digits.
  • An earlier manual classification over 20 days: 52 of 68 failed Opus 5.5 edits had lost their Korean text. GPT, Grok and DeepSeek had none.
  • I found no case where repairJson turned an invalid escape into a literal backslash, so I don't think the repair path causes this. The corrupted cases are already valid JSON before any repair.

What I ruled out

  • eager_input_streaming: on vs off, 21 attempts each. One corrupted call in each group.
  • Session length: I forked an affected session and ran four edits each with the default edit, a hash-anchored edit extension, and all extensions loaded. All 12 succeeded. On the same day, the original window failed 3 of 4.
  • Edit tool format: the hash-anchored edit tool made no difference.
  • Encoding in general: in the same failing window, shell edits, write, and a Node script inside the shell all wrote Korean correctly.

A context effect

The failures cluster after corrupted strings have been visible in the context. In the original window, the broken calls closely resembled an example string that had just been displayed during analysis. Later, a fresh session reproduced it twice in a row right after reading notes that contained such an example. I also hit the garbage-call symptom about six times today in a long session, after the raw examples had already been removed from those notes, so removing them does not prevent it.

So this looks like a model-side tendency that feeds on its own output. I can't prove where the u goes missing from the client side.

Why report it here

Even if the root cause is the model, the pi-side problem is that corruption is silent. A cheap guard would make it a normal retryable validation error:

  • For edit / write (or any string tool args), reject C0 control characters other than \t, \n, \r, with a message like "argument contains control character U+0008; possible malformed \\u escape".
  • Or, in the Anthropic provider, flag \b/\f followed by hex digits in the raw partialJson before parsing.

If the context effect is real, the error should not echo the corrupted string back to the model. Naming the code point is probably enough.

I can write this guard as a local extension (a tool_call handler returning { block, reason }). It seems worth handling in core, though, because every non-ASCII user on Claude is exposed to silent file corruption.

Related: #6278 (Claude tool-call schema errors, closed as model behavior). This case is narrower: non-ASCII content only, and it can corrupt files without any validation error.

Steps to reproduce

Not deterministic. Using a Claude model, ask for several edit calls that replace Korean text in a UTF-8 file. It is much more likely once a corrupted string has appeared in the conversation. Failures show up as oldText mismatches whose arguments contain U+0008/U+000C, or as very short oldText values.

I can share the log-scanning script (counts only) if helpful.

Version / environment

  • pi 0.87.1 (@earendil-works/pi-coding-agent), Windows, PowerShell 7
  • Provider anthropic, Claude subscription login through the third-party @gotgenes/pi-anthropic-auth 3.3.2 extension. It only handles authentication, but I have not tested with an API key.