Write tool creates files with CRLF line endings on WSL2/Linux, breaking shell script execution

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Dec 2, 2025 · closed Dec 3, 2025

Environment:

  • Claude Code version: Current (as of 2025-01-02)
  • OS: Linux (WSL2: Linux 6.6.87.2-microsoft-standard-WSL2)
  • Platform: linux (from environment context)

Description:

The Write tool creates files with Windows-style CRLF (\r\n) line endings even when running on Linux/WSL2 systems. This causes bash scripts to fail immediately after creation with errors like:

/bin/bash: line 1: ./script.sh: cannot execute: required file not found

Reproduction Steps:

  1. Use Write tool to create a bash script on WSL2/Linux:
<invoke name="Write">
<parameter name="file_path">/path/to/test.sh</parameter>
<parameter name="content">#!/bin/bash
echo "Hello World"
</parameter>
</invoke>
  1. Verify line endings:
file test.sh
# Shows: ASCII text, with CRLF line terminators

od -c test.sh | head -2
# Shows \r\n instead of \n
  1. Attempt to execute:
chmod +x test.sh
./test.sh
# Error: required file not found (due to \r in shebang)

Expected Behavior:

On Unix-like systems (Linux, macOS, WSL), the Write tool should:

  • Create files with LF (\n) line endings by default
  • Respect the platform's native line ending convention
  • Alternatively, provide a parameter to specify line ending style

Current Workaround:

After every Write operation creating shell scripts:

dos2unix script.sh
# or: sed -i 's/\r$//' script.sh

Impact:

  • Immediate execution failures: Scripts cannot be tested immediately after creation without manual post-processing
  • Workflow friction: Requires extra steps after file creation
  • Easy to forget: The error only appears when attempting to execute the script
  • Partial mitigation via .gitattributes: Using .gitattributes normalizes line endings at commit time, but doesn't help the window between file creation and commit

Suggested Solution:

The Write tool should detect the platform and use appropriate line endings:

  • Unix-like systems → LF (\n)
  • Windows (non-WSL) → CRLF (\r\n)
  • Optionally: Allow explicit line ending specification via parameter

Additional Context:

This issue affects any text file creation but is most critical for shell scripts where CRLF breaks the shebang (#!/bin/bash\r is not recognized). Similar issues may affect other interpreted scripts (Python, Ruby, etc.) though they're often more tolerant of CRLF.

View original on GitHub ↗

4 Comments

github-actions[bot] · 10 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2805
  2. https://github.com/anthropics/claude-code/issues/6819
  3. https://github.com/anthropics/claude-code/issues/38

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

baloo0402 · 10 months ago

closing as dup of #2805

baloo0402 · 10 months ago

dup of #2805

github-actions[bot] · 10 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.