Claude Code Hooks and Permissions Starter
Starter permission rules and four hook templates that make Claude Code enforce a repository's hard rules.
Move hard rules out of CLAUDE.md prose and into permission rules and hooks that the harness enforces.
Template · AI Coding · PDF, 17 pages · Free · Updated 2026-11-22
What you will accomplish
What is inside
Written for: Teams using Claude Code; Repository maintainers; Platform engineers.
Preview
Starter settings.json
Permission rules for a shared project file: what runs without asking, what always prompts, and what is blocked.
"allow": [
"Bash([LINT COMMAND])",
"Bash([TEST COMMAND] *)",
"Bash([BUILD COMMAND])",
"Bash(git commit *)"
],
"ask": [
"Bash(git push *)",
"Bash([DEPLOY COMMAND] *)",
"Bash([MIGRATION COMMAND] *)",
"Edit(/[CI CONFIG DIRECTORY]/**)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./[SECRETS DIRECTORY]/**)",
"Edit(/[GENERATED OR VENDORED DIRECTORY]/**)",
"Bash(curl *)",
"Bash(git push --force *)",
"Bash(git reset --hard *)",
"Bash([DESTRUCTIVE COMMAND] *)"
],
Hook template 1: block edits to protected paths
A PreToolUse hook on Edit and Write that exits with code 2 when the target file matches a protected path, so the edit never runs and Claude is told why.
INPUT=$(cat)
FILE_PATH=$(printf '%s' "$INPUT" | jq -r '.tool_input.file_path // empty')
# file_path arrives absolute. On Windows it uses backslashes, so normalize.
FILE_PATH=$(printf '%s' "$FILE_PATH" | tr '\\' '/')
# One path fragment per line. Keep the slashes: "/.git/" must not match ".github".
while IFS= read -r pattern; do
case "$FILE_PATH" in
*"$pattern"*)
echo "Blocked: $FILE_PATH matches protected pattern '$pattern'. [WHAT TO DO INSTEAD]" >&2
exit 2
;;
esac
done <<'EOF'
/.env
/.git/
/[LOCKFILE NAME]
/[GENERATED OR VENDORED DIRECTORY]/
/[APPLIED MIGRATIONS DIRECTORY]/
EOF
Tools covered
Related reading
Claude Code review: terminal-first agentic coding