#!/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