[BUG] Edit tool corrupts literal escape sequences
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?
The edit tool appears to corrupt escape sequences in the strings, turning for instance \^@ into zero character, resulting in the match failing.
The model doesn't seem to know this, and after being surprised by the failure it tries to work it around by replacing with Python or similar, which is not acceptable behavior, since the Python needs extra permissions and is not introspectable in the UI or otherwise.
The solution is that obviously the edit tool should not do any backslash sequence processing by default, unless a dedicated option is set to enable this feature, which would be enabled by model only in rare cases where editing involves bytes/characters that are not representable directly in the tool argument (and BTW, this should be byte-oriented, not character-oriented, since files don't have to be UTF-8).
What Should Happen?
The string is treated as-is, without interpreting escape sequences, unless an option to interpret them is set.
Error Messages/Logs
Steps to Reproduce
Create a file with \^@ (literally) and ask the model to edit it to \^A
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.168 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗