Skip to content

Instantly share code, notes, and snippets.

@w3cj
Created July 24, 2025 20:43
Show Gist options
  • Save w3cj/439cbee2b784e93d0e0193dccddbdf58 to your computer and use it in GitHub Desktop.
Save w3cj/439cbee2b784e93d0e0193dccddbdf58 to your computer and use it in GitHub Desktop.
Claude - Block npm / npx
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "./.claude/use-pnpm-hook.sh"
}
]
}
]
}
}
#!/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
@taowang1993
Copy link

We need more CC hooks from CJ!!!

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