Troubleshooting · as of 2026-10-13

Claude Code Refuses to Edit GBK Files

As of 2026-10-13, Edit and NotebookEdit in Claude Code save the whole file back as UTF-8, and before 2.1.296 every byte they could not decode was replaced with the character U+FFFD — that is what turned Chinese and Japanese text in GBK, Shift-JIS or Windows-1252 files into garbage. Since 2.1.296 (dated October 9, 2026 in the official changelog) such edits are refused with the message File is not valid UTF-8, and nothing is written. A safe order: confirm the encoding with the generic file command, back the file up and convert it with iconv, then let Claude Code edit again. The six Claude Code documentation pages this article consulted on 2026-10-13 — settings, troubleshooting, common-workflows, checkpointing, terminal-config and overview — list no setting that chooses a file encoding.

Updated 2026-10-14

Hit your subscription limit or keep getting 429s? Switch to an API billed per token and keep working with one key.

#File is not valid UTF-8#2.1.296#file -i#iconv -f -t

Four things to pin down first

2.1.296

The version that starts refusing

The sentence sits under 2.1.296 in the official changelog, whose version date reads October 9, 2026; the same sentence appears word for word in the CHANGELOG.md on GitHub, where version headings carry no date.

U+FFFD

What older versions wrote

The official error reference states: Before v2.1.296, Edit and NotebookEdit applied such an edit and saved every byte they couldn't decode as U+FFFD. It tells anyone still on an older version to update Claude Code.

0 bytes

What a refusal costs you

In the official words: Claude Code refused the change. Nothing was written, so the file is as it was. A refused edit leaves every byte of the file untouched.

file -i

The generic way to check

The file(1) manual says -i makes file output mime type strings (its example reads text/plain; charset=us-ascii) and --mime-encoding prints only that element. These are Unix tools, not Claude Code options.

Why files got corrupted, and why edits are refused now

As of 2026-10-13 the official docs answer both halves. The tools reference gives the reason for the refusal: The tools refuse because they save the whole file back as UTF-8, which would replace every byte they can't decode with the replacement character U+FFFD. The changelog says that before 2.1.296 Edit and NotebookEdit were replacing every non-ASCII character in files that are not valid UTF-8, and the error reference adds that they saved every byte they could not decode as U+FFFD, so one edit was enough to fill a GBK file with replacement characters. Now Edit and NotebookEdit refuse and leave the file untouched, and the message names three legacy encodings: Windows-1252, Shift-JIS and GBK. Note the scope: the error reference says the check covers the file's bytes as a whole, so even a file meant to be UTF-8 gets the same message when it holds one invalid byte sequence.

The changelog sentence verbatim

The Claude Code changelog entry for 2.1.296 reads: Fixed Edit and NotebookEdit replacing every non-ASCII character in files that are not valid UTF-8 (Windows-1252, Shift-JIS, GBK); such edits are now refused. It is identical in the code.claude.com changelog page and in the CHANGELOG.md on GitHub, and the page says it is generated from that file; only the docs page carries the version date October 9, 2026. Two earlier entries are also encoding fixes: 2.1.214 (July 18, 2026) stopped > and >> under PowerShell 5.1 from writing UTF-16LE files that other tools could not read as UTF-8, and 2.1.267 (September 9, 2026) made an artifact publish name the line and column when the file is not valid UTF-8 or contains U+FFFD.

Three dated entries from the official pages

2026-07-18

Claude Code 2.1.214: fixes > and >> on Windows PowerShell 5.1 writing UTF-16LE files other tools could not read as UTF-8, and Python scripts crashing with a UnicodeDecodeError when reading non-UTF-8 standard input. The tools reference says these Windows encoding behaviors require v2.1.214 or later.

2026-09-09

Claude Code 2.1.267: publishing an artifact from a file that is not valid UTF-8 or contains the replacement character U+FFFD now reports the line and column to fix. The error reference adds that before v2.1.267 Claude Code uploaded such a file without checking it and the server refused the publish.

2026-10-09

Claude Code 2.1.296: Edit and NotebookEdit stop replacing non-ASCII characters in files that are not valid UTF-8 (Windows-1252, Shift-JIS, GBK) and refuse those edits instead.

Confirmed vs not documented

Confirmed (verbatim in the official pages)

All of this is worded exactly this way on the official pages this article consulted on 2026-10-13: the 2.1.296 changelog sentence and its date October 9, 2026; the tools reference stating Claude can't use NotebookEdit on a file that isn't valid UTF-8. The same goes for Edit, unless the file starts with a little-endian UTF-16 byte-order mark. — the byte-order-mark exception is written for Edit only; that a refusal leaves the file untouched, and that the reason is saving the whole file back as UTF-8; the error reference message text and its two options (let Claude change the file with a shell command that reads and writes it in its own encoding, or convert to UTF-8 and edit again); that before v2.1.296 undecodable bytes were saved as U+FFFD; and that Write can still replace such a file but then saves it as UTF-8, so the original encoding is lost. On the generic-tools side: file(1) for -i and --mime-encoding, iconv(1) for -f and --from-code, -t and --to-code, -l, -c, //TRANSLIT and //IGNORE, and the GNU libiconv encoding list, which includes SHIFT_JIS, GBK and the CP1252 family.

Unverified and not documented

Three things are not described on the eight Claude Code documentation pages this article consulted on 2026-10-13 — settings, troubleshooting, common-workflows, checkpointing, terminal-config, overview, errors and tools reference — so do not plan around them. First, none of them lets you choose a file encoding: only the errors and tools reference pages discuss how files are decoded, and the other six list no encoding setting. Second, no setting or option on those pages makes Edit write a file back as GBK. Third, they offer no tool that restores text already turned into U+FFFD: in the artifact-publish section the error reference says only to save the file again as UTF-8 and replace each U+FFFD with the character an earlier edit, paste, or conversion lost. file(1) also states that some of its encoding logic is hard-coded in encoding.c, so its charset guess is a hint rather than proof.

Two official routes, two kinds of garbling

Keep the encoding vs convert to UTF-8

The error reference gives two routes: to keep the file in its current encoding, let Claude make the change with a shell command that reads and writes the file in that encoding; to keep editing with the Edit tool, convert it to UTF-8, or fix the invalid bytes in a file that is meant to be UTF-8, then ask Claude to make the edit again. Only the second restores Edit and NotebookEdit. For the first the error reference names the method but no command, and the generic way is a form like iconv -f GBK -t UTF-8.

A corrupted file vs a corrupted display

The troubleshooting page attributes boxes, smears and wrong glyphs in the VS Code, Cursor or Devin Desktop integrated terminal to the terminal's GPU renderer, and tells you to run /terminal-setup to set terminal.integrated.gpuAcceleration to off, or change it in the editor settings and reload the window; the bytes are untouched there. A real encoding problem shows File is not valid UTF-8 and, since 2.1.296, writes nothing. If the text already holds U+FFFD characters, that is the character versions before 2.1.296 wrote.

Work through it in this order

① Confirm the encoding with generic commands. file(1) documents -i (mime type strings; its example reads text/plain; charset=us-ascii) and --mime-encoding for that element alone, and iconv -l lists the encoding names your system knows; these are Unix tools, not Claude Code options. ② Back up, then convert. Copy the original first, then run iconv naming both sides: the manual synopsis is iconv [ options ] [ -f from-encoding ] [ -t to-encoding ] and its example is iconv -f ISO-8859-15 -t UTF-8 < input.txt > output.txt. The manual also states that unconvertible characters stop iconv unless you pass -c, that //TRANSLIT approximates them and prints a question mark when it cannot, and that //IGNORE discards them and reports an error after conversion; each of those loses characters, so inspect the result and keep the original. ③ Then let Claude Code edit. Update Claude Code to 2.1.296 or later (for older versions the docs say only: update Claude Code). If the file must stay in its own encoding, follow the official message and have Claude use a shell command that reads and writes that encoding; once the file is UTF-8, Edit works again, while a full replacement with Write would save it as UTF-8 and lose the original encoding.

On QCode

The encoding check happens inside Claude Code on your machine, so it does not depend on which endpoint you use. Two variables connect Claude Code to QCode: ANTHROPIC_BASE_URL set to https://api.qcode.cc/api and ANTHROPIC_AUTH_TOKEN set to the cr_ key from the dashboard; the ANTHROPIC_BASE_URL setup guide on qcode.cc adds that the value takes no trailing slash and that Claude models are served only over the Anthropic endpoint. As of 2026-10-13, claude-sonnet-5-5, claude-haiku-4-5-20251001 and claude-opus-5-5 are available on QCode. Billed per token; per-model rates are listed on /models.

Frequently asked questions

Why did Claude Code turn my GBK file into garbage, and why does it refuse the edit now?

Because Edit and NotebookEdit save the whole file back as UTF-8. The tools reference states the reason for the refusal: The tools refuse because they save the whole file back as UTF-8, which would replace every byte they can't decode with the replacement character U+FFFD. Before 2.1.296 that replacement is exactly what happened, so one edit filled a GBK or Shift-JIS file with replacement characters. Since 2.1.296 those edits are refused: the changelog says Fixed Edit and NotebookEdit replacing every non-ASCII character in files that are not valid UTF-8 (Windows-1252, Shift-JIS, GBK); such edits are now refused, and the error reference adds Nothing was written, so the file is as it was. How the characters look on screen is up to your editor; the character the docs name is U+FFFD.

How do I confirm what encoding a file actually uses?

Use the generic file command. The file(1) manual says -i causes the file command to output mime type strings rather than the more traditional human readable ones, its example being text/plain; charset=us-ascii, and that --mime-type and --mime-encoding print only the specified element. Treat the answer as a hint: file classifies text by byte ranges and sequences, and the manual notes some encoding logic is hard-coded in encoding.c, so confirm by converting with iconv and reading the text back. The six Claude Code documentation pages this article consulted on 2026-10-13 (settings, troubleshooting, common-workflows, checkpointing, terminal-config and overview) mention no command that prints or sets a file's encoding.

How do I convert to UTF-8, and do I need a backup first?

Back up first, convert second, compare third. The iconv(1) synopsis is iconv [ options ] [ -f from-encoding ] [ -t to-encoding ]: -f names the encoding of the input characters and -t the encoding of the output, and the manual's own example is iconv -f ISO-8859-15 -t UTF-8 < input.txt > output.txt, so a GBK file becomes -f GBK. Remember what the manual says about failures: unconvertible characters terminate the run unless you pass -c, //TRANSLIT approximates them and prints a question mark when it cannot, and //IGNORE discards them with an error after conversion. All of them lose characters, so keep the copy and check the Chinese or Japanese passages. These are standard Unix tool usages, not Claude Code parameters.

Is it the same for Japanese Shift-JIS and Western Windows-1252?

Same rule, same set. The 2.1.296 sentence names Windows-1252, Shift-JIS and GBK together; the error reference names the same three, and the tools reference gives Windows-1252 and Shift-JIS as examples. The check is whether the file's bytes decode as UTF-8 as a whole, so a file that should be UTF-8 triggers the same message when it holds even one invalid byte sequence. For conversion, use the names from the GNU libiconv encoding list, which includes SHIFT_JIS, CP932, GBK, CP936, GB18030, BIG5 and the CP1250 to CP1257 family, with UTF-8 as the target.

How do I connect Claude Code through QCode, and where are the rates?

Two variables. QCode's Claude Code tutorial gives export ANTHROPIC_BASE_URL = https://api.qcode.cc/api and export ANTHROPIC_AUTH_TOKEN = cr_ followed by your key, and the endpoint table in QCode's documentation gives Claude Code the same value https://api.qcode.cc/api; the ANTHROPIC_BASE_URL setup guide on qcode.cc adds that the base URL takes no trailing slash and that Claude models go only to the Anthropic endpoint. As of 2026-10-13 claude-sonnet-5-5, claude-haiku-4-5-20251001 and claude-opus-5-5 are available on QCode. Billed per token; per-model rates are listed on /models.

How do I pay and get started from China?

Alipay and WeChat Pay both work. QCode's payment-methods page lists Alipay, WeChat Pay, Credit / Debit Card (Visa / Mastercard / AMEX), Apple Pay / Google Pay and Cryptocurrency (many coins and networks, with manual reconciliation of the on-chain transfer) on the top-up page; billing is prepaid — you top up, then buy a plan that draws down the balance. The same page states the limits it prints: CNY top-ups start at ¥100 and USD top-ups run from $1 to $2,000. After registering, create a cr_ key in the dashboard and point Claude Code at it.

Sources

The Claude Code changelog (the code.claude.com changelog page and the CHANGELOG.md on GitHub) and the official documentation pages Error reference, Tools reference, Troubleshooting, Settings, Terminal configuration, Overview, Common workflows and Checkpointing, all consulted on 2026-10-13; for the generic tools, the file(1) and iconv(1) manual pages on man7.org and the GNU libiconv documentation, also from 2026-10-13; for QCode, the docs.qcode.cc pages on endpoints and API paths, the Claude Code tutorial and payment methods, plus the on-site guides on using Claude Code in China, one-click install and ANTHROPIC_BASE_URL setup, all consulted on 2026-10-13.

One cr_ key, Claude Code connected

Set ANTHROPIC_BASE_URL to https://api.qcode.cc/api and ANTHROPIC_AUTH_TOKEN as QCode's docs describe, run claude-sonnet-5-5 and other Claude models; billed per token, per-model rates listed on /models.

Related reading

The quotations and steps on this page were checked on 2026-10-13 against the Claude Code changelog and documentation, the file(1) and iconv(1) manual pages, the GNU libiconv documentation and the QCode docs; official pages change without notice, so go by the official pages. file and iconv are generic Unix tools: this page shows their documented usage, not Claude Code options. Model availability is whatever /models shows.

Try first, then decide

Not sure which tier? Start with Starter ($8.57/mo) and upgrade when you're happy — the unused value of the old plan goes back to your balance.