[BUG] Bash tool incorrectly escapes special characters inside single-quoted strings

Resolved 💬 3 comments Opened Dec 17, 2025 by cesarbahena Closed Dec 21, 2025

Bug Report: Bash Tool Adds Extra Backslashes to Single-Quoted Arguments

Summary

The Claude Code Bash tool incorrectly adds backslashes before special characters (like !) inside single-quoted strings, violating POSIX shell quoting rules.

Minimal Reproduction

Test Case 1: Simple Echo

echo 'hello!'

Expected output:

hello!

Actual output:

hello\!

Test Case 2: Python Argument Inspection

python3 -c "import sys; print(repr(sys.argv[1]))" 'hello!'

Expected: Python should receive string hello!

'hello!'

Actual: Python receives string hello\! (with backslash)

'hello\\!'

Test Case 3: Argument Passing

bash -c 'echo "[$1]"' _ 'test!'

Expected output:

[test!]

Actual output:

[test\!]

Comparison: Double Quotes Work Correctly

python3 -c "import sys; print(repr(sys.argv[1]))" "hello!"

Output: ✓ Correct

'hello!'

Root Cause

Single quotes in POSIX shells preserve literal values - no character inside has special meaning. The Bash tool is adding escape characters inside single-quoted strings, which violates this fundamental behavior.

The tool correctly handles double quotes but incorrectly modifies single-quoted content.

Impact

  • Commands with special characters (!, $, ` ``, etc.) in single-quoted arguments fail
  • This affects passwords, file paths, text processing, and any data containing shell metacharacters
  • Violates user expectations of standard shell behavior

View original on GitHub ↗

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