/tools-plugin:zsh-gotchasfrom tools-plugin
Diagnoses five zsh-specific expansions that silently rewrite commands: $VAR:word modifier, leading = command lookup, missing word splitting, path/PATH coupling, and bare local. Use when a zsh command returns wrong results, empty output, or false 'command not found'.
Ships in tools-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Five zsh behaviours. The first four have no bash equivalent; the fifth is
shared with bash for typeset, declare and export, and is zsh's own for
local. Each one fires on ordinary commands, including the one-liners an
agent runs through the Bash tool — not just on .zsh files — so a snippet
lifted from a bash-tested doc breaks only here.
What makes them expensive is that three of the five fail silently or misattribute: the command runs, exits, and reports something that looks like a real answer about the world. The fifth is loud, and what it prints is the environment. The first four were each diagnosed the wrong way first.
| Symptom | Mechanism | Section |
|---|---|---|
A URL/path with $var: hits the wrong endpoint; fast empty 404 | $VAR:x is a history modifier | 1 |
A later command in a ; chain produced no output | a word starting with = is a command lookup | 2 |
$2 empty after set -- $spec; tool prints its usage text | zsh does not word-split | 3 |
command not found for a tool that is installed | path is tied to PATH | 4 |
A function prints hundreds of NAME=value lines before its real output | local $names with names empty is a bare local | 5 |
Out of scope: zsh-vs-POSIX pattern expansion and extended glob. Those bite when
writing .zsh / zshrc files, not on every command, and are not covered here.
| Use this skill when... | Use shell-expert instead when... |
|---|---|
| A zsh command ran and returned a result that does not match what you typed | Writing a shell script, function, or pipeline from scratch |
| An unexpected 404, an empty positional, or a missing chunk of output from a chain | Choosing portable constructs across bash / zsh / POSIX |
command not found names a tool you know is installed | Structuring error handling, set flags, or CLI argument parsing |
| A bash-tested snippet behaves differently once run through the Bash tool | The question is shell style rather than a wrong runtime result |
The split is runtime versus authoring: this skill covers five expansions that make a correct-looking zsh command do something else, three of them silently.
$VAR:word Is a Modifier, Not a Colon After a VariableZsh applies history-style modifiers directly to a bare parameter expansion:
$f:h (dirname), $f:t (basename), $f:r, $f:e, $f:s/a/b/, $f:g…. So a
URL that puts a variable straight before a colon is not the URL you wrote:
# Wrong — `:g` is read as the start of a global-substitution modifier
curl "https://…/v1beta/models/$MODEL:generateContent"
Observed 2026-09-05 (robocar-unified, probing a replacement Gemini model): three
requests came back HTTP 404 in 60 ms with an empty body, and were nearly
reported as "the new model does not support generateContent". The empty body and
the sub-100 ms turnaround were the tell — a real API 404 carries a JSON error and
takes a round trip. The same request with braces returned 200.
Brace the expansion. Braces end the parameter name, so the colon is literal:
curl "https://…/v1beta/models/${MODEL}:generateContent"
Double quotes do not protect you — modifiers apply inside them.
model:method REST paths, host:port, user:group,
file:line, scp/rsync host:path targets — any $var: with a letter
after the colon.unrecognized modifier); the recognised ones (g, h, t, r, e, s,
a, A, l, u, q, Q, x, c, P) fail silently by rewriting the
string.= Is a Command LookupWith EQUALS set (the zsh default), an unquoted word that begins with = is
replaced by the path of the command named after it: =ls becomes /bin/ls.
When no such command exists, the expansion is a fatal error that aborts the
rest of the command line, not just that word, and ; does not contain it:
zsh -fc 'echo a; echo ======; echo b'
# a
# zsh:1: ===== not found ← `echo b` never runs, exit 1
Observed 2026-09-15 (claude-plugins, session-end): survey.sh …; echo ======; distill-survey.sh … printed the survey, then (eval):1: ===== not found, and
the second collector silently never ran. The error names the word minus its
leading =, which reads like a missing command rather than a separator.
Quote the word (echo '======'), or use a separator that does not start with
= (echo ---). setopt noequals also works but changes the shell for
everything after it.
echo =====, print ==== x).=: --flag =value, git log =main, a jq or awk
program passed unquoted.Bash splits an unquoted $var on IFS; zsh does not, because SH_WORD_SPLIT
is off by default. The whole string stays one word, so $1 is everything and
$2 is empty:
# Wrong — $2 is empty, so gh runs without a PR number
for spec in "ForumViriumHelsinki/infrastructure 2379" "ForumViriumHelsinki/.github 127"; do
set -- $spec
gh pr view "$2" -R "$1" --json state
done
Observed 2026-09-16 (verifying three PRs after a merge): the loop printed gh's
usage text three times — "argument required when using the --repo flag" — and
verified nothing. The message names a flag, so it reads as a wrong invocation
rather than an empty variable, and the obvious next move is to rewrite the gh
call that was already correct.
Force splitting with ${=var}, or read into named variables:
for spec in "ForumViriumHelsinki/infrastructure 2379"; do read -r repo num <<< "$spec"; gh pr view "$num" -R "$repo" --json state; done
Named variables are the better habit: they survive a copy into a bash script, and they say what each field is.
set -- $line / set -- $spec over a list of space-separated records — the
natural way to unpack "repo number" or "host port" pairs.cmd $args where args holds several flags. Zsh passes them as one
argument; the tool reports an unknown option containing spaces.${(s:,:)csv} in zsh, not
IFS=, read.ssh host '…' hands the
command string to the remote user's login shell, so a bash-tested
C="apptainer exec … colmap"; $C image_undistorter … exits 127 there: the
whole string is looked up as one command name. Observed 2026-10-23 driving a
GPU box whose login shell was zsh — the same script body ran fine once fed to
bash. Run multi-line remote work as ssh host bash -s <<'EOF' … EOF (or
ssh host bash script.sh), and hold a command in a shell function
(colmap() { apptainer exec … colmap "$@"; }), never a string.Both halves of that session's evidence were silent. The gh loop printed usage
text, and a malformed taskwarrior query minutes later (task export status:pending — taskwarrior wants the filter before the command) returned
three empty lists that read exactly like an empty queue. A control re-run with
the correct order returned 457 tasks. Control-test any negative that gates an
action.
path Is Not a Free Variable NameZsh ties path to PATH: path is the array view, PATH the scalar view,
and writing either rewrites the other. Assigning a string to path therefore
destroys the search path for the rest of the shell.
The usual way in is a loop variable chosen for readability:
# Wrong — `path` is special; PATH is destroyed on the FIRST iteration
while IFS=$'\t' read -r key title labels path; do
gh issue create --title "$title" --body-file "$path" ...
done < list.tsv
Observed 2026-09-02 (silverbucket-helper, filing eight issues): every iteration
printed command not found: tail, and nothing was created — gh was already
unreachable by the time the body ran.
Zsh's tied variables are a small set, and the rest are just as ordinary looking:
path, cdpath, fpath, manpath, fignore, mailpath, module_path,
prompt, psvar, status, argv. path and fpath are the two a script is
most likely to reach for by accident.
Pick a name that is not tied. Any of bodyfile, file, p, target works; the
rename is the whole fix.
while IFS=$'\t' read -r key title labels bodyfile; do gh issue create --title "$title" --body-file "$bodyfile"; done < list.tsv
typeset does not rescue you — local path inside a function still shadows the
tied parameter and still breaks command lookup for that function's body.
The failure is loud but misattributed: zsh reports the missing command, not the cause, so the obvious next move is to fix the "missing" tool. Before retrying a loop that had side effects, establish whether the side effects happened — a partially-completed run retried from the top creates duplicates.
gh issue list --state open --limit 30 --json number,createdAt
In the case above the answer was none, because PATH died on iteration one
before gh was reached. Had it died later, some issues would exist and a blind
retry would have double-filed them.
local, typeset, declare and export print parameters when they run with
no arguments. An unquoted expansion that is empty contributes no word, so a
declaration whose arguments are all expansions turns into the bare builtin:
# Wrong — with `names` unset this is a bare `local`
status_line() { local $names; set_colours; print "${green}ok${rst}"; }
Observed 2026-11-12 (dotfiles, a gh merge wrapper run through Claude Code's
! prefix): that shell had the wrapper functions but not the global array they
took their colour names from. One function printed about 92 KB of parameters,
beginning 0=<function name>, into the session transcript, and that included
every exported API token. The merge then succeeded, so nothing pointed at the
declaration.
Bash's bare local prints nothing, so a function tested under bash shows no
symptom; that part is zsh's own. typeset, declare and export list in both
shells (measured in bash 5.2 and zsh 5.9 with an exported canary variable).
Make the statement unable to run bare. Any of these:
local green red yellow # write the names out
export "$name" # one quoted name: empty is an error
typeset "${names[@]:?names is empty}" # an empty list aborts
Quoting does not rescue a list: "${names[@]}" of an empty array and "$@"
with no arguments are zero words as well.
typeset -f output, a
restored shell snapshot, a subshell after unset.export $(grep -v '^#' .env | xargs) when .env is missing or empty.declare -p $name with name unset prints every declaration.Where hooks-plugin is installed, its bare-declaration-guard.sh blocks an
Edit or Write that adds such a line to a shell file.
The first four are testable in one line against a pristine shell (zsh -f skips
rc files, so the result is the language's behaviour and not this machine's):
zsh -fc 'M=models/x; echo "$M:generateContent"; echo "${M}:generateContent"'
zsh -fc 'v="a b"; set -- $v; echo "bare: 1=[$1] 2=[$2]"; set -- ${=v}; echo "split: 1=[$1] 2=[$2]"'
If the braced or ${=…} form differs from the bare one, the expansion is the
bug — not the tool you were calling.
For the fifth, count the lines a bare declaration prints. Zsh prints a few
hundred, bash prints 0:
zsh -fc 'f() { local $nothing; }; f | wc -l'; bash -c 'f() { local $nothing; }; f | wc -l'
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub laurigates/claude-plugins --plugin tools-plugin18 skills in this plugin
/apptainerApptainer: run OCI images as rootless batch jobs with --nv GPU passthrough and digest-pinned SIFs. Use when running a CUDA tool without Docker, podman lacks GPU support, or a pull fills root./binary-analysisBinary analysis: strings, binwalk, hexdump, xxd, file, objdump. Use when identifying unknown files, extracting strings, hunting credentials, or entropy analysis./cli-smoke-recipesCLI smoke recipes: expose pure-function modules via subcommands with a bulk-smoke justfile recipe. Use when designing data-transform modules or authoring smoke tests.Other plugins' skills for the same job