11#! /usr/bin/env bash
2- # rm-tmp.sh — Delete files under .claude/tmp/ only.
2+ # rm-tmp.sh — Delete files or directories under .claude/tmp/ only.
33# Usage: bash <path>/rm-tmp.sh <path> [<path> ...]
44#
5- # Restricts deletion to files under the project's .claude/tmp/ directory
5+ # Restricts deletion to paths under the project's .claude/tmp/ directory
66# so that Bash(rm:*) need not be added to the permission allowlist.
7- # Rejects: paths outside .claude/tmp/, paths containing '..', and directories.
7+ # Rejects: paths outside .claude/tmp/, paths containing '..',
8+ # and the .claude/tmp/ root itself (only sub-paths may be deleted).
9+ # Directories are removed recursively.
810
911set -euo pipefail
1012
1113if [ $# -eq 0 ]; then
12- echo " Error: at least one file path is required" >&2
14+ echo " Error: at least one path is required" >&2
1315 exit 2
1416fi
1517
@@ -28,10 +30,13 @@ for target in "$@"; do
2830 exit 1
2931 fi
3032
31- if [ -d " ${normalized} " ]; then
32- echo " Error: directory deletion is not allowed: ${target} " >&2
33+ # Reject the bare .claude/tmp/ root (must have at least one path
34+ # component beneath it). Trailing slash is normalized away first.
35+ stripped=" ${normalized%/ } "
36+ if [[ " ${stripped} " == " ${ALLOWED_PREFIX%/ } " ]]; then
37+ echo " Error: deleting the .claude/tmp/ root itself is not allowed: ${target} " >&2
3338 exit 1
3439 fi
3540
36- rm -f -- " ${normalized} "
41+ rm -rf -- " ${normalized} "
3742done
0 commit comments