Claude Code is Anthropic's official command-line AI coding agent. It runs directly in your terminal, reads your codebase, edits files, runs commands, and manages Git — all guided by natural language. Unlike browser-based AI tools, Claude Code lives where developers already work: the shell.
This is a complete guide to getting started, mastering the core features, and building workflows that make Claude Code indispensable.
What Is Claude Code?
Claude Code is an agentic AI coding tool built on top of Claude — Anthropic's state-of-the-art language model. It's not an autocomplete plugin. It's an agent that can:
- Read and understand your entire codebase
- Edit multiple files in a single session
- Run shell commands, tests, and build scripts
- Manage Git (stage, commit, create branches)
- Search the web for documentation
- Call external APIs via MCP servers
Think of it as a senior engineer you can pair-program with via the command line — one with perfect recall of every file in your project.
Installation
Claude Code requires Node.js 18+ and an Anthropic API key.
# Install globally
npm install -g @anthropic-ai/claude-code
# Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."
# Start Claude Code in your project
cd your-project
claudeYou can also install the VS Code extension for integrated IDE support, or use Claude Code inside the claude.ai/code web app.
Your First Session
Once running, Claude Code opens an interactive REPL. Type in natural language:
> Add a rate-limiting middleware to my Express API.
Use express-rate-limit, 100 requests per 15 minutes per IP,
apply it to all /api/* routes, and return JSON errors.Claude Code will:
- Read your project structure
- Find your Express server file
- Check if
express-rate-limitis installed (and install it if not) - Write the middleware
- Apply it to the correct routes
- Show you a diff before saving
You approve or reject each change. Nothing is applied without your confirmation.
Slash Commands — The Power User Interface
Claude Code ships with built-in slash commands that trigger specific behaviors:
| Command | What it does |
|---|---|
/help | Show all available commands |
/clear | Clear conversation history |
/compact | Compress context to save tokens |
/review | Deep review of changed files |
/init | Generate a CLAUDE.md file for your project |
/memory | View and edit Claude's persistent memory |
/cost | Show token usage for this session |
/model | Switch between Claude models |
Custom Slash Commands
You can create your own slash commands as Markdown files inside .claude/commands/:
<!-- .claude/commands/pr-review.md -->
Review the staged changes as a strict code reviewer.
Check for: security issues, edge cases, missing tests,
performance regressions, and style consistency.
Output a prioritized list of issues with file:line references.Now /pr-review is available in every session.
CLAUDE.md — Project Memory
CLAUDE.md is a Markdown file at the root of your project that Claude Code reads at the start of every session. It's how you give Claude permanent context about your codebase.
# My Project — Claude Instructions
## Stack
- Next.js 15, TypeScript, Tailwind CSS
- PostgreSQL via Prisma
- Deployed on Railway
## Conventions
- Components: PascalCase, co-located .test.tsx files
- API routes: snake_case, always return { data, error }
- Never use `any` — use `unknown` and narrow
## DO NOT
- Modify the authentication middleware without asking
- Add dependencies without checking if a lighter alternative exists
- Use default exports for utilitiesWith a good CLAUDE.md, Claude Code understands your conventions without you repeating them.
Hooks — Automate Workflows
Hooks execute shell commands automatically in response to Claude Code events. Configure them in .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $CLAUDE_FILE_PATH"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "npm run typecheck"
}
]
}
]
}
}This example:
- Runs Prettier automatically every time Claude edits a file
- Runs TypeScript type checking when the session ends
Hooks can run any shell command — linters, test runners, formatters, notification scripts.
MCP Servers — Extend Claude's Capabilities
Model Context Protocol (MCP) lets Claude Code talk to external services. Anthropic and the community have built MCP servers for:
- Filesystem operations — advanced file manipulation
- GitHub — read PRs, issues, and repo metadata
- PostgreSQL / SQLite — query your database directly
- Puppeteer — control a browser for testing
- Google Drive — read documents
- Slack — send notifications
Configure MCP servers in ~/.claude.json:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
}
}
}
}Now Claude Code can read your GitHub issues and pull requests during a session:
> Look at issue #142 and implement the described feature.Real-World Workflows
Workflow 1: Feature From Ticket to PR
claude
> Read the GitHub issue #87.
Implement the described feature following our CLAUDE.md conventions.
Write unit tests. Then stage the changes and write a commit message.Claude Code reads the issue, implements it, writes tests, stages the diff, and suggests a commit message. Review, approve, push.
Workflow 2: Codebase Onboarding
claude
> Explain the architecture of this project.
How does data flow from the API to the database?
What are the most critical files I should understand first?Paste this into every new codebase you join. Claude Code reads the project structure and gives you a map.
Workflow 3: Automated Code Review
git diff main..HEAD | claude -p "Review this diff as a strict engineer.
Prioritize: security, correctness, edge cases.
Output: numbered list, severity HIGH/MEDIUM/LOW, file:line."Pipe git diffs directly into Claude Code for headless reviews.
Workflow 4: Legacy Code Modernization
claude
> Audit all files in /src/utils that are older than 2 years.
For each: identify deprecated patterns, propose modern alternatives,
and flag anything that might break in Node 22.Claude Code vs GitHub Copilot vs Cursor
| Feature | Claude Code | Copilot | Cursor |
|---|---|---|---|
| Lives in terminal | ✅ | ❌ | ❌ |
| Multi-file agent | ✅ | Partial | ✅ |
| Runs shell commands | ✅ | ❌ | Limited |
| MCP / extensions | ✅ | ❌ | ❌ |
| Custom hooks | ✅ | ❌ | ❌ |
| Works headlessly (CI) | ✅ | ❌ | ❌ |
| IDE integration | Plugin | Native | Native |
| Context window | 200K tokens | ~8K | ~20K |
Claude Code wins on agentic capability and context. Copilot and Cursor win on in-editor experience. Many developers use both.
Permission Modes
Claude Code asks for permission before running dangerous operations. You can configure trust levels:
{
"permissions": {
"allow": [
"Bash(npm run *)",
"Bash(git status)",
"Bash(git diff *)",
"Read(**)",
"Edit(src/**)"
],
"deny": [
"Bash(rm -rf *)",
"Bash(git push --force *)"
]
}
}This lets Claude run safe commands automatically while requiring confirmation for destructive operations.
Tips for Getting the Most from Claude Code
1. Write a great CLAUDE.md
Invest 30 minutes writing your project's CLAUDE.md. It pays back every session.
2. Use /compact on long sessions
When context grows large, /compact compresses history while preserving key decisions. This saves tokens and keeps responses fast.
3. Be specific about constraints
"Write a login form" → generic result
"Write a login form: TypeScript, React Hook Form, Zod validation, Tailwind CSS, no external UI library, handle loading and error states" → production-ready result
4. Use headless mode for automation
claude -p "Run the test suite and summarize failures" --no-interactiveIntegrate Claude Code into CI pipelines for automated review gates.
5. Iterate, don't restart
Claude Code remembers the full session. If the first implementation isn't right, say "The rate limiting isn't applying to the /api/auth routes — fix that" rather than starting over.
Security Considerations
- Claude Code runs in your local environment with your filesystem access
- Review every file edit before approving
- Never share your
ANTHROPIC_API_KEYin project files — use environment variables - Use the
denypermission list to block destructive operations - For sensitive repos, review the Anthropic privacy policy
Getting Started Today
- Install:
npm install -g @anthropic-ai/claude-code - Get an API key at console.anthropic.com
- Run
/initin your project to generate a starterCLAUDE.md - Read the official Claude Code documentation
Claude Code is the most powerful AI tool in a developer's terminal. The learning curve is gentle — and the productivity gains compound every week.