Skip to content

[BUG] Claude Code does not respect file encoding, corrupts Windows-1252 files #7134

Description

@edlyra

Environment

  • Platform (select one):
    • [ X] Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other:
  • Claude CLI version: 1.0.103 (Claude Code)
  • Operating System: Windows 11
  • Terminal: VSCode

Bug Description

Claude Code does not respect the original file encoding when editing files. It assumes UTF-8 encoding for all operations, which causes character corruption when working with files encoded in other formats like Windows-1252.

Steps to Reproduce

  1. Open a file that is encoded in Windows-1252 (common for Delphi/Pascal projects)
  2. Use Claude Code's Edit tool to modify text containing accented characters (e.g., Portuguese: configuração, não)
  3. The file becomes corrupted with characters like configuração instead of configuração

Expected Behavior

Claude Code should:

  • Detect the original file encoding
  • Preserve the same encoding when making edits
  • Or provide a way to configure the target encoding for edits

Current Workaround

Users must either:

  1. Accept corrupted characters and manually fix them
  2. Maintain separate UTF-8 clones of their repositories specifically for Claude Code usage
  3. Use pre-commit scripts to convert between encodings

Impact

This affects any codebase that uses non-UTF-8 encoding, particularly:

  • Legacy Delphi/Pascal projects (Windows-1252)
  • Projects with specific encoding requirements
  • International projects with accented characters

Technical Details

  • Claude Code's Read tool correctly displays Windows-1252 files
  • The Edit/Write tools force UTF-8 output regardless of input encoding
  • VSCode correctly shows Windows-1252 files when configured properly
  • The issue only occurs when Claude Code modifies the files

Environment

  • Claude Code version: [current version]
  • File encoding: Windows-1252 (ANSI - Latin 1)
  • IDE: Delphi XE
  • Language: Portuguese (Brazilian) with accented characters

This is a critical issue for maintaining legacy codebases that require specific encodings for compiler compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workingduplicateThis issue or pull request already existsplatform:windowsIssue specifically occurs on Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions