Skip to content
Back to skills

Cwd Safety

BSecurity

Use BEFORE `mv`/`rm -rf` on any directory. Verifies pwd does not match target; session cwd cannot recover once its directory is gone.

  • 6 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 26, 2026
ai-agentspythongoshellbashgit

Works with

  • terminal

Security analysis

B85/100
  • highPerforms destructive filesystem operations

Pro shows the line behind each finding and how to fix it

Scanned November 26, 2026

npx -y skills add jleechanorg/jleechan-skills --skill cwd-safety --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cwd Safety?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cwd Safety
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/jleechanorg-cwd-safety/badge)](https://www.skillsdirectory.com/skills/jleechanorg-cwd-safety)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cwd-safety
description: "Use BEFORE `mv`/`rm -rf` on any directory. Verifies pwd does not match target; session cwd cannot recover once its directory is gone."
---

# 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/`):**
1. Do NOT use the Bash tool for this operation at all
2. Give the user all commands as `! <cmd>` blocks to run in their terminal
3. 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 as `xcrun 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` (`standard` level) operational idioms**:
  - `rm -r` on variable targets (`rm -rf "$D"`) is denied (`rm.recursive-force-dynamic-target`) — pass literal paths.
  - `rsync --delete` is allowed only into explicit paths inside cwd, `/tmp`, `/var/tmp`, `$TMPDIR`, or remote `user@host:/path` (`rsync.delete`) — drop `--delete` and remove stale files explicitly when syncing elsewhere in `$HOME`.
  - `prog - <<'PY'` heredocs are denied (`analysis.unsupported-heredoc`) — write `STEP_PY="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh tmp)/step.py"` via `cat > "$STEP_PY" <<'PY'` then run `python3 "$STEP_PY"` (`cat`, `tee`, `git apply`, `git commit`, `gh pr create`, `gh issue create` heredocs stay allowed).
  - Never run `pkill`/`killall` with multiple patterns, `<6`-char patterns, or `-f` without `-u` — use `pgrep -f -- '<6+ char anchored pattern>'` then `kill <PID>`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.