Skip to content

Make validate_brain_file hook portable across python/python3#3

Open
hema-sanam wants to merge 1 commit into
phuryn:mainfrom
hema-sanam:fix/portable-python-hook
Open

Make validate_brain_file hook portable across python/python3#3
hema-sanam wants to merge 1 commit into
phuryn:mainfrom
hema-sanam:fix/portable-python-hook

Conversation

@hema-sanam

Copy link
Copy Markdown

Problem

The scaffold's .claude/settings.json wires the validate_brain_file.py PostToolUse hook with a bare python:

"command": "python .claude/hooks/validate_brain_file.py"

On macOS (and many modern Linux distros) only python3 is on PATHpython doesn't exist. So a PM-brain workspace generated on those systems fails to run the validator on every Write/Edit, silently losing the provenance/link checks the hook is meant to enforce.

Fix

Use a POSIX-shell launcher that prefers python3 and falls back to python:

"command": "sh -c 'if command -v python3 >/dev/null 2>&1; then python3 .claude/hooks/validate_brain_file.py; else python .claude/hooks/validate_brain_file.py; fi'"
  • No change to validate_brain_file.py itself — launcher only.
  • Works on macOS/Linux natively and on Windows via Git Bash (where Claude Code already runs sh).
  • The hook's shebang is already #!/usr/bin/env python3, so this just makes the invocation match that intent.

Test plan

  • JSON remains valid (single-quoted sh -c arg, no inner double quotes to escape).
  • On macOS: trigger a Write under hypotheses/ in a generated workspace and confirm the hook runs via python3.

🤖 Generated with Claude Code

The PostToolUse hook in the scaffold's settings.json invoked bare `python`,
which doesn't exist on macOS (and many Linux distros), where only `python3`
is on PATH. A generated PM-brain workspace would then fail to run the
validator on Write/Edit.

Use a POSIX-shell launcher that prefers python3 and falls back to python:

    sh -c 'if command -v python3 >/dev/null 2>&1; then \
        python3 .claude/hooks/validate_brain_file.py; \
      else python .claude/hooks/validate_brain_file.py; fi'

No logic change to the hook itself.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant