[BUG] Regression: Bash tool again escapes "!" → "\!" (regression of #32864, fixed in 2.1.87)

Resolved 💬 2 comments Opened Jun 13, 2026 by CroneKorkN Closed Jun 13, 2026

Preflight Checklist

  • [x] I searched existing issues. The closest matches (#32864, #29210, #23740) are all closed and locked, so I cannot reopen or comment — hence this new report.
  • [x] This is a single bug report.
  • [x] I am using the latest version of Claude Code (2.1.177).

What's Wrong?

The Bash tool prepends a backslash to every literal ! in a command string before execution — even inside single/double quotes and in a non-interactive shell (where history expansion is already off). The backslash survives into the executed command and corrupts arguments to downstream tools.

This is the exact bug from #32864, which was reported fixed in 2.1.87 (per its comments). It has regressed on the current release, 2.1.177.

What Should Happen?

A literal ! should reach the shell/executable unchanged.
echo "a != b" should print a != b; python3 -c "print(1 != 2)" should print True.

Error Messages/Logs

$ echo "a != b"
a \!= b                       # expected: a != b

$ python3 -c "print(1 != 2)"
<string>:1: SyntaxWarning: "\!" is an invalid escape sequence
# the interpreter receives:  print(1 \!= 2)

Steps to Reproduce

  1. In Claude Code's Bash tool, run: echo "a != b" → outputs a \!= b.
  2. Run: python3 -c "print(1 != 2)" → emits the SyntaxWarning above and the interpreter receives print(1 \!= 2).
  3. The backslash is inserted regardless of quoting. bash -c '...' and quoted heredocs do not avoid it (the whole command string is escaped before any shell parses it). Only the content-level workaround $'\x21' produces a literal !.

Claude Model

Opus

Is this a regression?

Yes - it worked before

Last Working Version

Fixed in 2.1.87 and reported working through ~2.1.92 (see #32864 comments). The exact version where it regressed is unknown.

Claude Code Version

2.1.177

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (zsh)

Additional Information

Impact: corrupts any inline command containing ! — Python !=, jq filters, Jira JQL (status != Done → server rejects with 400), branch names, etc.

Related issues (all closed/locked, hence this new report):

  • #32864 — same bug, closed Completed (fixed 2.1.87), locked
  • #29210 — stale-closed (auto), locked
  • #23740 — closed as duplicate, locked
  • #7387 — open, related ("crazy escaping")

_(ai-assisted bug report)_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗