[BUG] Claude Code corrupted ANSI files by converting them to UTF-8

Resolved 💬 3 comments Opened Apr 19, 2026 by enricogaggero Closed May 26, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] 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_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗