Bash tool hook rewrites \!= to \\!= in command text, breaking inline Python comparisons
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
- In a Claude Code session, run via the Bash tool:
``bash``
python3 -c "x = 1; print(x \!= 2)"
- The hook rewrites it to:
``bash``
python3 -c "x = 1; print(x \\!= 2)"
- Python raises
SyntaxError: invalid syntaxat 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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗