Claude Code Complete Guide
A step-by-step guide to mastering Claude Code. Written for developers coming from Kilo Code, Kiro.dev, or Antigravity.
Installation
Step 1: Install Claude Code
Requires Node.js 18+. This installs the claude command globally.
Step 2: Navigate to Your Project & Launch
On first run, your browser opens for Anthropic authentication. Log in with your Claude Pro account.
Step 3: Verify Installation
Should show version 2.1.x or higher. Update anytime with: npm update -g @anthropic-ai/claude-code
CLAUDE.md Memory = Workspace Rules
CLAUDE.md files are your "workspace rules" — they provide persistent context that Claude reads at the start of every session. Think of them like .kilorc or .kiro/rules.
Create Your Project CLAUDE.md
Run this command inside Claude Code to auto-generate a starter file:
This creates a CLAUDE.md in your project root with basic project info.
Memory Hierarchy
Claude reads these files in order (later files override earlier ones):
~/.claude/CLAUDE.md
→ Global: Your personal preferences across all projects (coding style, preferred libraries, etc.)
./CLAUDE.md
→ Project: Project-specific context. Commit this to git! Your team can share it.
./src/CLAUDE.md
→ Subdirectory: Overrides for specific folders (e.g., different rules for frontend vs backend).
Example CLAUDE.md Template
# Project: My Awesome App
## Tech Stack
- Language: TypeScript (strict mode)
- Framework: Next.js 14 with App Router
- Database: PostgreSQL + Prisma
- Testing: Vitest for unit, Playwright for E2E
## Project Structure
src/
├── app/ # Next.js app router pages
├── components/ # React components
├── lib/ # Shared utilities
└── server/ # API routes and server logic
## Code Conventions
- Use functional components with hooks
- Prefer `type` over `interface` for TypeScript
- Use absolute imports with @/ prefix
- Co-locate test files with source (.test.ts)
## Common Commands
- `pnpm dev` - Start development server
- `pnpm test` - Run unit tests
- `pnpm lint` - Run ESLint + Prettier
- `pnpm build` - Production build
## Important Notes
- Auth uses NextAuth with GitHub provider
- All API routes need rate limiting middleware
- Images served via Cloudinary CDN
## Do NOT
- Use `any` type without a comment explaining why
- Push directly to main branch
- Skip tests before committing
- Use npm (we use pnpm)
/memory to add something to CLAUDE.md. Example: "Remember that we use Zod for validation" — Claude will append it automatically.
MCP Servers
MCP (Model Context Protocol) servers extend Claude's capabilities by connecting to external services like databases, APIs, and tools. They're similar to IDE extensions.
Step 1: Create Settings File
Create .claude/settings.json in your project (or ~/.claude/settings.json for global):
Recommended MCP Configuration
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@context7/mcp-server"],
"description": "Live documentation lookup for libraries"
},
"filesystem": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-filesystem", "."],
"description": "Enhanced file system access"
},
"github": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-github"],
"env": {
"GITHUB_TOKEN": "ghp_your_token_here"
},
"description": "GitHub issue and PR management"
}
}
}
Replace ghp_your_token_here with your GitHub personal access token.
Step 2: Verify MCP Servers
Inside Claude Code, check which servers are loaded:
Popular MCP Servers
Live documentation lookup
Issues, PRs, repos
Database queries
Web search
Extensions
VS Code Extension
Deep IDE integration- Open VS Code Extensions panel (Cmd+Shift+X)
- Search for "Claude Code"
- Install the official Anthropic extension
- The extension auto-connects when you run
claudein terminal
What it does: View diffs inline, cherry-pick individual changes, jump to files Claude mentions, see LSP diagnostics.
Chrome Extension
Browser control & visual testing- Install "Claude Code" from Chrome Web Store
- In Claude Code terminal, run:
- Select "Enabled by default: Yes" when prompted
What it does: Claude can navigate websites, click buttons, fill forms, take screenshots for UI analysis, and manage multiple tabs.
Custom Slash Commands
Custom commands are reusable prompt templates you invoke with /project:command-name (project-level) or /user:command-name (global). They save you from typing repetitive instructions and ensure consistency across your workflow.
What Custom Commands Are Good For
- Git workflows — Commit with conventions, create PRs, update branches
- Code review — Review staged changes before committing
- Documentation — Generate API docs, README updates, changelogs
- Testing — Run tests, generate test cases, analyze coverage
- Refactoring — Apply consistent transformations across files
Step-by-Step: Create Your First Custom Command
Create the commands directory
Open your terminal and navigate to your project root:
For global commands (available across all projects): mkdir -p ~/.claude/commands
Create a markdown file for your command
The filename becomes the command name (without .md):
This creates a command you'll invoke as /project:git-push
Write your prompt instructions
Open the file in your editor and write clear, specific instructions. The entire file content is sent to Claude when you invoke the command.
Tips for writing good command prompts:
- • Be specific about what you want Claude to do
- • Include any formatting requirements
- • Specify which files to check or tools to use
- • Add constraints (e.g., "don't modify production code")
Use your command in Claude Code
Start typing / and your commands appear in the autocomplete menu:
Claude reads your command file and executes the instructions immediately.
Command Scope: Project vs Global
Location: .claude/commands/
Invoke with: /project:name
Best for: Project-specific workflows. Commit these to git so your team can use them.
Location: ~/.claude/commands/
Invoke with: /user:name
Best for: Personal workflows you use across all projects (e.g., your preferred git commit style).
Using Arguments in Commands
Use $ARGUMENTS in your command file to accept dynamic input when invoking the command.
Example command file: .claude/commands/fix-issue.md
Look up GitHub issue #$ARGUMENTS in this repository.
Read the issue description and any comments.
Then implement a fix for the issue:
1. Understand what's broken
2. Find the relevant code
3. Make the minimal change needed to fix it
4. Run tests to verify the fix
Usage:
/project:fix-issue 123 — the "123" replaces $ARGUMENTS in the prompt.
Recommended Starter Commands
Copy these to your .claude/commands/ directory to get started:
git-push.md — Smart commit and push
File: .claude/commands/git-push.md
Check the current git status and diff of staged changes.
Based on the changes, create a commit message following conventional commits format:
- feat: for new features
- fix: for bug fixes
- docs: for documentation
- refactor: for code refactoring
- test: for adding tests
- chore: for maintenance tasks
The commit message should be concise but descriptive.
Include a body if the changes are complex.
Then commit the changes and push to the current branch.
If the remote branch doesn't exist, create it with --set-upstream.
Usage: Stage your changes with git add, then run /project:git-push
pr.md — Create pull request
File: .claude/commands/pr.md
Create a pull request for the current branch.
Steps:
1. Run `git status` to see what branch we're on
2. Get the list of commits not yet in main: `git log main..HEAD --oneline`
3. Generate a clear PR title from the branch name and commits
4. Write a comprehensive description with:
- ## What Changed (summary of commits)
- ## Why (infer motivation from commit messages and code)
- ## How to Test (suggest specific test steps)
- ## Screenshots (if UI changes, remind to add them)
5. Use `gh pr create` with the title and body
If gh CLI is not installed, tell me how to install it with:
`brew install gh` and `gh auth login`
Usage: After pushing your branch, run /project:pr
review.md — Pre-commit code review
File: .claude/commands/review.md
Review the staged changes (run `git diff --cached`) for issues:
## Review Checklist
### 🐛 Bugs & Logic Errors
- Incorrect logic, off-by-one errors
- Missing null/undefined checks
- Unhandled edge cases
- Race conditions
### 🔒 Security Issues
- SQL injection vulnerabilities
- XSS attack vectors
- Hardcoded secrets or API keys
- Missing authentication/authorization checks
- Insecure data handling
### ⚡ Performance
- N+1 query problems
- Unnecessary loops or iterations
- Memory leaks
- Missing indexes for database queries
### 📝 Code Quality
- Poor naming that obscures intent
- Dead or unreachable code
- Missing error handling
- Violations of project conventions
## Output Format
For each issue found:
📍 **File:line** — Brief description
↳ Suggested fix
Only report REAL issues. Don't flag style preferences or nitpicks.
If everything looks good, say so briefly.
Usage: Stage changes, run /project:review, then fix issues before committing
test-gen.md — Generate tests for a file
File: .claude/commands/test-gen.md
Generate comprehensive tests for: $ARGUMENTS
Steps:
1. Read and understand the file's code
2. Identify all public functions/methods/exports
3. For each function, generate tests covering:
- Happy path (normal expected usage)
- Edge cases (empty inputs, boundaries, null/undefined)
- Error cases (invalid inputs, failure modes)
Use the testing framework already in the project (check package.json).
Co-locate test files with the source (e.g., utils.ts → utils.test.ts).
Follow existing test patterns in the codebase if any exist.
Write clear test descriptions that explain what's being tested.
Usage: /project:test-gen src/utils/validation.ts
/project:review to check your code, fix any issues, then /project:git-push to commit.
Sub-Agents
Sub-agents are specialized AI assistants that run in isolated contexts with their own tool permissions. Think of them as "expert consultants" Claude can delegate to — perfect for code review, security audits, or any task where you want focused expertise without cluttering your main conversation.
When to Use Sub-Agents
- Code review — A reviewer sub-agent examines changes in isolation, then reports findings back to your main session
- Security audits — Give a security-focused agent read-only access to scan for vulnerabilities
- Research tasks — Send an agent to gather information while you continue coding
- Parallel work — Run multiple agents on different tasks (with Ctrl+B for background)
Sub-Agent Benefits
Sub-agent conversations are separate from your main session. No context pollution.
Give agents only the tools they need. Read-only agents can't accidentally modify code.
Custom system prompts make agents experts in specific tasks.
Commit agents to git. Your whole team benefits from the same specialized assistants.
Method 1: Create Sub-Agent via UI (Recommended for Beginners)
Open the Agents Manager
In Claude Code, run:
Create a New Agent
Select "Create New Agent" from the menu. Choose where to save it:
- • Project-level — Saved in
.claude/agents/, shared with team via git - • User-level — Saved in
~/.claude/agents/, available across all your projects
Describe the Agent's Purpose
Tell Claude what you want this agent to do. Example: "A code reviewer that checks for security issues, performance problems, and bugs."
Claude generates an initial system prompt and tool configuration.
Configure Tool Access
Choose which tools the agent can use:
Read, Grep, Glob
Read-only (safe for review)
Read, Write, Edit, Bash
Full access (for implementation)
Edit and Save
Press e to edit the system prompt if you want to refine it. Then save.
Method 2: Create Sub-Agent Manually (More Control)
Create the agents directory
Create a markdown file for your agent
The filename (without .md) becomes the agent's name.
Write the agent definition
Use YAML frontmatter + markdown instructions (see template below)
Sub-Agent Template
File: .claude/agents/your-agent-name.md
---
name: your-agent-name
description: One-line description shown in agent list
tools: Read, Grep, Glob
---
# Agent Role
Describe who this agent is and their expertise.
Example: "You are a senior security engineer specializing in web application security."
# Task Instructions
Explain what the agent should do when invoked:
1. First, do this...
2. Then check for...
3. Finally, report...
# Output Format
Specify how findings should be formatted:
- Use bullet points for issues
- Include file paths and line numbers
- Provide severity levels
# Constraints
List any limitations:
- Don't suggest changes outside scope of review
- Focus only on security issues, not style
How to Invoke a Sub-Agent
There are two ways to use sub-agents:
Option 1: Explicit Request
Ask Claude to use a specific agent:
Option 2: Automatic Delegation
Claude automatically recognizes when a task matches an agent's description and may suggest delegating to it. You can approve or decline.
Option 3: Background Execution
Run an agent in the background while you continue working:
Press Ctrl+B to send to background. Results appear when ready.
Tool Permissions Reference
Common tool combinations for different agent types:
Can't modify files
Read, Grep, Glob
Read code + web search
Read, Grep, Glob, WebFetch
Full code access
Read, Write, Edit, Bash, Glob, Grep
Read code + write docs
Read, Write, Edit, Glob, Grep
Recommended Sub-Agents to Install
code-reviewer.md
---
name: code-reviewer
description: Reviews code for bugs, security issues, and best practices
tools: Read, Grep, Glob
---
You are a senior code reviewer with 10+ years of experience.
# When Invoked
Review the specified code or changes (git diff --cached for staged changes).
# Review Focus Areas
1. **Bugs** — Logic errors, off-by-one, null checks, race conditions
2. **Security** — Injection, XSS, secrets, auth issues
3. **Performance** — N+1 queries, memory leaks, unnecessary work
4. **Maintainability** — Clear naming, proper error handling
# Output Format
For each issue:
📍 **file:line** — Brief problem description
Severity: 🔴 Critical | 🟡 Warning | 🔵 Suggestion
Fix: How to resolve
If code looks good, say "✅ No issues found" with brief summary.
security-auditor.md
---
name: security-auditor
description: Scans code for security vulnerabilities and hardcoded secrets
tools: Read, Grep, Glob
---
You are a security engineer specializing in application security.
# When Invoked
Scan the specified directory or files for security issues.
# Security Checks
1. **Secrets** — API keys, passwords, tokens in code
2. **Injection** — SQL injection, command injection, XSS
3. **Authentication** — Weak auth, missing checks, session issues
4. **Authorization** — Privilege escalation, IDOR vulnerabilities
5. **Data Exposure** — Sensitive data in logs, error messages
6. **Dependencies** — Known vulnerable packages (check package.json)
# Output Format
## 🔴 Critical Issues (fix immediately)
- Issue description with file:line
- Exploitation scenario
- Remediation steps
## 🟡 Warnings (should fix)
...
## 🔵 Recommendations (nice to have)
...
doc-writer.md
---
name: doc-writer
description: Generates documentation for code and APIs
tools: Read, Write, Edit, Glob, Grep
---
You are a technical writer who creates clear, comprehensive documentation.
# When Invoked
Generate or update documentation for the specified code.
# Documentation Types
- **JSDoc/TSDoc** — Add inline documentation to functions/classes
- **README** — Project overview, setup instructions, examples
- **API Docs** — Endpoint documentation with request/response examples
- **Architecture** — System design and component relationships
# Style Guidelines
- Use clear, concise language
- Include code examples for complex concepts
- Add "Quick Start" sections where appropriate
- Keep paragraphs short (3-4 sentences max)
# Output
Create/update documentation files in appropriate locations.
For inline docs, edit source files directly.
.claude/agents/ folder.
Skills
Skills are reusable "how-to" guides that teach Claude specific tasks. Unlike sub-agents (which run in isolation), skills extend Claude's main capabilities — think of them as plugins that Claude loads on-demand when your task matches.
Skills vs MCP Servers vs Sub-Agents — When to Use What?
| Feature | Skills | MCP Servers | Sub-Agents |
|---|---|---|---|
| Best for | Task workflows & file generation | Connecting to external systems | Isolated specialized tasks |
| Examples | Create PDFs, generate components, TDD workflow | Query database, GitHub API, web search | Code review, security audit |
| Context | Runs in main conversation | Always available as tools | Isolated (separate context) |
| Can run scripts? | Yes (Python/Node.js helpers) | Yes (server-side) | Uses Claude's tools |
| When loaded | Auto when task matches description | Always running in background | When explicitly invoked |
Do you need MCP Servers if using Skills?
They serve different purposes and work great together:
- • Skills alone: Great for task workflows, file generation, coding patterns
- • MCP alone: Great for connecting to databases, APIs, external services
- • Both together: Skills can use MCP servers (e.g., a "deploy" skill that uses GitHub MCP)
What Skills Are Good For
- Document generation — Create PDFs, Word docs, Excel files, PowerPoint presentations
- Coding patterns — TDD workflow, component generators, API scaffolding
- Complex multi-step tasks — Deployment pipelines, release workflows
- Domain expertise — Financial calculations, scientific formulas, legal document formatting
Step-by-Step: Create Your First Skill
Create the skill directory
Each skill lives in its own folder inside .claude/skills/:
The folder name is your skill's identifier.
Create the SKILL.md file
This is the main file Claude reads to understand the skill:
Write the skill definition
Open SKILL.md and add:
- • YAML frontmatter — Name, description, and optional metadata
- • When to Use — Keywords/phrases that trigger this skill
- • How It Works — Step-by-step instructions for Claude
- • Output Format — What the skill should produce
(Optional) Add helper scripts
For skills that need to run code (e.g., PDF generation):
Add Python or Node.js scripts here. Claude can execute them when using the skill.
Use the skill
Skills activate automatically when your request matches the skill's description. Just ask Claude to do something that matches — e.g., "Generate API documentation" will trigger an api-docs skill.
Skill Folder Structure
SKILL.md Template
---
name: skill-name
description: Brief description shown when Claude scans available skills
---
# Skill Name
Extended description of what this skill does.
## When to Use
Activate this skill when the user asks to:
- First matching phrase
- Second matching phrase
- Third matching phrase
## Prerequisites
List any requirements:
- Required npm packages: `package1`, `package2`
- Required Python packages: `package1`
- Environment variables: `API_KEY`
## How It Works
Step-by-step instructions Claude follows:
1. First, gather information by...
2. Then, process the data by...
3. Finally, generate output by...
## Output Format
Describe what the skill produces:
- File format and location
- Structure and content
- Validation criteria
## Examples
### Example 1: Basic Usage
Input: "Create a component called UserCard"
Output: Creates `src/components/UserCard.tsx`
### Example 2: Advanced Usage
Input: "Create a form component with validation"
Output: Creates component with Zod schema
How Skills Load (Progressive Disclosure)
Skills use a smart loading system to minimize context usage:
tokens
Stage 1: Scan
Claude reads only skill names and descriptions to find matches
tokens
Stage 2: Load
Full SKILL.md instructions load only when skill activates
Stage 3: Execute
Scripts, templates, and resources load only when needed
This means you can have dozens of skills installed without impacting performance.
Installing Community Skills
Method 1: Clone from GitHub
Clone a skill repo directly into your skills folder:
Method 2: Manual Copy
Download the skill folder and copy it to .claude/skills/
Recommended Skills to Install
🦸 Superpowers
The most popular community skill pack
20+ battle-tested skills including:
📄 Official Anthropic Skills
First-party skills from Anthropic
Document handling and more:
Hooks
Hooks let you run custom scripts at specific points in Claude's workflow — like auto-formatting files after edits or running lint before commits.
How to Configure Hooks
Add a hooks section to your .claude/settings.json:
Example Hooks Configuration
{
"hooks": {
"postFileWrite": [
{
"pattern": "*.ts",
"command": "npx prettier --write $FILE"
},
{
"pattern": "*.tsx",
"command": "npx prettier --write $FILE"
}
],
"preCommit": [
{
"command": "npm run lint"
},
{
"command": "npm run test -- --run"
}
]
}
}
Available Hook Types
postFileWrite
— Runs after Claude writes/edits a file. Use $FILE for the file path.
preCommit
— Runs before Claude creates a git commit.
postToolCall
— Runs after Claude uses a tool. Great for notifications.
Boris Cherny's Workflow Creator's Method
Boris Cherny is the creator of Claude Code. Here's his recommended daily workflow:
Categorize Your Task
Before starting, decide if this is an Easy, Medium, or Hard task (see Task Tiers below). This determines which tool to use.
Enable Plan Mode for Medium+ Tasks
Press Shift + Tab before entering your prompt. This makes Claude think through the approach before writing code.
Workshop the Plan
Don't accept the first plan. Ask Claude to refine it, consider edge cases, or suggest alternatives. Get the plan right before any code is written.
Execute & Clear After Milestones
After completing a significant chunk of work, use /clear to reset context. Claude will re-read CLAUDE.md and stay sharp.
Update Memory with Learnings
When you discover something important about the project, use /memory to save it to CLAUDE.md for future sessions.
Task Tiers Strategy
Match the right approach to your task complexity. This dramatically improves success rates.
Easy Tasks — One-Shot
Bug fixes, documentation updates, small refactors, dependency updates.
Best Tool: Use @claude mention on GitHub Issues/PRs. Claude handles it automatically without you opening the terminal.
Medium Tasks — Plan + Execute
New features, API integrations, component rewrites, adding tests.
Approach: Enable Shift+Tab Plan Mode → Workshop the plan → Execute. Success rate jumps from 20-30% to 70-80%.
Hard Tasks — Multi-Phase
Architecture changes, greenfield projects, major migrations, complex systems.
Approach: Create a spec.md with phases → Use Plan Mode to refine each phase → Execute phase-by-phase with /clear between phases.
Plan Mode = Spec-Driven Dev
Plan Mode is like the spec-driven development you know from Kiro.dev. It forces Claude to think through the problem before writing any code.
How to Use Plan Mode
When enabled, Claude will outline its approach, break down the task into steps, identify potential issues, and ask for your approval before writing code.
Usage Tracking Like Antigravity Cockpit
Built-in Usage Commands
/cost
View current session token usage
/usage
Detailed breakdown by model
Community Usage Tools
- • Use
/clearafter milestones to reset context - • Use
/compactto summarize long conversations - • Use
/model sonnetfor simple tasks (cheaper) - • Spawn sub-agents for code review (separate context)
- • Batch related tasks in single sessions
Model Selection
opus
Default for Pro
Best for complex reasoning, architecture decisions, multi-file refactors. Use this for hard tasks.
sonnet
Faster, lower cost
Great for everyday coding, simple features, quick fixes. Good balance of speed and capability.
haiku
Fastest
Best for quick questions, code explanations, simple edits. Very fast responses.
Keyboard Shortcuts
| Shift + Tab | Toggle Plan Mode |
| Shift + Enter | Multi-line input |
| Esc | Cancel current operation |
| Ctrl + C | Interrupt & get partial results |
| Ctrl + B | Background current task (async) |
!command |
Run bash command (output feeds into context) |
Built-in Slash Commands
/init |
Create CLAUDE.md file |
/model |
Switch models (opus/sonnet/haiku) |
/clear |
Reset context (keeps CLAUDE.md) |
/compact |
Summarize long conversation |
/cost |
Show session usage |
/memory |
Save something to CLAUDE.md |
/agents |
Manage sub-agents |
/mcp |
Manage MCP servers |
/chrome |
Enable browser control |
/permissions |
View/set tool permissions |
/help |
Show all available commands |
IDE Agent Mapping
Quick translation from your existing IDE agent concepts:
| Concept | Kilo/Kiro/Antigravity | Claude Code |
|---|---|---|
| Workspace Rules | .kilorc, .kiro/rules |
CLAUDE.md |
| Global Rules | Settings/Config | ~/.claude/CLAUDE.md |
| Spec-Driven Dev | Kiro specs, PRDs | Plan Mode (Shift+Tab) |
| MCP Servers | Extension settings | .claude/settings.json |
| Usage Tracking | Antigravity Cockpit | /cost, ccflare |
| Background Tasks | N/A | Ctrl+B, sub-agents |
| Reusable Plugins | Extensions | .claude/skills/ |
Resources
Official Documentation
Anthropic's comprehensive Claude Code docs
Awesome Claude Code
Curated list of commands, tools, CLAUDE.md files
Awesome Claude Skills
Official & community skills collection
Awesome Sub-Agents
100+ specialized sub-agents by category
Claude Squad
Manage multiple Claude instances in parallel