$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Claude CodeintermediateNew

Hooks Configuration

Share

Configure Claude Code hooks for automated pre/post actions

Works with OpenClaude

You are a Claude Code automation engineer. The user wants to configure Claude Code hooks for automated pre/post actions on file operations, code generation, and skill execution.

What to check first

  • Run claude-code config list to see current hook configuration
  • Check if .claude-code/hooks.json exists in your project root
  • Verify Node.js runtime is available (node --version)

Steps

  1. Create .claude-code/hooks.json in your project root with the hook registry structure
  2. Define pre-hooks that run before file writes using the beforeWrite event type
  3. Define post-hooks that run after code generation using the afterGenerate event type
  4. Specify the hook handler path (relative to project root) for each hook entry
  5. Add hook metadata including name, description, priority (0-100, higher runs first), and async flag
  6. Create handler modules that export a default function accepting context object with file path, content, and operation type
  7. Register hooks using claude-code hook register <hook-name> <handler-path> command
  8. Test hooks with a trial file write to verify execution order and error handling

Code

{
  "version": "1.0",
  "hooks": [
    {
      "id": "lint-before-write",
      "event": "beforeWrite",
      "name": "Lint Before Write",
      "description": "Run ESLint on generated code before writing to disk",
      "handler": ".claude-code/hooks/lint-handler.js",
      "priority": 90,
      "async": true,
      "config": {
        "ruleset": ".eslintrc.json",
        "fix": true
      },
      "enabled": true
    },
    {
      "id": "format-after-generate",
      "event": "afterGenerate",
      "name": "Format After Generate",
      "description": "Auto-format generated code with Prettier",
      "handler": ".claude-code/hooks/format-handler.js",
      "priority": 85,
      "async": true,
      "config": {
        "parser": "babel",
        "semi": true,
        "singleQuote": false
      },
      "enabled": true
    },
    {
      "id": "git-track-changes",
      "event": "afterWrite",
      "name": "Git Track Changes",
      "description": "Stage modified files to git automatically",
      "handler": ".claude-code/hooks/git-handler.js",
      "priority": 50,
      "async": false,
      "enabled": true
    }
  ]
}
// .claude-code/hooks/lint-handler.js
const { execSync } = require('child_process');
const path = require('path');

module.exports = async function lintHandler(context) {
  const { filePath, content, config } =

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryClaude Code
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
claude-codehooksautomation

Install command:

curl -o ~/.claude/skills/hooks-configuration.md https://claude-skills-hub.vercel.app/skills/claude-code/hooks-configuration.md

Related Claude Code Skills

Other Claude Code skills in the same category — free to download.

Want a Claude Code skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.