Created
July 24, 2025 20:43
-
-
Save w3cj/439cbee2b784e93d0e0193dccddbdf58 to your computer and use it in GitHub Desktop.
Claude - Block npm / npx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"hooks": { | |
"PreToolUse": [ | |
{ | |
"matcher": "Bash", | |
"hooks": [ | |
{ | |
"type": "command", | |
"command": "./.claude/use-pnpm-hook.sh" | |
} | |
] | |
} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# hook to block npm/npx commands and suggest pnpm | |
# Read JSON input | |
input=$(cat) | |
command=$(echo "$input" | jq -r '.tool_input.command // ""') | |
# Check for npm or npx command and block if found | |
if [[ "$command" =~ ^npm[[:space:]] || "$command" =~ ^npx[[:space:]] ]]; then | |
echo '{"decision": "block", "reason": "npm/npx commands are not allowed. Please use pnpm instead."}' | |
exit 2 | |
fi | |
# Allow the command | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We need more CC hooks from CJ!!!