`!` injection: `&&` chain drops commands after sudo (works fine in fresh shell)
Repro
In a Claude Code session, with any sudo cache state (cached or fresh), paste:
! sudo touch /tmp/repro_a && echo "step2 ran" && touch /tmp/repro_b && echo "step3 ran"
Actual
No output. Only /tmp/repro_a is created. step2 ran / step3 ran echoes never appear; /tmp/repro_b is never created. Chain exits 1.
❯ ! sudo touch /tmp/repro_a && echo "step2 ran" && touch /tmp/repro_b && echo "step3 ran"
❯ ! ls /tmp/repro_* 2>&1; echo "---exit: $?---"
/tmp/repro_a
---exit: 1---
Expected
Both files exist, both echoes printed.
Same chain in a fresh shell works correctly
Exact same command in a fresh konsole window (no Claude Code involvement, same user/zsh/sudo config):
❯ sudo touch /tmp/chain_a && echo "step2 ran" && touch /tmp/chain_b && echo "step3 ran"; echo "exit: $?"
[sudo] password for elienop:
step2 ran
step3 ran
exit: 0
So the bug is specifically in how ! shell injection handles && chains that contain a sudo command — not the shell or sudo config.
Sudo cache state doesn't matter
Bug fires whether sudo prompts for a password (cache cleared with sudo -k) or runs silently from a warm cache. So it's not about password input being intercepted.
Environment
- Claude Code: 2.1.143
- OS: CachyOS Linux (Arch derivative), kernel 7.0.8-1-cachyos
- Shell: zsh 5.9 with powerlevel10k
- sudo: 1.9.17p2
Impact
Multi-step workflows involving sudo silently fail. Hit it ~4 times today during routine operations (file copy + service restart, system upgrades, cleanup chains). The silence is the worst part — easy to think the command succeeded.
Workaround
Wrap everything inside one sudo invocation so the chain doesn't cross the sudo boundary:
! sudo bash -c 'cmd1 && cmd2 && cmd3'
Or split into separate ! calls (each independent sudo invocation).
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗