Skip to main content

Claude Code

What is Claude Code?

Claude Code is a command-line AI agent from Anthropic. Unlike Copilot (autocomplete) or Cursor (IDE chat), Claude Code runs in your terminal and can take autonomous actions on your behalf:

  • Read and write files
  • Run shell commands
  • Execute git operations
  • Search the web
  • Install packages
  • Run tests and fix failures

You describe what you want done; Claude Code figures out the steps and executes them.

Installation

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

Requires an Anthropic API key or Claude Max subscription. After install:

claude # starts Claude Code in your current directory

How It Works

Claude Code reads your entire project to understand context, then takes actions. It asks for permission before running shell commands unless you've pre-approved them.

$ claude

> Add a /health endpoint to the Express app that returns uptime and version

Claude Code: I'll add a health check endpoint. Let me first look at
your Express setup...

[reads app.js, package.json]

I'll add the endpoint to app.js:

app.get('/health', (req, res) => {
res.json({
status: 'ok',
uptime: process.uptime(),
version: process.env.npm_package_version
});
});

Shall I make this change? [Y/n]

What Claude Code Excels At

Multi-step tasks

> Write tests for the UserController, run them, and fix any failures

Claude Code:
1. Reads UserController.js
2. Generates userController.test.js
3. Runs npm test
4. Sees 2 failures
5. Reads the error output
6. Fixes the failing tests
7. Runs tests again — all pass

Codebase exploration

> How does authentication work in this project?
> What would break if I changed the User schema?
> Find all places where we're making external API calls

Refactoring

> Rename all instances of "userId" to "user_id" in the API responses
(but not in the database schema)

Claude Code searches, edits, and verifies the change without you touching a file.

Git operations

> Show me what changed in the last 3 commits
> Create a commit for the authentication changes with a good message
> What files were changed in the last PR?

Debugging

> The login route is returning 500. Here's the error:
MongoServerError: E11000 duplicate key error...
Find out why and fix it.

Effective Prompting for Claude Code

Be specific about constraints

❌ "Refactor the auth code"
✅ "Refactor the auth middleware to use async/await instead of callbacks,
don't change the function signatures or break existing tests"

Give it the error output

> I'm getting this when I run npm start:
Error: Cannot find module './config/database'
Fix it.

Pasting the actual error is faster than describing it.

Break large tasks into parts

> First, show me all the files that handle payment processing
[review]
> Now add input validation to the createPayment function
[review]
> Now write tests for that validation

Use it for code review

> Review the changes I've made since the last commit and point out
any bugs or security issues

Slash Commands

Inside a Claude Code session:

CommandWhat it does
/helpShow available commands
/clearClear conversation history
/compactSummarize conversation to save context
/costShow API cost so far this session
/exitEnd the session

Project Instructions with CLAUDE.md

Create a CLAUDE.md file in your project root to give Claude Code persistent context about your project:

CLAUDE.md
# Project: My API

## Stack
- Node.js + Express
- MongoDB with Mongoose
- Jest for testing

## Conventions
- All async handlers use the asyncHandler wrapper
- Errors are passed to next(err) for centralized handling
- Tests must be written before committing new features

## Important
- Never modify the auth middleware without running the full test suite
- The /api/admin routes require role="admin" checks

Claude Code reads this at the start of every session and follows these rules.

Claude Code vs Cursor vs Copilot

CopilotCursorClaude Code
InterfaceIn-editorIn-editorTerminal
ScopeCurrent fileWhole codebaseWhole codebase + terminal
Can run commandsNoNoYes
Best forAutocompleteChat + editsAutonomous multi-step tasks
Agentic actionsNoNoYes

Tips

  • Run it at the project root — it needs to see the full file structure
  • Start with > summarize this project — good way to verify it has the right context
  • Use it for tasks you'd write a script for — "find all TODO comments and create GitHub issues for them"
  • Review every change — Claude Code shows diffs before applying; always read them
  • Iterative beats one-shot — complex tasks work better as a conversation than one long prompt