zsh stops a command with "no matches found" when a glob matches nothing, unlike bash
Symptom#
A cleanup such as rm -f $S/sx_*.txt, or a grep -rn x --include=*.rs, does not run at all in zsh:
zsh:1: no matches found: /tmp/rkb_nomatch_*.txt
and exits 1. The same line in bash runs and exits 0. Claude Code's Bash tool runs commands in the user's login shell, which is zsh on macOS.
Cause#
zsh's NOMATCH option is on by default: a pattern that matches no file is an error, so the command never starts. bash passes the pattern through as a literal word. An unquoted --include=*.rs is a pattern too.
Fix#
Quote a pattern that is meant for the program, not the shell (--include='*.rs'). For file cleanups, give explicit file names, or in zsh run setopt nullglob first so an empty match expands to nothing. See also zsh word splitting.
Evidence#
2026-09-29, macOS zsh: zsh -c 'rm -f /tmp/rkb_nomatch_*.txt; echo "exit $?"' printed the error above and exit 1; bash -c with the same line printed exit 0; zsh -c 'setopt nullglob; rm -f /tmp/rkb_nomatch_*.txt' exited 0. In the rkb session that day, grep -rn ... --include=*.rs failed with (eval):1: no matches found: --include=*.rs. In a dftracer-utils session, rm -f $S/sx_*.txt failed the same way and explicit file names fixed it.
Also found by searching
- rm -f /tmp/out_*.txt -> zsh:1: no matches found: /tmp/out_*.txt (exit 1)
- grep --include=*.rs works in bash but in my mac terminal the command does not run at all
- how do I make an unmatched wildcard not abort the command in zsh like bash does
- zsh NOMATCH glob error when no files match, Claude Code Bash tool on macOS uses zsh not bash
- zsh:1: no matches found: /tmp/build_*.txt
- rm -f with a wildcard fails in zsh but works in bash when there are no files
- how do I stop zsh erroring on grep --include=*.rs when nothing matches
- (eval):1: no matches found: --include=*.rs claude bash tool glob nomatch nullglob