Files
claude-foundations/scripts/find-project-root
Paul O'Reilly e94417b896 Add best practices, hooks, memory files, and scripts from recent sessions
Includes: spec-driven and test-driven development best practices,
reproduce-before-fixing debugging workflow, require-plan-file hook,
find-project-root script, session logs, memory files for decisions/
gotchas/process-lessons, and updates to existing best practice topics.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 09:47:47 +13:00

31 lines
757 B
Bash
Executable File

#!/usr/bin/env bash
# Walk up from CWD to find the highest directory containing CLAUDE.md.
# Usage:
# eval "$(scripts/find-project-root)" # sets CLAUDE_PROJECT_ROOT
# export CLAUDE_PROJECT_ROOT="$(scripts/find-project-root --print)"
#
# With --print: outputs just the path (for subshell capture).
# Without flags: outputs an export statement (for eval).
set -euo pipefail
root=""
dir="$(pwd)"
while [[ "$dir" != "/" ]]; do
if [[ -f "$dir/CLAUDE.md" ]]; then
root="$dir"
fi
dir="$(dirname "$dir")"
done
if [[ -z "$root" ]]; then
echo "ERROR: No CLAUDE.md found in any parent directory of $(pwd)" >&2
exit 1
fi
if [[ "${1:-}" == "--print" ]]; then
echo "$root"
else
echo "export CLAUDE_PROJECT_ROOT=\"$root\""
fi