Skip to content

toolkit: hooks read $CLAUDE_FILE_PATHS which does not exist; .env guard and formatter never ran #750

Description

@genwave-radio

🐛 Problem

Both hooks in .claude/settings.example.json (copied verbatim into the active settings.local.json) read $CLAUDE_FILE_PATHS:

case "$CLAUDE_FILE_PATHS" in *.cs) dotnet format --include "$CLAUDE_FILE_PATHS" ... ;; esac
echo "$CLAUDE_FILE_PATHS" | grep -qE '\.env(\..*)?$' && { ...; exit 2; } || exit 0

Claude Code exports no such variable. Hook env vars are CLAUDE_PROJECT_DIR, CLAUDE_EFFORT, CLAUDE_ENV_FILE; the edited path arrives as stdin JSON at .tool_input.file_path. So the .env guard has never blocked anything and the formatter has never run. || true hid the failure.

Secondary: test -f package.json checks the repo root but the UI lives in admin-ui/; the repo uses npm (admin-ui/package-lock.json), not bunx.

✅ Fix

"PreToolUse": [{ "matcher": "Edit|Write", "hooks": [{ "type": "command",
  "command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in *.env|*.env.*) echo \"refuse: $f is an env file\" >&2; exit 2;; esac; exit 0" }] }],
"PostToolUse": [{ "matcher": "Edit|Write", "hooks": [{ "type": "command",
  "command": "f=$(jq -r '.tool_input.file_path // empty'); case \"$f\" in */admin-ui/*.ts|*/admin-ui/*.tsx) (cd \"$CLAUDE_PROJECT_DIR/admin-ui\" && npx --no-install prettier --write \"$f\" >&2);; esac; exit 0" }] }]

Drop the per-file dotnet format hook (it restores and formats the whole project on every Write; CI already checks format). Apply to both the example file and the personal settings.local.json.

📎 Source

docs/AI_TOOLKIT_AUDIT_CLAUDE.md F2.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High prioritybugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions