Build This Now
Build This Now
Keyboard ShortcutsStatus Line Guide
speedy_devvkoen_salo
Blog/Toolkit/Hooks/Claude Code Setup Hooks

Claude Code Setup Hooks

Braid scripts, agents, and docs into Claude Code setup hooks. One command runs a deterministic script, hands output to a diagnosing agent, logs living docs.

Stop configuring. Start building.

SaaS builder templates with AI orchestration.

Published Mar 11, 2026Toolkit hubHooks index

The quality of an engineering team shows up in one number: how long it takes a new hire to get the project running on their machine.

Great teams need one link, one doc, a few commands. Most teams eat a day or two of pairing, Slack threads, dusty wiki pages, and back and forth over why something broke.

Agents make this solvable.

Getting a codebase up has always been a choice between three bad shapes:

Pure scripts are predictable but fragile. They run the same commands every time and freeze the moment reality shifts. A missing dependency or a downed database, and the script just dies.

Pure agents are clever but unreliable. You cannot plug one into a CI/CD pipeline and expect the exact same output across every run.

Pure docs are flexible but human-dependent. Nobody reads them, and they go stale inside a few weeks.

What works is braiding all three together. Scripts handle the execution. Agents watch over them. You end up with a living document that executes.

Setup hooks landed in Claude Code on January 25th, 2026. They're a dedicated hook type that fires before your session spins up. When you run:

claude --init

The setup hook goes first, then Claude starts. The hook can install packages, seed the database, and prep your environment. By the time Claude boots, it already knows what happened.

This is where things get interesting. You can tack a prompt onto the init flag:

claude --init "/install"

Now the hook runs, and the /install command fires right after. The agent reads the log files, works out what happened, and reports back in plain language.

claude --init "/install true"

Three setups fall out of this:

┌─────────────────────────────────────────────────────────┐
│  DETERMINISTIC          AGENTIC           INTERACTIVE   │
│  (hooks only)           (hooks + prompt)  (hooks + Qs)  │
│                                                         │
│  claude --init          /install          /install true │
│                                                         │
│  - Fast                 - Supervised      - Asks Qs     │
│  - Predictable          - Diagnostic      - Adapts      │
│  - CI-friendly          - Reports status  - Context-    │
│                                             aware       │
└─────────────────────────────────────────────────────────┘

Deterministic mode: Script only. Fast, repeatable, perfect for CI/CD where every run has to match.

Agentic mode: Script first, then an agent reads the results. It scans log files, parses errors, and tells you in plain language what went right or wrong.

Interactive mode: Script first, then the agent pulls you into a short Q&A. "Fresh database or keep the old one? Full install or minimal? Want me to check prerequisites first?"

The script is always the source of truth. Hooks and prompts call the same script every time. What changes is whether an agent supervises, and whether it asks you questions up front.

Just is a tiny command runner, and it pairs nicely with setup hooks. Treat it as a launchpad for your engineering work. Instead of memorizing flags, you type just and see every available command:

just          # See all commands
just cldi     # Deterministic setup
just cldii    # Agentic setup (with reporting)
just cldit    # Interactive setup (asks questions)

The justfile itself stays simple:

# Deterministic codebase setup
cldi:
  claude --init
 
# Agentic codebase setup
cldii:
  claude --init "/install"
 
# Interactive setup (asks questions)
cldit:
  claude --init "/install true"
 
# Deterministic maintenance
cldm:
  claude --maintenance
 
# Agentic maintenance (with reporting)
cldmm:
  claude --maintenance "/maintenance"

Teammates and agents never have to memorize flags twice. They run just cldii and things work.

ScenarioModeCommand
CI/CD pipelineDeterministicclaude --init-only
Quick local setupDeterministicjust cldi
Setup failed, need diagnosisAgenticjust cldii
New engineer, unfamiliar codebaseInteractivejust cldit
Weekly dependency updatesAgenticjust cldmm

--init-only is the pipeline flag. It runs the hook, returns an exit code, and shuts down. No interactive session attached.

Onboarding is where this shines. A new engineer types just cldit and the agent walks them through it:

Agent: How should I handle the database?

┌─ Database Setup ─────────────────────────────────┐
│  ○ Fresh database (Recommended)                  │
│  ○ Keep existing                                 │
│  ○ Skip database setup                           │
└──────────────────────────────────────────────────┘

The agent asks about install mode, env variables, and whether to verify prerequisites first. It adapts to the answers and runs only the steps that match.

Scripts cannot do this. They play the same tape every time. Agents can stop mid-run, ask a clarifying question, and branch on the answer.

Setup hooks are one of 12 lifecycle events in the hook system. Configuration lives in .claude/settings.json:

{
  "hooks": {
    "Setup": [
      {
        "matcher": "init",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/setup_init.py",
            "timeout": 120
          }
        ]
      },
      {
        "matcher": "maintenance",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/setup_maintenance.py",
            "timeout": 60
          }
        ]
      }
    ]
  }
}

The hook script runs your commands and logs the whole thing:

def main():
    # Install backend dependencies
    run(["uv", "sync"], cwd="apps/backend")
 
    # Install frontend dependencies
    run(["npm", "install"], cwd="apps/frontend")
 
    # Initialize database
    run(["uv", "run", "python", "init_db.py"], cwd="apps/backend")
 
    # Tell Claude what happened
    print(json.dumps({
        "hookSpecificOutput": {
            "hookEventName": "Setup",
            "additionalContext": "Setup complete. Run 'just be' and 'just fe' to start."
        }
    }))

The /install slash command picks up the log and writes up the results:

---
description: Run setup and report installation results
---
 
## Workflow
 
1. Run /prime to understand the codebase
2. Read the log file at .claude/hooks/setup.init.log
3. Analyze for successes and failures
4. Write results to app_docs/install_results.md
5. Report to user

When something breaks, the agent already has the context to diagnose it. List the usual failure modes inside the prompt, and the agent will walk the fix playbook on its own.

Think about onboarding time against the pace you want your team to grow. Could one prompt handle setup and installation for a new hire? Could it make each step clear by asking before it acts?

Yes, on both counts. Agents are good enough for this. The missing piece is standardization.

Determinism preserved: The hook fires the same script each time. Zero LLM variance during execution. The agent only looks at results after the deterministic work finishes.

CI compatible: GitHub Actions runs claude --init-only and gets back a clean exit code.

Interactive when it matters: New hires get guided through setup. Everyone else runs the fast version.

A living document that executes: Your install process now lives in natural language, tucked into prompts that agents follow. Updates happen by editing the prompt.

Start simple. Write a .claude/hooks/setup_init.py script that installs your dependencies, wire it up in .claude/settings.json, then add an /install command that reads the log and reports back. Wrap the whole thing in a justfile so your team runs just install and stops thinking about it.

Need something lighter? If you only want to load different context per session type, a slash command is usually enough. No install script required.

Setup hooks pay off most when you want one command that installs the world, diagnoses the failures, and walks new engineers through each step. Scripts supply the certainty. Agents supply the judgment. If your team hops across Windows, Linux, and macOS, read the cross-platform hook patterns so the same setup runs on every OS.

Continue in Hooks

  • Context Backup Hooks for Claude Code
    A StatusLine-driven Claude Code context backup hook. Writes structured snapshots every 10K tokens so auto-compaction never eats errors, signatures, decisions.
  • Cross-Platform Hooks for Claude Code
    Cross-platform Claude Code hooks: skip .cmd, .sh, and .ps1 wrappers and invoke node directly so one .mjs file runs on macOS, Linux, and Windows across the team.
  • Hooks Guide
    Claude Code hooks from first principles: exit codes, JSON output, async commands, HTTP endpoints, PreToolUse and PostToolUse matchers, production patterns.
  • MCP Tool Hooks in Claude Code
    How to call MCP server tools directly from Claude Code hooks using type: mcp_tool — schema, substitution syntax, use cases, and production patterns.
  • Claude Code Permission Hook
    Install a three-tier Claude Code permission hook: instant allow for safe calls, instant deny for dangerous ones, LLM check for the gray area. No skip flag.
  • Self-Validating Claude Code Agents
    Self-validating Claude Code agents: wire PostToolUse lint hooks, Stop hooks, and read-only reviewer sub-agents into agent definitions so bad output never ships.

More from Toolkit

  • Keyboard Shortcuts
    Configure Claude Code keybindings.json: 17 contexts, keystroke syntax, chord sequences, modifier combinations, and how to unbind any default shortcut instantly.
  • Status Line Guide
    Set up a Claude Code status line for model name, git branch, session cost, and context usage. settings.json config, JSON input, bash, Python, Node.js scripts.
  • AI SEO and GEO Optimization
    A rundown of Generative Engine Optimization: how to get content cited inside ChatGPT, Claude, and Perplexity responses instead of just ranked on Google.
  • Claude Code vs Bolt.new: Which Should You Use?
    Bolt.new prototypes in 28 minutes with zero setup. Claude Code takes 90 minutes but ships production-ready code. Here is how to pick the right tool.

Stop configuring. Start building.

SaaS builder templates with AI orchestration.

On this page

No Headings

Stop configuring. Start building.

SaaS builder templates with AI orchestration.