Claude Code Setup Guide: AI-Powered CLI for Developers
On this page
TL;DR: Claude Code at a Glance
Claude Code is Anthropic's official agentic coding tool that runs directly in your terminal. It reads your codebase, edits files, runs shell commands, and manages git workflows — all through natural language. Unlike autocomplete-style tools, Claude Code operates as an autonomous coding agent that can reason through multi-step tasks across your entire project.
What Is Claude Code? (And Why You Might Need It)
Claude Code is a command-line tool that brings Claude's reasoning capabilities directly into your development workflow. Powered by Claude Sonnet 4 and Claude Opus 4, it acts as an AI pair programmer that understands your full codebase context.
What makes it different from IDE extensions like Copilot or Cursor:
- Agentic execution — Claude Code doesn't just suggest code. It reads files, writes changes, runs terminal commands, creates commits, and executes multi-step plans autonomously.
- Full codebase context — It indexes your project and understands relationships across files, not just the file you're editing.
- Terminal-native — No IDE dependency. Works in any terminal, on any machine, over SSH.
- Tool use — Claude Code has built-in tools for file reading, editing, glob search, grep, and bash execution. It decides which tools to use based on your request.
Installation and Initial Setup
Prerequisites
You'll need:
- macOS, Linux, or Windows (WSL2 required for Windows)
- Node.js 18+ (check with
node -v) - An Anthropic API key or a Claude Max/Team/Enterprise subscription
- A terminal — that's it
Step 1: Install via npm
npm install -g @anthropic-ai/claude-code
Verify installation:
claude --version
Note: The CLI command is claude, not claude-code.
Step 2: Authentication
Claude Code supports two authentication methods:
Option A: API Key (pay-per-use)
Set the ANTHROPIC_API_KEY environment variable:
# For zsh (macOS default)
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.zshrc
source ~/.zshrc
# For bash
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
source ~/.bashrc
Get your API key from console.anthropic.com.
Option B: Claude Max Subscription (flat rate)
If you have a Claude Max, Team, or Enterprise subscription, Claude Code is included. Run claude and follow the OAuth login flow — no API key needed.
Step 3: Launch
Navigate to your project directory and start Claude Code:
cd /path/to/your/project
claude
That's it. Claude Code opens an interactive session where you type natural language requests. There's no separate chat subcommand — just claude.
How Claude Code Works
When you launch claude in a project directory, it:
- Reads your project structure — understands the file tree, recognizes frameworks
- Loads CLAUDE.md files — project-specific instructions (more on this below)
- Opens an interactive session — you type requests in natural language
- Uses tools autonomously — reads files, edits code, runs commands, searches your codebase
Example session:
$ claude
> Find all API routes that don't have error handling and add try-catch blocks
Claude will:
- Search for API route files using glob/grep
- Read each file
- Identify routes missing error handling
- Edit each file to add proper try-catch blocks
- Show you a summary of changes
You can also pass a one-shot prompt:
claude -p "Explain the authentication flow in this project"
The -p flag runs a single prompt and exits — useful for scripting and CI/CD.
Configuration with CLAUDE.md
Claude Code uses CLAUDE.md files for project-specific instructions and context. This is the primary configuration mechanism — there is no JSON config file.
Where to Place CLAUDE.md
- Project root (
./CLAUDE.md) — loaded automatically when you runclaudein the directory - Subdirectories — loaded when Claude reads files in that directory
- Home directory (
~/.claude/CLAUDE.md) — global instructions applied to all projects - User-level per-project (
.claude/CLAUDE.md) — gitignored personal preferences
What to Put in CLAUDE.md
# Project Instructions
## Tech Stack
- Next.js 14 with App Router
- TypeScript in strict mode
- Tailwind CSS for styling
- PostgreSQL with Prisma ORM
## Conventions
- Use server components by default
- All API routes must include error handling
- Use absolute imports with @ prefix
- Write JSDoc for all exported functions
## Commands
- Dev server: npm run dev
- Build: npm run build
- Test: npm run test
- Deploy: ./deploy.sh
Claude Code reads this context at the start of every session, ensuring consistent behavior across your team.
Essential Slash Commands
Inside an interactive Claude Code session, these slash commands are available:
/init— Generate a CLAUDE.md file for your project by analyzing the codebase/compact— Compress conversation history to free up context window/cost— Show token usage and cost for the current session/help— Show all available commands/clear— Clear conversation history and start fresh/model— Switch between Claude models mid-session
Real-World Workflows
Code Editing and Refactoring
> Refactor the UserService class to use dependency injection instead of direct database calls
Claude Code will read the relevant files, plan the refactoring, make the edits, and verify the changes compile. It uses a diff-based editing approach — you see exactly what changed.
Bug Fixing
> The /api/orders endpoint returns 500 when the cart is empty. Fix it.
Claude Code will trace the issue through the codebase, identify the root cause, apply a fix, and often suggest adding a test case.
Git Workflows
Claude Code has deep git integration:
> Create a commit for the changes we just made with a descriptive message
> Show me what changed since yesterday
> Create a new branch called feature/user-auth and switch to it
Running Commands
Claude Code can execute shell commands as part of its workflow:
> Run the test suite and fix any failing tests
> Install axios and refactor the fetch calls to use it
> Check if there are any TypeScript errors and fix them
Multi-File Operations
> Add proper TypeScript types to all files in src/utils/
> Update all imports to use the new package name after the rename
> Add error boundaries to all page components
Pricing
Claude Code pricing depends on your authentication method:
API Key (pay-per-use)
You pay standard Anthropic API rates based on tokens consumed:
- Claude Sonnet 4 — $3 per million input tokens, $15 per million output tokens
- Claude Opus 4 — $15 per million input tokens, $75 per million output tokens
Most coding sessions use Sonnet 4 by default. A typical hour of active coding costs $1-5, depending on codebase size and request complexity. Heavy sessions with large codebases can cost more.
Claude Max Subscription (flat rate)
Claude Max plans include Claude Code usage:
- Max 5x — $100/month (5x the standard usage)
- Max 20x — $200/month (20x the standard usage)
For developers who use Claude Code daily, a Max subscription is typically more cost-effective than API pay-per-use.
Claude Code vs. Other AI Tools
Use Claude Code when you want:
- An autonomous agent that reads, writes, and executes — not just suggests
- Multi-file refactoring with full project context
- Terminal-native workflows without IDE lock-in
- Git integration and command execution built in
- Deep reasoning about architecture and design
Use Cursor when you want:
- Real-time inline autocomplete while typing
- IDE-integrated experience with visual diff review
- Tab-completion style suggestions
Use GitHub Copilot when you want:
- Lightweight autocomplete in VS Code/JetBrains
- Minimal setup, predictable pricing
- Team-wide rollout with enterprise features
Claude Code is strongest when the task requires reasoning across multiple files and executing a multi-step plan. Autocomplete tools are better for rapid line-by-line coding.
Advanced Features
MCP (Model Context Protocol) Support
Claude Code supports MCP servers, which extend its capabilities with custom tools. You can connect it to databases, APIs, browsers, and more:
// .claude/mcp.json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}
}
}
With MCP, Claude Code can query your database, browse the web, or interact with any service that has an MCP server.
Headless Mode for CI/CD
Use the -p flag with --output-format json for scripted automation:
claude -p "Are there any security issues in src/auth/?" --output-format json
This is useful in CI pipelines for automated code review, pre-merge checks, or documentation generation.
Custom Slash Commands
Create project-specific commands by adding markdown files in .claude/commands/:
<!-- .claude/commands/review.md -->
Review the changes in the current git diff. Check for:
1. Security issues
2. Performance problems
3. Missing error handling
4. TypeScript type safety
Then use it with /project:review in your session.
Permission Modes
Claude Code offers three permission modes to control how much autonomy it has:
- Default — Asks permission before file writes and command execution
- Auto-accept edits — File edits are applied automatically, commands still need approval
- Full auto (YOLO mode) — Everything runs without asking. Use with caution. Enabled with
--dangerously-skip-permissions
Common Pitfalls and Solutions
Context Window Limits
Problem: Long sessions slow down as conversation history grows.
Fix: Use /compact to compress the conversation. Claude Code summarizes the history and frees up context for new work. For very long sessions, consider starting fresh with /clear.
Large Codebases
Problem: Indexing takes time on repos with thousands of files.
Fix: Create a .claudeignore file (same syntax as .gitignore) to exclude directories Claude doesn't need:
node_modules/
dist/
.next/
coverage/
*.min.js
Unexpected File Edits
Problem: Claude Code edited a file you didn't want changed.
Fix: Claude Code uses git-aware editing. If you're in a git repo, you can always git checkout -- <file> to revert. Run in default permission mode (not YOLO) to approve edits before they're applied.
Best Practices
-
Start with
/init— Let Claude Code generate a CLAUDE.md for your project. It analyzes your codebase and creates useful context. -
Be specific in requests — "Fix the bug in the login flow" is better than "Fix bugs." Give Claude Code enough context to narrow scope.
-
Use
/compactregularly — Long sessions accumulate context. Compacting keeps responses fast and focused. -
Review changes before committing — Claude Code shows you diffs. Read them. The tool is powerful but not infallible.
-
Combine with your existing workflow — Claude Code works alongside linters, type checkers, and test suites. Use it to fix the issues those tools find.
-
Leverage CLAUDE.md — The more context you put in CLAUDE.md, the better Claude Code understands your project conventions and constraints.
Summary
Claude Code is a terminal-native AI coding agent that goes beyond autocomplete. It reads your codebase, reasons about architecture, edits files, runs commands, and manages git — all through natural language. Whether you're refactoring legacy code, debugging production issues, or building new features, Claude Code handles multi-step tasks that would take significant manual effort.
The setup is straightforward: install via npm, authenticate, and run claude in your project directory. Configuration lives in CLAUDE.md files, not obscure JSON configs. The tool is production-ready and actively maintained by Anthropic.
Sources
- Claude Code Overview — Anthropic Docs
- Claude Code CLI Usage — Anthropic Docs
- CLAUDE.md Configuration — Anthropic Docs
- Claude Pricing — Anthropic
- Model Context Protocol — Anthropic
- Claude Code GitHub Repository
Questions about Claude Code? Drop a message. I'm @mervcodes.
Related Articles
How to Set Up GitHub Actions for CI/CD (Beginner-Friendly Guide)
Learn how to set up GitHub Actions for CI/CD pipelines — from your first workflow file to automated deployments with real YAML examples.
Running Local LLMs With Ollama: Developer Setup Guide
Set up Ollama to run local LLMs on your machine. Covers installation, model selection, API usage, and integrating local models into your dev workflow.
Python Virtual Environments Explained: venv vs conda vs pyenv
A practical comparison of Python's venv, conda, and pyenv — when to use each, how to set them up, and which one fits your workflow.