-
Notifications
You must be signed in to change notification settings - Fork 284
PreToolUse:Bash hook - OPC script directory guard #148
Copy link
Copy link
Open
Description
Problem
When running /research-external, Claude can deviate from documented commands (cd $CLAUDE_OPC_DIR && uv run python scripts/mcp/...) and run from ~/.claude/ instead. This causes uv run to miss opc/pyproject.toml and its dependencies, resulting in ModuleNotFoundError.
Solution
Create a PreToolUse:Bash hook that:
- Detects
scripts/(mcp|core)/references in Bash commands - Blocks execution unless prefixed with
cd $CLAUDE_OPC_DIR && - Returns a deny message with the corrected command
Files
~/.claude/hooks/src/mcp-directory-guard.ts— hook implementation~/.claude/settings.json— register PreToolUse:Bash matcher
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels