MervCodes

Tech Reviews From A Programmer

Claude Code Setup Guide: AI-Powered CLI for Developers

8 min read

TL;DR: Claude Code at a Glance

Claude Code is Anthropic's CLI tool that brings Claude 3.5 Sonnet's code capabilities directly to your terminal. Setup takes 5 minutes, costs $0.80-$3/month for most developers, and integrates seamlessly with your existing editor and git workflow. It's best for refactoring, architectural reviews, and batch processing multiple files — less ideal for real-time IDE autocompletion compared to Cursor or Copilot.


What Is Claude Code? (And Why You Might Need It)

Claude Code is a command-line interface that pipes your codebase into Claude 3.5 Sonnet, Anthropic's strongest model for reasoning through code problems. Unlike IDE extensions that intercept keystrokes, Claude Code operates on explicit requests — you ask it to refactor a function, analyze a bug, or generate documentation, and it returns results you can review before applying.

The core advantage: Claude Code handles multi-file context better than most competitors, maintaining understanding across 20-30 files in a single conversation. If you're managing a Node.js microservice, refactoring a legacy React component, or reviewing architectural changes, Claude Code can see the full picture without losing context.


Installation and Initial Setup

Prerequisites

You'll need:

  • macOS, Linux, or Windows (WSL2 recommended for Windows)
  • Node.js 18+ (check with node -v)
  • An Anthropic API key (get one free at console.anthropic.com)
  • 5 minutes and a terminal

Step 1: Install via npm

npm install -g @anthropic-ai/claude-code

Or if you prefer yarn:

yarn global add @anthropic-ai/claude-code

Verify installation:

claude-code --version

Step 2: Configure Your API Key

Claude Code reads your API key from the ANTHROPIC_API_KEY environment variable. Add it to your shell profile:

For macOS/Linux (bash):

echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
source ~/.bashrc

For macOS (zsh):

echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.zshrc
source ~/.zshrc

For Windows (PowerShell):

[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "User")

Then restart your terminal.

Test the connection:

claude-code --test

Core Commands and Workflows

Interactive Chat Mode

Start a conversation with your codebase:

cd /path/to/project
claude-code chat

This opens an interactive REPL where you can ask questions about your code. Claude maintains conversation history, so context compounds across messages.

Example session:

$ claude-code chat
Claude Code CLI v1.2.0
Type 'exit' to quit, 'help' for commands.

> Analyze src/api/users.js for N+1 query problems
[Claude analyzes file and explains the issue...]

> Show me how to fix this with a database transaction
[Claude generates refactored code...]

> Generate unit tests for the fixed version
[Claude writes comprehensive tests...]

> exit

Analyze a Single File

claude-code analyze src/middleware/auth.ts

Claude returns:

  • Security concerns
  • Performance bottlenecks
  • Dead code or unused variables
  • Architectural recommendations

Refactor with Constraints

claude-code refactor src/components/Dashboard.jsx --constraint "Keep React hooks only, no class components" --output refactored.jsx

The --output flag saves Claude's suggestion without overwriting your original.

Batch Process Multiple Files

For processing an entire directory:

claude-code batch --input src/ --task "Add JSDoc comments to all exports" --output docs/

Claude processes each file and saves annotated versions.


Real-World Setup Example: Node.js Project

Let's walk through setting up Claude Code in a typical Node.js monorepo:

# Navigate to your project
cd ~/projects/my-app

# Initialize a Claude Code config (optional but recommended)
cat > .claudecode.json << 'EOF'
{
  "modelId": "claude-3-5-sonnet-20241022",
  "maxTokens": 4096,
  "temperature": 0.2,
  "includePatterns": [
    "src/**/*.js",
    "src/**/*.ts",
    "package.json"
  ],
  "excludePatterns": [
    "node_modules/**",
    "dist/**",
    ".next/**"
  ]
}
EOF

# Start interactive session
claude-code chat

Inside the chat, you can now ask contextual questions:

> Review src/db/migrations/ for SQL injection risks
> Suggest a caching strategy for src/services/userData.ts
> Generate integration tests for the order pipeline
> Identify circular dependencies in the project

Claude will read your entire source tree (respecting .claudecode.json filters) and respond with deep understanding of your architecture.


Pricing: What Does It Actually Cost?

Claude Code uses the Claude API pay-as-you-go model — not a separate subscription. Pricing as of June 2026:

Model Input Output
Claude 3.5 Sonnet $3 / 1M tokens $15 / 1M tokens

Real costs for typical workflows:

  • Code review of 5 files (500 lines): ~$0.02
  • Refactor a module with conversation: ~$0.10
  • Analyze entire src/ directory: ~$0.50-$1.00
  • Daily usage (10 tasks): ~$0.50-$2.00
  • Monthly budget: ~$10-$60 for active developers

Compare this to GitHub Copilot ($10-20/month) or Cursor ($20/month) — Claude Code is genuinely cheaper for occasional, deep-dive analysis.


Claude Code vs. Other AI Tools

If you're deciding between Claude Code, Cursor, and GitHub Copilot, context matters:

Use Claude Code for:

  • Multi-file refactoring (it maintains full codebase context)
  • Architectural reviews and design discussions
  • Batch processing and automation
  • When you want to review changes before applying them
  • Cost-sensitive teams

Use Cursor or Copilot for:

  • Real-time autocompletion while you type
  • IDE integration without switching tools
  • Teams that need IDE-native workflows

For a deeper comparison, check out our Cursor vs Claude Code comparison for 2026 and our broader AI code assistants comparison guide.


Advanced Configurations

Custom System Prompts

Create a .claude-system.txt file in your project root to set context for all conversations:

You are reviewing code for a production Node.js/React SaaS application.
Priority: Security > Performance > Code elegance.
We use TypeScript, strict mode enabled.
All async functions must include error handling.
Database queries must use parameterized queries.

Claude Code will prepend this to every conversation:

claude-code chat --system .claude-system.txt

Ignore Files and Patterns

Create .claudecodeignore (similar to .gitignore):

node_modules/
dist/
.next/
coverage/
*.test.js
migrations/

This prevents Claude from analyzing test files or generated code, saving tokens and improving focus.

Integration with Git Hooks

Automatically review commits before pushing:

#!/bin/bash
# .git/hooks/pre-push

BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ $BRANCH == "main" ]]; then
  FILES=$(git diff-tree --no-commit-id --name-only -r $(git rev-parse HEAD))
  echo "Running Claude Code security review..."
  claude-code analyze $FILES --task "Security audit for production code"
fi

Common Pitfalls and Solutions

Issue: "API key not found"

Cause: Environment variable not set or shell not reloaded.

Fix:

# Verify it's set
echo $ANTHROPIC_API_KEY

# If empty, re-export and reload
export ANTHROPIC_API_KEY="sk-ant-..."
source ~/.bashrc  # or ~/.zshrc for macOS

# Test again
claude-code --test

Issue: Claude Code ignores large directories

Cause: Token limits. Claude Code has a 100k token input limit by default.

Fix: Use .claudecodeignore to exclude node_modules/, tests, and build output. Process directories in smaller chunks:

# Instead of analyzing entire src/
claude-code analyze src/api/ --task "Security review"
claude-code analyze src/components/ --task "Security review"

Issue: Refactored code doesn't work

Cause: You didn't test it before applying.

Fix: Always use --output to save Claude's suggestion first:

claude-code refactor src/utils.js --output src/utils.claude.js
# Review the file, test it, then move it
cp src/utils.claude.js src/utils.js

Integration with Your Existing Workflow

Using Claude Code with Docker

If you deploy with Docker, Claude Code is useful in your CI/CD pipeline. See our guide on Docker Compose for local development — you can run Claude Code analysis as a build step.

Combining with VS Code

While Claude Code is CLI-first, you can pair it with VS Code:

  1. Open VS Code terminal (Ctrl+ `)
  2. Run claude-code chat
  3. Ask Claude questions while editing

Or use it in pre-commit hooks alongside your favorite VS Code extensions.

AWS EC2 Deployments

When reviewing code before deploying to AWS EC2, run a final Claude Code audit:

claude-code analyze src/ --task "Performance optimization for production" > audit.md

Best Practices for Production Teams

  1. Always review before applying. Claude Code suggests refactorings — human judgment is final.

  2. Use it for code review augmentation. Run claude-code analyze on pull request diffs before human review.

  3. Set up a .claudecode.json with team standards. This ensures consistent prompting across your team.

  4. Monitor token usage. Check your Anthropic dashboard regularly — most teams spend <$100/month.

  5. Combine with existing tools. Claude Code works best alongside Docker, git, and your testing framework. It's not a replacement for linters or type checkers.

  6. For teams building custom solutions, consider consulting services like Adaptels who specialize in integrating AI tools into development workflows.


Summary: When to Reach for Claude Code

Claude Code is production-ready for:

  • Refactoring legacy code (maintains multi-file context)
  • Security audits (Claude 3.5 Sonnet is strong at vulnerability detection)
  • Batch documentation generation
  • Architectural reviews
  • Cost-conscious teams (cheaper than subscriptions)

It's not ideal for:

  • Real-time IDE autocompletion (use Cursor or Copilot instead)
  • Teams that never review before applying changes

The setup is 5 minutes. The cost is negligible. The capability is real. If you haven't tried Claude Code yet, spend 30 minutes with it this week. You'll know immediately whether it fits your workflow.

Sources

  1. Anthropic Documentation
  2. Anthropic API Reference
  3. Claude Code Documentation

Questions? Open an issue in your terminal or drop a message. I'm @mervcodes.