[BUG] Write tool produces CRLF line endings in WSL, breaking shell scripts
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?
Environment
- OS: WSL (Windows Subsystem for Linux)
- Shell: bash
Issue
The Write tool creates files with Windows-style CRLF line endings instead of Unix LF endings. This causes shell scripts to fail with a confusing error:
bash: ./script.sh: cannot execute: required file not found
Steps to Reproduce
- Use Claude Code in WSL
- Ask Claude to create a shell script using the Write tool
- chmod +x the script
- Try to execute it
Expected Behavior
Files should have LF line endings in a Linux environment.
Actual Behavior
Files have CRLF endings (visible as ^M when running cat -A script.sh).
Workaround
Use Bash with printf instead of Write tool for shell scripts, or manually fix with:
sed -i 's/\r$//' script.sh
Impact
Silent failure with misleading error message. Took a while to debug since "required file not found" doesn't indicate a line ending issue.
What Should Happen?
It should not
Error Messages/Logs
Steps to Reproduce
Have CC try to create a .sh script, then try to run it:
~/ (❗main❗ branch)$ ./prep_stack.sh ./dec11_substack.md
bash: ./prep_stack.sh: cannot execute: required file not found
~/ (❗main❗ branch)$ echo $SHELL
/bin/bash
~/ (❗main❗ branch)$ cat -A prep_stack.sh | head -1
#!/bin/bash^M$
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.65 (Claude Code
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗