Files
claude-foundations/hooks/require-plan-file.sh
Paul O'Reilly 7838db4f26 feat(hooks): allow projects to opt out of require-plan-file check
Add a sentinel-file escape hatch: if `.claude/skip-plan-file-check`
exists in the project's cwd, the ExitPlanMode hook exits 0 without
demanding a local *-PLAN.md file.

Needed by projects (e.g. agent-runtimes) that manage plans via an
external system (work-items CP) rather than local repo files.
2026-07-12 11:40:07 +12:00

25 lines
924 B
Bash
Executable File

#!/bin/bash
# Blocks ExitPlanMode unless a *-PLAN.md file exists in the current working directory.
# Fired via PreToolUse hook on ExitPlanMode.
# Input: JSON on stdin with session context including "cwd".
INPUT=$(cat)
CWD=$(echo "$INPUT" | python3 -c "import sys, json; print(json.load(sys.stdin).get('cwd', ''))" 2>/dev/null)
if [ -z "$CWD" ]; then
exit 0 # Can't determine cwd, allow through
fi
# Projects can opt out by placing .claude/skip-plan-file-check in their root.
# Used when the project manages plans via an external system (e.g. a work-items CP).
if [ -f "$CWD/.claude/skip-plan-file-check" ]; then
exit 0
fi
if ls "$CWD"/*-PLAN.md 2>/dev/null | grep -q .; then
exit 0 # Plan file exists, allow exit
fi
echo "No PLAN.md file found in $CWD. Before exiting plan mode, write the complete plan to a file named [MILESTONE]-[PURPOSE]-PLAN.md in the project root (e.g. M2-auth-PLAN.md)." >&2
exit 2