AGENT0S
HomeLibraryAgentic
FeedbackLearn AI
LIVE
Agent0s · AI Intelligence Library
Share FeedbackUpdated daily · 7am PST
Library/hook
hookintermediateClaude Code

Claude Code Hooks & CLAUDE.md: Automate Your Dev Workflow with Lifecycle Events

Claude Code hooks let you attach shell commands to coding events—like auto-formatting files with Prettier every time Claude edits them—without any manual intervention. CLAUDE.md is a special project file that feeds Claude your codebase rules, build commands, and conventions upfront so it stops asking redundant questions. Together, these two features turn Claude Code from a reactive assistant into a self-disciplined automated dev pipeline.

AI SETUP PROMPT

Paste into Claude Code — it will scan your project and set everything up

# Install & Configure: Claude Code Hooks & CLAUDE.md: Automate Your Dev Workflow with Lifecycle Events

## What This Is
Claude Code hooks let you attach shell commands to coding events—like auto-formatting files with Prettier every time Claude edits them—without any manual intervention. CLAUDE.md is a special project file that feeds Claude your codebase rules, build commands, and conventions upfront so it stops asking redundant questions. Together, these two features turn Claude Code from a reactive assistant into a self-disciplined automated dev pipeline.

Source: https://serenitiesai.com/articles/claude-code-hooks-guide-2026

## Before You Start

Scan my workspace and analyze:
- The project language, framework, and directory structure
- Existing agent configuration (check for .claude/, .codex/, CLAUDE.md, settings.json, commands/, skills/ directories)

Then ask me before proceeding:
1. Which lifecycle event should this hook fire on? (PreToolUse, PostToolUse, Notification, etc.)
2. Are there any files, patterns, or tools this should be scoped to?

## Source Access Note

The source URL (https://serenitiesai.com/articles/claude-code-hooks-guide-2026) may not be directly accessible from the terminal. Use the Reference Implementation and Additional Context sections below instead. If you need more details, ask me to paste relevant content from the source.

## What to Implement

This is an **Agent Hook** — a shell/HTTP command that fires at lifecycle events.

- Add the hook configuration to `.claude/settings.json` under the lifecycle event I specified
- If the hook needs a shell script, create it and make it executable (`chmod +x`)
- If the hook calls an external API, configure it using credentials from my .env files
- Validate the JSON config is syntactically correct before saving

## Additional Context

- Create a `.claude/` directory in your project root and add a `settings.json` file with a Prettier hook using the exact config snippet below, then run any Claude edit command to confirm auto-formatting fires on save.
- Write a CLAUDE.md file in your project root listing your build command, linter setup, preferred naming conventions, and folder structure—keep it under 200 lines so Claude loads it every session without truncation.
- Add a second hook entry with a `matcher` of `PostToolUse` and a command that runs `tsc --noEmit` to catch TypeScript errors automatically after every Claude-generated code change.

## Reference Implementation

```
{
  "hooks": [
    {
      "matcher": "Edit|Write",
      "hooks": [
        {
          "type": "command",
          "command": "prettier --write \"$CLAUDE_FILE_PATHS\""
        }
      ]
    }
  ]
}
```

## Guidelines

- Adapt everything to my existing project — do not assume a specific stack or directory layout
- Review any fetched code for safety before installing or executing it
- After setup, run a quick verification and show me a summary of exactly what was installed, where, and how to use it
2,986 charactersCompatible with Claude Code & Codex CLI
MANUAL SETUP STEPS
  1. 01Create a `.claude/` directory in your project root and add a `settings.json` file with a Prettier hook using the exact config snippet below, then run any Claude edit command to confirm auto-formatting fires on save.
  2. 02Write a CLAUDE.md file in your project root listing your build command, linter setup, preferred naming conventions, and folder structure—keep it under 200 lines so Claude loads it every session without truncation.
  3. 03Add a second hook entry with a `matcher` of `PostToolUse` and a command that runs `tsc --noEmit` to catch TypeScript errors automatically after every Claude-generated code change.

CODE INTELLIGENCE

bash
{
  "hooks": [
    {
      "matcher": "Edit|Write",
      "hooks": [
        {
          "type": "command",
          "command": "prettier --write \"$CLAUDE_FILE_PATHS\""
        }
      ]
    }
  ]
}

FIELD OPERATIONS

Automated Code Quality Gate for Claude Edits

Build a hooks configuration that chains three sequential commands on every Edit or Write event: Prettier formatting, ESLint auto-fix, and a Jest test run scoped to the changed file. Any non-zero exit code blocks Claude from proceeding, creating a local CI-like gate with zero extra tooling.

Dangerous Command Blocker with Audit Log

Use a PreToolUse hook with a bash script that intercepts shell commands matching patterns like `rm -rf`, `DROP TABLE`, or `git push --force`, writes them to a local audit.log with a timestamp, and exits with code 1 to block execution—giving teams a lightweight safety net for AI-assisted ops work.

STRATEGIC APPLICATIONS

  • →A software agency onboarding a new client project can drop a CLAUDE.md with the client's coding standards and a hooks config enforcing their linter on every AI edit, ensuring all Claude-generated code is compliant before it ever reaches code review.
  • →A solo SaaS founder using Claude Code for rapid feature development can set up PostToolUse hooks that auto-run integration tests against a local database after every file write, catching regressions in seconds rather than discovering them in production.

TAGS

#claude-code#hooks#automation#CLAUDE.md#lifecycle-events#prettier#typescript#workflow#settings.json#shell-commands
Source: WEB · Quality score: 7/10
VIEW SOURCE