[BUG] bash negation fails in bash mode with grep (`if ! grep` does not parse correctly)

Resolved 💬 4 comments Opened Mar 8, 2026 by JasonGross Closed Apr 8, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

If I type ! and then for i in *; do if ! grep -q 'Error' $i; then echo "$i"; fi; done, I get a bunch of /bin/bash: line 1: !: command not found. If I run this in bash, it works fine. If I replace grep -q 'Error' $i with true, it works fine. If I get rid of !, it works fine. Seems like it is probably some weird parsing issue mixup with ! for bash mode.

What Should Happen?

The command should run in the same way it does on command line.

Error Messages/Logs

/bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found         
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found
     /bin/bash: line 1: !: command not found

Steps to Reproduce

  1. claude
  2. type !
  3. type for i in *; do if ! grep -q 'Error' $i; then echo "$i"; fi; done
  4. press Enter

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.71 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗

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