HomeClaude Code CLICustom Commands & Hooks
intermediate12 min read· Module 4, Lesson 7

🔗Custom Commands & Hooks

Create reusable workflows and automate actions

Custom Commands (Skills)

Custom commands let you package repeatable workflows that your whole team can share.

Creating a Custom Command

Create a file in .claude/commands/ in your project:

Terminal
mkdir -p .claude/commands

Example: /review-pr command

Create .claude/commands/review-pr.md:

Markdown
Review the current PR changes. For each file: 1. Check for bugs and logic errors 2. Verify error handling 3. Look for security issues 4. Check for performance problems 5. Verify tests cover the changes Format your review as: - **File**: path - **Issues**: list any problems - **Suggestions**: improvements

Now you can run:

Terminal
claude /review-pr

More Custom Command Ideas

.claude/commands/deploy-check.md:

Markdown
Before deploying, check: 1. All tests pass 2. No TypeScript errors 3. No lint warnings 4. Build succeeds 5. No TODO or FIXME comments in changed files Report a go/no-go decision with reasons.

.claude/commands/write-tests.md:

Markdown
Write comprehensive tests for the file I specify: 1. Unit tests for each exported function 2. Edge cases (null, undefined, empty, boundary values) 3. Error scenarios 4. Use the project's existing test patterns 5. Run the tests and fix any failures

Hooks

Hooks let you run shell commands automatically before or after Claude Code performs certain actions.

What Are Hooks?

WhenWhat Happens
Before file editRun a command before Claude edits a file
After file editAuto-format, lint, or run tests after edits
Before commandValidate or log before Claude runs a terminal command
After commandCheck results after Claude runs something

Example Hook: Auto-Format After Edit

In your Claude Code settings, you can configure hooks to automatically run Prettier after every file edit:

JSON
{ "hooks": { "afterEdit": "npx prettier --write {file}" } }

Example: Run Tests After Edit

JSON
{ "hooks": { "afterEdit": "npm test -- --related {file}" } }

MCP (Model Context Protocol)

MCP lets Claude Code connect to external data sources:

  • Google Drive — Read design docs
  • Jira — Update tickets
  • Slack — Post messages
  • Databases — Query data
  • Custom tools — Your own integrations

Setting Up MCP

MCP servers are configured in your Claude Code settings. Each server provides tools that Claude can use during a session.

Next up: Advanced Claude Code workflows — agent teams, CI/CD, and automation.