Bash tool hook rewrites \!= to \\!= in command text, breaking inline Python comparisons

Resolved 💬 3 comments Opened Apr 24, 2026 by masahiroono36 Closed Apr 28, 2026

Description

The Claude Code user-prompt-submit-hook (or an equivalent pre-execution transform) rewrites \!= to \\!= inside Bash tool command text. When a command embeds Python code inline via python3 -c "..." or a heredoc (python3 - << 'PY'), the rewritten \\!= causes a Python SyntaxError.

Steps to Reproduce

  1. In a Claude Code session, run via the Bash tool:

``bash
python3 -c "x = 1; print(x \!= 2)"
``

  1. The hook rewrites it to:

``bash
python3 -c "x = 1; print(x \\!= 2)"
``

  1. Python raises SyntaxError: invalid syntax at the \\!= token.

Expected Behavior

\!= inside Bash tool command strings should not be rewritten. It is valid Python (and valid bash) syntax and has no security implications that would justify escaping.

Actual Behavior

\!= is escaped to \\!=, breaking any inline Python that uses inequality comparisons.

Workaround

Write Python code to a .py file and invoke with python3 file.py to bypass the hook transform.

Impact

Automation frameworks that generate inline Python for state manipulation (e.g. JSON ledger updates) cannot use \!= comparisons without a file-based workaround. This is especially disruptive in orchestration contexts where writing temp files adds fragility.

Environment

  • Claude Code CLI (macOS)
  • Python 3.x (any version)
  • Observed during agentic run sessions using Bash tool

View original on GitHub ↗

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