Chapter 4: Claude Code
"The terminal is where engineers live. Now AI lives there too."
Claude Code is Anthropic's agentic coding tool that runs entirely in your terminal. Unlike IDE-based tools, Claude Code meets you where you already are—the command line.
What Makes Claude Code Different
Claude Code isn't just another AI assistant. It's an agentic system that can:
- Read and understand your entire codebase
- Make changes across multiple files
- Run terminal commands and react to the output
- Iterate until the task is complete
- Work autonomously while you watch (or do other things)
Think of it as having a junior developer in your terminal who can actually execute on tasks, not just suggest code.
//The Agentic Difference
Most AI tools wait for you to copy-paste context and then give you suggestions. Claude Code actively explores your codebase:
- You give it a task
- It reads relevant files to understand the context
- It makes changes or runs commands
- It checks the results
- It iterates if something didn't work
This loop continues until the task is done—or until it needs your input.
Getting Started
//Installation
# Install via npm (Node.js 18+ required)
npm install -g @anthropic-ai/claude-code
# Or use npx to run without installing
npx @anthropic-ai/claude-code
//Authentication
Claude Code uses your Anthropic API key:
# Set your API key
export ANTHROPIC_API_KEY=your-key-here
# Or Claude Code will prompt you on first run
claude
//Your First Session
Navigate to a project directory and start Claude Code:
cd ~/projects/my-app
claude
You'll enter an interactive session where you can chat with Claude about your codebase.
Core Commands and Usage
//Interactive Mode
Just run claude to start a conversation:
claude
Then type naturally:
- "Explain how the authentication system works"
- "Find all the places where we handle user input"
- "Add error handling to the payment processing function"
//One-Shot Commands
For quick tasks, pass your request directly:
# Ask a question
claude "What does the UserService class do?"
# Make a change
claude "Add a created_at timestamp to the User model"
# Run a task
claude "Write tests for the checkout flow"
//Useful Flags
# Continue a previous conversation
claude --continue
# Start fresh (ignore previous context)
claude --no-context
# Use a specific model
claude --model claude-sonnet-4-20250514
# Increase output limit for complex tasks
claude --max-tokens 8000
What Claude Code Can Do
//1. Codebase Exploration
Claude Code excels at helping you understand unfamiliar code:
> Explain the architecture of this project
> How does data flow from the API to the database?
> What are the main entry points to this application?
> Find all the places where we call external APIs
It will read through your files, trace connections, and give you a coherent explanation.
//2. Code Generation
Write new code that fits your existing patterns:
> Create a new API endpoint for user preferences that follows
the same patterns as the existing user endpoints
> Add a caching layer to the database queries in UserRepository
> Write a React component for displaying order history,
matching the style of existing components
//3. Refactoring
Make changes across multiple files:
> Rename the "Customer" class to "Client" everywhere in the codebase
> Extract the validation logic from UserController into a separate
ValidationService
> Convert all callbacks in the auth module to async/await
//4. Debugging
Give Claude Code an error and let it investigate:
> I'm getting this error when I run the tests:
TypeError: Cannot read property 'id' of undefined
at processOrder (orders.js:47)
Find and fix the bug.
It will read the relevant code, understand the context, and propose (or make) a fix.
//5. Testing
Generate tests that actually understand your code:
> Write unit tests for the PaymentProcessor class
> Add integration tests for the checkout API endpoint
> The tests in auth.test.js are failing. Fix them.
//6. Git Operations
Claude Code can help with version control:
> What changed in the last 5 commits?
> Create a commit with an appropriate message for my current changes
> Help me resolve the merge conflicts in user-service.ts
//7. DevOps and Scripts
Perfect for automation tasks:
> Write a bash script to backup the database and upload to S3
> Create a GitHub Action that runs tests on every PR
> Help me debug why the Docker build is failing
Advanced Usage
//Working with Large Codebases
For big projects, help Claude Code focus:
> Look at the files in src/payments/ and explain the payment flow
> Only considering the backend code, how do we handle authentication?
> Ignore the node_modules and focus on our source code
//Chaining Tasks
You can build on previous work in a session:
> Create a new endpoint for user notifications
[Claude Code creates the endpoint]
> Now add input validation to that endpoint
[Claude Code adds validation]
> Write tests for it
[Claude Code writes tests]
> Run the tests and fix any failures
[Claude Code runs tests and iterates]
//Using with SSH/Remote Servers
One of Claude Code's biggest advantages is remote work:
# SSH into your server
ssh user@production-server
# Run Claude Code there
claude "Check the logs for errors in the last hour and summarize them"
claude "The API is slow. Profile the database queries and suggest optimizations"
No need to set up remote IDE extensions—just a terminal.
//CLAUDE.md Project Files
Create a CLAUDE.md file in your project root to give Claude Code persistent context:
# CLAUDE.md
## Project Overview
This is a Node.js REST API for an e-commerce platform.
## Tech Stack
- Node.js 20
- Express.js
- PostgreSQL with Prisma
- Jest for testing
## Key Patterns
- All API routes are in src/routes/
- Business logic lives in src/services/
- Database access is through src/repositories/
## Commands
- npm run dev - Start development server
- npm test - Run tests
- npm run lint - Lint code
## Important Notes
- Never modify files in src/legacy/ - deprecated code
- All new endpoints need authentication middleware
Claude Code reads this automatically and uses it as context for every conversation.
Claude Code vs Cursor
| Aspect | Claude Code | Cursor |
|---|---|---|
| Interface | Terminal | VS Code-based IDE |
| Best for | Terminal lovers, remote work, automation | Visual development, complex refactoring |
| File editing | Yes (shows diffs in terminal) | Yes (visual diffs) |
| Runs commands | Yes, natively | Yes, with confirmation |
| IDE features | None | Full VS Code |
| Remote/SSH | Trivial | Requires Remote SSH extension |
| Learning curve | Lower if you live in terminal | Lower if you use VS Code |
//When to Use Claude Code
- You're already in the terminal
- You're SSH'd into a remote machine
- You want quick answers without opening an IDE
- You're doing DevOps/scripting work
- You prefer keyboard-only workflows
//When to Use Cursor
- You need visual diff review
- You want IDE features (debugging, etc.)
- You're doing heavy visual refactoring
- You prefer a GUI
Tips for Effective Claude Code Usage
//1. Be Specific About Scope
# Too vague
> Fix the bugs
# Better
> Fix the null pointer exception in UserService.getById()
//2. Provide Error Context
# Good
> I ran npm test and got this error:
[paste full error]
Fix it.
//3. Let It Iterate
Don't interrupt too quickly. Claude Code often fixes issues on subsequent attempts:
> Run the tests and fix any failures until they all pass
//4. Use It for Exploration First
Before making changes, ask Claude Code to explain:
> Before we modify anything, explain how the current
authentication flow works
//5. Review the Changes
Always review what Claude Code produces:
> Show me the diff of all changes you made
Key Takeaways
-
Claude Code is agentic. It doesn't just suggest—it acts, observes, and iterates.
-
It lives in your terminal. No IDE required, works over SSH, perfect for command-line workflows.
-
Use CLAUDE.md to give it project context automatically.
-
Let it iterate. Don't micromanage—give it a goal and let it work.
-
Great for exploration. Use it to understand codebases before making changes.
-
Complements Cursor. Use Claude Code for terminal work, Cursor for visual IDE work.
Next: Other companion tools—ChatGPT, Augment Code, and more.