[BUG] Exclamation mark is escaped

Status Closed — not planned
Maintainer reply None cached
Activity 10 comments · opened Jul 3, 2025 · closed Jan 26, 2026

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 1.0.41 (Claude Code)
  • Operating System: Debian 13
  • Terminal: foot

Bug Description

I often observe claude executing a benign command with exclamation mark somewhere in the middle only to raise Error: ERROR: syntax error at or near "\"

Steps to Reproduce

  1. Work with SQL for some time
  2. Observe the error

Expected Behavior

Command is executed as-shown.

Actual Behavior

Error: ERROR:  syntax error at or near "\"
LINE 1: ...1 END) as no_size_data FROM document WHERE status \!= 'delet...

Additional Context

Command shown after Bash(... had no backslash before the exclamation mark.

View original on GitHub ↗

10 Comments

AnhQuanTrl · 1 year ago

Same issue here as well. The exclamation mark escaping break every CLI that use this character. I has this problem when Claude execute HTTPie to a Graphql Endpoint:

> http --verbose --ignore-stdin POST http://localhost:4000/graphql \
  Content-Type:application/json \
  query='mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { user { id email } } }' \
  variables:='{
    "input": {
      "email": "john.doe@example.com",
      "name": "John Doe"
    }
  }'

The ! after CreateUserInput will be escaped as \\! which break the graphql syntax :( Tested on MacOS with kitty term.

I don't think this issue is related to any terminal environment.

dpehrson · 12 months ago

Can confirm I just ran into this when instructing a Claude Code sub-agent to execute the following command that relies on jq for filtering GItHub CLI/API responses:

gh api "repos/{repository-owner}/{repository-name}/contents/.github/ISSUE_TEMPLATE" --jq '[.[] | select(.type == "file" and (.name | test("\\.ya?ml$")) and .name != "config.yml") | {name, download_url}]'

This results in the following error upon attempting execution:

Error: failed to parse jq expression (line 1, column 42)
         [.[] | select(.type == "file" and (.name \!= "config.yml" and .name | test("\\.ya?ml$"))) | {name, download_url}]
                                                  ^  unexpected token "\\"

I was able to work around this by changing to use .name == "config.yml" | not but I can imagine many other commands such as the ones above do not have that kind of flexibility.

bukzor · 10 months ago

I dare you to count the number of failed Bash commands due to this bug, and sum up all the tokens wasted.

bukzor · 10 months ago

Workaround: tell Claude to use a "$(cat <<EOF)" heredoc:

> use Bash() to execute: seq 3 | jq 'select(. != 2)'
but you'll need a "$(cat <<EOF)" heredoc to avoid an escaping issue with the ! character

● I'll execute that command using a heredoc to avoid the ! escaping issue:

● Bash(seq 3 | jq "select(. != 2)")
  ⎿  1
     3

Note, apparently claude-code pretty prints heredocs as quoted strings:

> Please run this tool invocation exactly as written, for contrast: Bash(seq 3 | jq "select(. != 2)")

● Bash(seq 3 | jq "select(. != 2)")
  ⎿  Error: jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
     select(. \!= 2)
     jq: error: try .["field"] instead of .field for unusually named fields at <top-level>, line 1:
     select(. \!= 2)
     jq: 2 compile errors

The journal reveals the successful tool call is actually:

      {
        "type": "tool_use",
        "name": "Bash",
        "input": {
          "command": "seq 3 | jq \"$(cat <<'EOF'\nselect(. != 2)\nEOF\n)\"",
          "description": "Run seq 3 through jq filter excluding 2"
        }
      }
github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

ChadNedzlek · 8 months ago

Yes, this is still, embarrassingly, still happening.

github-actions[bot] · 7 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

marcindulak · 7 months ago

This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.

bman654 · 7 months ago

this bug is absurd. And closed?

github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.