Max Techera.

Architecting Production AI Since 2012

Site

CoursesBlogMy StoryFAQ

Social

Legal

PrivacyTerms

© 2026 Max Techera. All rights reserved.

System Stable // Uruguay to Global
Max Techera.
CoursesBlog
Back to course

Claude Code Mastery: From 0 to 10x Developer

Progress0/13
1. Foundations
  • 1
    Introduction to Claude Code
  • 2
    Installation and Configuration
2. Working Modes
  • 1
    Default Mode (Interactive)
  • 2
    Auto Mode (YOLO)
  • 3
    Plan Mode and Extended Thinking
3. Memory Systems
  • 1
    The CLAUDE.md System
  • 2
    Context Management
4. Advanced Techniques
  • 1
    Sub-agents
  • 2
    MCP Integrations
  • 3
    Hooks
5. Production
  • 1
    Testing with Claude
  • 2
    CI/CD Pipelines
6. Action Plan
  • 1
    The 7-Day Plan
0%
CoursesClaude Code Mastery: From 0 to 10x DeveloperAdvanced TechniquesHooks
Advanced Techniques

Hooks

Automate actions with hooks that run before and after Claude operations like file edits and command execution.

1.695 min

Hooks

Hooks let you run custom scripts before or after Claude performs actions, enabling powerful automation.

What Are Hooks?

Hooks are scripts that execute at specific points:

  • PreToolUse - Before Claude uses a tool
  • PostToolUse - After Claude uses a tool
  • PreEdit - Before file modifications
  • PostEdit - After file modifications

Configuring Hooks

Add hooks to your settings:

{
  "hooks": {
    "PostEdit": {
      "command": "npm run lint:fix",
      "pattern": "**/*.ts"
    }
  }
}

Common Hook Patterns

Auto-format on Edit

{
  "hooks": {
    "PostEdit": {
      "command": "prettier --write",
      "pattern": "**/*.{ts,tsx,js,jsx}"
    }
  }
}

Auto-lint

{
  "hooks": {
    "PostEdit": {
      "command": "eslint --fix",
      "pattern": "src/**/*.ts"
    }
  }
}

Run Tests on Change

{
  "hooks": {
    "PostEdit": {
      "command": "npm test -- --related",
      "pattern": "src/**/*.ts"
    }
  }
}

Notify on Complete

{
  "hooks": {
    "PostToolUse": {
      "command": "terminal-notifier -message 'Task complete'",
      "tools": ["bash"]
    }
  }
}

Hook Configuration Options

{
  "hooks": {
    "PostEdit": {
      "command": "string",      // Command to run
      "pattern": "glob",        // File pattern match
      "tools": ["array"],       // Tool types to match
      "timeout": 30000,         // Timeout in ms
      "continueOnError": true   // Don't fail on hook error
    }
  }
}

Advanced Patterns

Chain Multiple Hooks

{
  "hooks": {
    "PostEdit": [
      {
        "command": "prettier --write",
        "pattern": "**/*.ts"
      },
      {
        "command": "eslint --fix",
        "pattern": "**/*.ts"
      }
    ]
  }
}

Conditional Hooks

{
  "hooks": {
    "PostEdit": {
      "command": "./scripts/validate.sh",
      "pattern": "src/critical/**/*"
    }
  }
}

Best Practices

Keep Hooks Fast

Slow hooks break flow:

// Good - fast
{ "command": "prettier --write" }
 
// Bad - slow
{ "command": "npm run build && npm test" }

Fail Gracefully

{
  "continueOnError": true,
  "timeout": 5000
}

Log Output

Debug with verbose logging:

{
  "command": "./hook.sh 2>&1 | tee hook.log"
}

Next Steps

In the next module, you'll learn about testing and CI/CD integration for production deployments.

Previous
MCP Integrations
Next
Testing with Claude