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

  • Set allow, ask and deny permission rules in a shared settings file so routine commands run and risky ones prompt or stop.
  • Block edits to protected paths and dangerous shell commands with PreToolUse hooks that hold in every permission mode.
  • Run a formatter and fast check after each edit, and a test gate before Claude stops, then roll the setup out to the team with a verified checklist.
  • What is inside

  • Starter settings.json with permission rules
  • 4 hook templates
  • Hook event reference table
  • Rollout checklist
  • 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

    Download the free PDF

    Tools covered

    Claude Code

    Related reading

    Claude Code review: terminal-first agentic coding

    Claude Code vs Codex

    Related resources

    CLAUDE.md Production Template: A practical repository instruction file for safer, more consistent Claude Code work.

    AI Agent Production Safety Checklist: Controls for tool permissions, data handling, budgets, approvals, observability, and shutdown.

    Codex Production Prompt Pack: Production-grade prompts for planning, implementing, verifying, and shipping changes with Codex.

    Browse the site

  • Home
  • About
  • Story
  • Work
  • Expertise
  • The AI practice
  • AI Product Development
  • AI Agents
  • AI Automation
  • AI Consulting
  • Arabic-first AI Products
  • AI in Kuwait
  • Web Development
  • Claude
  • Lovable
  • Notion
  • Webflow
  • Shopify
  • WordPress
  • AI Solutions
  • Services
  • Business Strategy
  • Growth Planning
  • Tools
  • Resources
  • Blog
  • Listening
  • Books
  • Dubai
  • Stack
  • Contact
  • Get a quote
  • Privacy
  • Terms