Directory replacement safety — never move your own cwd
Before mv or rm -rf on any directory, run pwd and verify it does not match the target path. The Bash tool's cwd persists across all calls in a session — moving your own cwd breaks every subsequent command with "path does not exist."
Protocol for replacing the working directory (e.g. recloning ~/.hermes/):
- Do NOT use the Bash tool for this operation at all
- Give the user all commands as
! <cmd>blocks to run in their terminal - The session cwd cannot recover once its directory is gone — hand off immediately
Broken cwd recovery: If Bash commands start failing with "path does not exist" after a directory move, the shell cwd is gone. Stop retrying. Instruct the user to run remaining steps via ! <cmd> in the prompt. Do not attempt further Bash tool calls.
Destructive-path guard & `cc-safety-net` (`standard`) idioms
Canonical rule: ~/.codex/AGENTS.md § "Destructive-path guard". Never aim rm -r, rsync --delete*/--del, find -delete, or mv onto an unvalidated computed path:
set -u, prove[ -n "$D" ] && [ "$D" != / ] || { echo "unsafe dest: '$D'" >&2; exit 1; }, use${D:?unset}, and validate tool outputs (such asxcrun simctl get_app_container ...) for non-empty, non-root, expected prefix before copying or deleting.- Self-check commands via
~/.claude/hooks/lib/destructive_path_guard.py --check '<cmd>'. cc-safety-net(standardlevel) operational idioms:rm -ron variable targets (rm -rf "$D") is denied (rm.recursive-force-dynamic-target) — pass literal paths.rsync --deleteis allowed only into explicit paths inside cwd,/tmp,/var/tmp,$TMPDIR, or remoteuser@host:/path(rsync.delete) — drop--deleteand remove stale files explicitly when syncing elsewhere in$HOME.prog - <<'PY'heredocs are denied (analysis.unsupported-heredoc) — writeSTEP_PY="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh tmp)/step.py"viacat > "$STEP_PY" <<'PY'then runpython3 "$STEP_PY"(cat,tee,git apply,git commit,gh pr create,gh issue createheredocs stay allowed).- Never run
pkill/killallwith multiple patterns,<6-char patterns, or-fwithout-u— usepgrep -f -- '<6+ char anchored pattern>'thenkill <PID>.