[BUG] exclamation mark corrupted in shell calls
Resolved 💬 2 comments Opened Jun 8, 2026 by lyphyser Closed Jun 12, 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?
When using the shell tools, "!" characters are replaced with "\\!", which obviously completely breaks actual shell usage.
This already been reported, but closed without fixing it. I'm pretty sure Claude Code can fix this bug autonomously and correctly, so not sure what you are waiting for to fix it. Please fix ASAP.
Claude says:
In the Claude Code Bash tool, every ! character in a command is backslash-escaped to \! before the command
reaches bash. This is not limited to the leading negation operator — it affects ! in any position. Depending on
context the escaping either breaks the command (reserved word, indirect expansion) or silently corrupts output
(literal ! inside quotes). It only survives where shell unescaping happens to restore it (unquoted arguments, [
]/test/find predicates).
What Should Happen?
It should obviously be passed through without mucking with it.
Error Messages/Logs
Steps to Reproduce
Claude says (after testing it itself):
Run each of the following through the Claude Code Bash tool (a non-interactive bash invocation) and compare the actual output to the expected:
1. Negation reserved word (leading):
! false; echo "exit=$?"
- Expected: exit=0
- Actual: /bin/bash: line 1: !: command not found then exit=127
2. Negation in other positions:
true && ! false; echo "exit=$?"
echo hi; ! false; echo "exit=$?"
if ! false; then echo ok; fi
- Expected: negation evaluates normally (exit=0, prints ok)
- Actual: each prints !: command not found, exit 127
3. Indirect parameter expansion:
v=PATH; echo "${!v}"
- Expected: the value of $PATH
- Actual: bash: ${\!v}: bad substitution
4. Literal ! inside quotes (output corruption):
echo "hello world!"
echo 'single: hi!'
- Expected: hello world! and single: hi!
- Actual: hello world\! and single: hi\! (stray backslash)
5. Confirm the root cause — inspect the bytes bash actually receives:
printf '%s' "x!y" | cat -A
- Expected: x!y
- Actual: x\!y (every ! has been rewritten to \! before execution)
6. Confirm history expansion is already off (so the escaping is unnecessary):
shopt -po histexpand
- Output: set +o histexpand
Contrast — cases that work (the shell strips the backslash during normal unescaping), showing the bug is the
escaping itself, not the ! semantics:
echo unquoted_abc!def # prints abc!def correctly
find . -maxdepth 1 ! -name . # works
[ ! -e /nonexistent ] && echo ok # works
[ a != b ] && echo ok # works
Claude Model
None
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
Terminal.app (macOS)
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗