Do not trust exit 0: prove the file changed
A helper overwrote the script and it still exited 0. This checks the real result and gives each agent its own folder.
The fix: check the result, not the exit code
Exit 0 says the command ended. It does not say the job was done. After the script runs, ask git if the file changed. git diff --quiet exits 0 when there is no difference and 1 when there is. Comparing with HEAD also catches changes that are already staged.
./fix.sh
git diff --quiet HEAD -- src/cart.js \n && { echo "src/cart.js did not change"; exit 1; }Give every helper its own folder
In the episode, helpers shared one folder and overwrote each other's script. A git worktree is a separate checkout on its own branch. Use a different name in each terminal. The repo needs at least one commit. To isolate subagents inside one session, say "use worktrees for your agents", or add isolation: worktree to the subagent's frontmatter.
# terminal 1
claude --worktree fix-cart
# terminal 2
claude --worktree fix-taxCheck it worked
Try the check on a file nobody touched. The command should print 0, which means no change, so your guard would stop the script. Then change the file and run it again: it prints 1. To see the folders, list the worktrees.
git diff --quiet HEAD -- README.md; echo $?
git worktree listPro tip: a pipe can hide a failed command
A pipeline returns the status of its last command, so tail's 0 hides npm's 1. With pipefail it returns the rightmost non-zero status. In a script, put set -euo pipefail at the top.
npm test 2>&1 | tail -1; echo $?
# 0 wrong: this is tail's status
set -o pipefail
npm test 2>&1 | tail -1; echo $?
# 1 honestPro tip: CI does not use pipefail by default
In GitHub Actions a step with no shell set runs bash -e {0}, which has no pipefail. Naming bash runs bash --noprofile --norc -eo pipefail {0}. Set it once for the whole workflow.
defaults:
run:
shell: bash
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm test | tail -20Common mistake
Trusting set -e to catch everything. Bash does not exit when the failing command is part of an if test, part of a && or || list (except the last command), follows while or until, or is not the last command of a pipeline and pipefail is off. In those places, check the status yourself.
Official docs
- code.claude.com/docs/en/worktrees
- code.claude.com/docs/en/common-workflows
- code.claude.com/docs/en/cli-reference
- git-scm.com/docs/git-diff
- www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
- www.gnu.org/software/bash/manual/html_node/Pipelines.html
- docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
One fix of twenty: the whole Claude Code survival kit.
Follow @whyshouldaicareA new disaster and its fix every day. Comment the word under a reel to get its guide.