Hooks, Skills, and Custom Commands
Automate your workflow with hooks that trigger on file saves and edits, plus custom slash commands for reusable prompts.
What hooks are
Hooks are automated actions that Claude Code runs at specific points during its workflow. They let you inject custom behaviour without manually asking Claude Code to do something every time. There are four hook types. PreToolUse runs before Claude Code executes a tool — before it reads a file, writes a file, or runs a command. You can use this to validate, transform, or block actions. PostToolUse runs after a tool executes — after a file is written or a command completes. This is where you put linting, formatting, and testing automation. Notification fires when Claude Code wants to notify you about something — task completion, errors, or status updates. You can route these to Slack, email, or desktop notifications. Stop runs when Claude Code finishes a task or conversation turn. Use this for cleanup, summary generation, or triggering follow-up workflows. Hooks are configured in your project's .claude/settings.json file. Each hook specifies a matcher (which tool or event it applies to) and a command (what to run). The command is a standard shell command — anything your terminal can execute, a hook can trigger.
Practical hook examples
Auto-lint on file save is the most common hook. When Claude Code writes a TypeScript file, automatically run ESLint and Prettier: configure a PostToolUse hook matching the Write tool with a command like "npx eslint --fix $CLAUDE_FILE_PATH && npx prettier --write $CLAUDE_FILE_PATH". This ensures every file Claude Code creates or modifies meets your coding standards without you asking. Auto-test on edit: when Claude Code modifies a file in src/, automatically run related tests. Match PostToolUse on Write for paths matching src/*, and run your test command filtering for related test files. This catches regressions immediately — before you even review the change. Notification on completion: configure a Notification hook to send a desktop notification or Slack message when Claude Code finishes a long-running task. On macOS, use osascript to trigger a native notification. For Slack, curl to a webhook URL. This lets you start a task, switch to other work, and get alerted when Claude Code is done. Error logging: a PostToolUse hook on Bash that checks the exit code and logs failures to a file. This creates an audit trail of every command Claude Code ran and which ones failed — invaluable for debugging.
Custom slash commands
Custom slash commands let you create reusable prompts that you trigger with a short command. They live in your project's .claude/commands/ directory as markdown files. Each file becomes a slash command — the filename (without .md) is the command name. For example, create .claude/commands/review.md with the content: "Review the staged git changes. Check for: bugs, security issues, performance problems, and style violations. Format as a markdown checklist." Now when you type /review in Claude Code, it executes that prompt. This is powerful for standardising team workflows. Some practical commands: /refactor — "Identify the most complex function in this file, explain why it is complex, and refactor it into smaller functions." /test — "Look at this file and write comprehensive unit tests covering edge cases and error paths." /doc — "Add JSDoc comments to all exported functions and types in this file." /migrate — "Check this file for deprecated APIs and update them to current equivalents." Commands can include variables using $ARGUMENTS — anything typed after the command name gets substituted in. This makes commands flexible: /review could become /review src/api/users.ts to target a specific file.
Settings.json configuration
All hooks and preferences live in .claude/settings.json in your project root. The file has a clean JSON structure with sections for hooks, permissions, and preferences. A typical settings.json looks like this: the hooks section contains an array for each hook type (PreToolUse, PostToolUse, Notification, Stop). Each hook entry has a matcher object (specifying which tool and optionally a file path pattern) and a command string. The permissions section controls which tools are allowed, denied, or require approval. You can allowlist tools like Read and Glob while requiring approval for Bash and Write. This gives you fine-grained control over what Claude Code can do autonomously versus what needs your explicit approval. Settings cascade: user-level settings in ~/.claude/settings.json apply everywhere, project-level settings in .claude/settings.json override for that project, and directory-level settings can further specialise. This means your personal preferences travel with you, but each project can enforce its own rules. Teams should commit .claude/settings.json to version control so everyone shares the same hooks and permission configuration.
Building a personal workflow with hooks and commands
The real power comes from combining hooks and commands into a cohesive workflow. Here is a practical setup for a TypeScript project. First, create a PostToolUse hook that auto-formats every file Claude Code writes with Prettier and ESLint. Second, create a PostToolUse hook on Bash that runs affected tests when source files change. Third, create custom commands: /pr for generating a pull request description from staged changes, /changelog for appending to CHANGELOG.md based on recent commits, /security for scanning a file for common vulnerabilities, and /explain for generating a plain-English explanation of a complex function. Fourth, set up a Notification hook that pings you on Slack when Claude Code finishes any task taking more than 30 seconds. The workflow then becomes: you give Claude Code a task, it works autonomously with auto-formatting and auto-testing, you get a Slack ping when it is done, you review the changes, and you use /pr to generate the pull request. This is not hypothetical — this is how productive Claude Code users actually work. The upfront investment in hooks and commands pays for itself within a week.
Claude Code Deep Dive
This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.
Go to lesson