Claude Code — Custom Commands & CLAUDE.md
Create /slash commands, hooks system, permissions setup
Claude Code is Anthropic's terminal-based AI coding agent. Unlike Cursor or Copilot which work inside an editor, Claude Code runs in your terminal and can autonomously navigate your codebase, run commands, edit files, and complete multi-step tasks. With CLAUDE.md and custom slash commands, you can make it deeply understand your specific project and workflow.
What You'll Learn
- What Claude Code is and how it differs from IDE-based AI tools
- Setting up CLAUDE.md (your project's AI instruction file)
- Creating custom /slash commands for repeatable tasks
- The hooks system for automated behaviors
- How to configure permissions safely
What Is Claude Code?
Claude Code is a command-line AI agent powered by Claude Sonnet 4.6. You install it via npm, run claude in your project directory, and interact through a REPL interface. It can:
- Read and write files in your project
- Run terminal commands (with your permission)
- Understand your entire codebase through indexing
- Complete multi-step tasks autonomously
- Work through complex refactors, bug fixes, and feature implementations
Requirements: Node.js, an Anthropic API key (or Claude Pro subscription at $20/month which includes Claude Code access).
Install:
npm install -g @anthropic-ai/claude-code
Then run in any project directory:
claude
Setting Up CLAUDE.md
CLAUDE.md is a Markdown file you create at the root of your project (or in ~/.claude/CLAUDE.md for global settings). When Claude Code starts, it reads this file automatically and uses it as persistent context for the entire session.
Why this matters: Without CLAUDE.md, you have to explain your project's conventions and architecture in every conversation. With CLAUDE.md, Claude Code already knows your stack, patterns, and rules before you type a single message.
Example CLAUDE.md for a Next.js project:
# My Project — Claude Code Instructions
## Tech Stack
- Next.js 15 with App Router
- TypeScript (strict: true)
- Tailwind CSS 4
- PostgreSQL + Prisma ORM
- Authentication: NextAuth.js
## Conventions
- Use Server Components by default
- 'use client' only when state/effects are needed
- All database queries go in lib/db/ files
- API routes follow RESTful naming: plural nouns
- Error handling: always use try/catch with typed errors
- Component naming: PascalCase, files match component names
## Code Style
- No default exports (use named exports)
- No 'any' TypeScript types — use proper types or 'unknown'
- Prefer async/await over .then()
- Comment complex logic, not obvious code
## Testing
- Playwright for E2E tests only
- Test files: *.spec.ts in e2e/ directory
## What NOT to do
- Never commit .env files
- Never use client-side database queries
- Never use console.log in production code
The more specific your CLAUDE.md, the better Claude Code performs on your project.
🇮🇳 India Note: If you are contributing to open-source projects on GitHub or working on a team, CLAUDE.md should be committed to the repository. This way, every team member using Claude Code gets consistent AI behavior on the project.
Creating Custom /Slash Commands
Custom slash commands let you define reusable prompts that you can invoke with /command-name. They save you from typing the same complex instructions repeatedly.
Slash commands are defined in your Claude Code settings file. The location:
- macOS/Linux:
~/.claude/settings.json - Windows:
%APPDATA%\claude\settings.json
Example settings.json with custom commands:
{
"commands": {
"commit": {
"description": "Create a git commit following our conventions",
"prompt": "Review the staged changes (git diff --staged), write a clear commit message following conventional commits format (feat/fix/chore/docs: description), and create the commit. Never use --no-verify."
},
"review-pr": {
"description": "Review a PR for quality and bugs",
"prompt": "Review the changes in this PR. Check for: 1) Logic errors or bugs, 2) Security issues (SQL injection, XSS, auth bypasses), 3) Performance problems, 4) Missing error handling, 5) TypeScript type issues. Format as a numbered list with severity (Critical/Major/Minor)."
},
"test": {
"description": "Write Playwright E2E tests for current feature",
"prompt": "Look at the current feature/page I am working on and write comprehensive Playwright E2E tests. Cover: happy path, error states, and edge cases. Follow our existing test patterns in e2e/."
},
"explain": {
"description": "Explain a complex part of the codebase",
"prompt": "Explain the code I am pointing at clearly. Include: what it does, why it is structured this way, potential edge cases, and how it connects to the rest of the system."
}
}
}
Use commands in Claude Code by typing /commit, /review-pr, etc.
The Hooks System
Hooks let you trigger automated Claude Code actions when specific events occur. This is powerful for enforcing quality gates automatically.
Available hook triggers:
pre_tool_call— runs before Claude Code executes any tool/commandpost_tool_call— runs after a tool/command completeson_error— runs when an error occurs
Example: Auto-format Python files after edits:
{
"hooks": {
"post_tool_call": [
{
"name": "format-python",
"condition": "tool == 'write_file' && file.endsWith('.py')",
"action": "run_command",
"command": "black {file}"
}
]
}
}
Example: Warn before running destructive commands:
{
"hooks": {
"pre_tool_call": [
{
"name": "warn-destructive",
"condition": "command.includes('drop table') || command.includes('rm -rf')",
"action": "require_confirmation",
"message": "This command is destructive. Are you sure?"
}
]
}
}
Permissions Configuration
Claude Code asks for permission before running commands by default. You can configure which commands require confirmation and which run automatically:
{
"permissions": {
"allow": [
"git status",
"git diff",
"npm run *",
"npx tsc --noEmit"
],
"require_confirmation": [
"git commit *",
"git push *",
"rm *",
"docker *"
],
"deny": [
"git push --force",
"rm -rf /"
]
}
}
Start with a restrictive permissions setup and loosen as you build trust in how Claude Code uses each command.
💰 Free Deal: Claude Code is included with Claude Pro ($20/month, USD only as of March 2026). The free Claude.ai tier does not include Claude Code. For Indian developers, paying in USD via Wise, Revolut, or a foreign currency card is the most common approach.
Practical Workflow Example
Here is a typical Claude Code session for adding a new feature:
$ claude
> I need to add a user profile page. Show avatar, name, email, and join date.
The API endpoint GET /api/v1/users/{id} already exists.
[Claude Code reads your CLAUDE.md, understands your stack]
[Creates the profile page component]
[Adds the route in app/]
[Writes the data fetching logic using your patterns]
[Creates basic Playwright tests]
> /review-pr
[Invokes your custom review command, checks the changes]
[Reports: "No critical issues. Minor: add loading skeleton for slow connections"]
> Add a loading skeleton
[Claude Code implements the skeleton component following your Tailwind patterns]
Official Resources
- Claude Code Docs — Official documentation
- Claude.ai — Sign up for Claude Pro
- Anthropic API Keys — For API key users
- CLAUDE.md Examples — Community CLAUDE.md templates
- Claude Code GitHub — Open-source client
Community Questions
0No questions yet. Be the first to ask!