claude-code - 💡(How to fix) Fix [BUG] Claude Code corrupted ANSI files by converting them to UTF-8 [3 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#50717Fetched 2026-04-20 12:15:01
View on GitHub
Comments
3
Participants
4
Timeline
7
Reactions
0
Timeline (top)
labeled ×4commented ×3

Error Message

Root cause: Claude failed to check the project's encoding before using the Write tool. When fix attempts kept failing, instead of acknowledging its inability to solve the problem with the available tools, it kept proposing wrong solutions — demonstrating outright stupidity by persisting with approaches that clearly weren't working, causing progressive damage rather than stopping at the first error and asking the user to intervene manually. Expected behavior: Claude Code should detect when a project uses ANSI-encoded files and warn the user instead of silently creating UTF-8 files, or alternatively just provide the file content as text and let the user create the file manually.

Error Messages/Logs

Root Cause

Root cause: Claude failed to check the project's encoding before using the Write tool. When fix attempts kept failing, instead of acknowledging its inability to solve the problem with the available tools, it kept proposing wrong solutions — demonstrating outright stupidity by persisting with approaches that clearly weren't working, causing progressive damage rather than stopping at the first error and asking the user to intervene manually.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code created a new .pas file (Delphi project) using the Write tool, which always saves in UTF-8. The project requires ANSI (Windows-1252) encoded files.

The consequences were:

  • The created file failed to compile (errors E2010, E2029)
  • In attempting to fix the issue, Claude made things progressively worse with each attempt
  • ANSI characters 161-255 in existing files were corrupted (replaced with ?)
  • The user had to manually repair the damaged files

Root cause: Claude failed to check the project's encoding before using the Write tool. When fix attempts kept failing, instead of acknowledging its inability to solve the problem with the available tools, it kept proposing wrong solutions — demonstrating outright stupidity by persisting with approaches that clearly weren't working, causing progressive damage rather than stopping at the first error and asking the user to intervene manually.

Environment: Windows 11, Delphi IDE, project with .pas source files in ANSI/Windows-1252 encoding.

What Should Happen?

Expected behavior: Claude Code should detect when a project uses ANSI-encoded files and warn the user instead of silently creating UTF-8 files, or alternatively just provide the file content as text and let the user create the file manually.

Error Messages/Logs

Steps to Reproduce

generic

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.113

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

No response

extent analysis

TL;DR

Claude Code should be modified to detect the project's encoding and warn the user or provide file content as text to avoid creating files with incorrect encoding.

Guidance

  • Check the project settings to ensure Claude Code can detect the encoding of existing files, potentially by adding an option to specify the encoding.
  • Modify the Write tool to warn the user if the project requires ANSI-encoded files but the tool is set to save in UTF-8.
  • Consider adding an option to let the user create files manually with the correct encoding.
  • Verify that the fix works by creating a new file with the Write tool and checking its encoding.

Example

No code snippet is provided as the issue does not contain specific code details.

Notes

The solution may require changes to the Claude Code application, specifically the Write tool, to handle encoding detection and user warnings.

Recommendation

Apply a workaround by manually creating files with the correct ANSI encoding until the Claude Code application is updated to handle encoding detection and warnings. This is because the current version of Claude Code (2.1.113) does not seem to have the necessary functionality to handle encoding correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Claude Code corrupted ANSI files by converting them to UTF-8 [3 comments, 4 participants]