Claude Code: AI That Writes and Fixes Your Code
Imagine telling your computer “fix that bug” and it does.
That’s Claude Code. It’s an AI coding assistant that lives in your terminal (the black screen with text).
Unlike chatbots where you copy-paste code, Claude Code can:
- Read your whole project
- Edit multiple files
- Run tests
- Use Git (commit, push, make branches)
- Fix its own mistakes
What Is Claude Code?
Think of it as a coding partner who never gets tired.
You type what you want in plain English. Claude Code:
- Reads your project files
- Plans what to change
- Shows you the plan
- Makes the changes (when you say yes)
- Runs tests to check nothing broke
All inside your terminal. No copy-paste needed.
How to Install It
You need:
- A computer with Node.js installed
- An Anthropic API key (free tier available)
Installation:
# Install Claude Code
npm install -g @anthropic-ai/claude-code
# Or use it without installing
npx @anthropic-ai/claude-code
First run:
- Open your terminal
- Go to your project folder:
cd my-project - Type:
claude-code - It asks for your API key (paste it)
- It scans your project
Done. You’re ready.
The Three Ways to Use It
Way 1: Ask It to Do Something
Type what you want. Use plain English.
Example 1 — Refactor code:
> Change all "var" to "const" across the project.
> Make sure nothing breaks.
Claude Code:
- Finds all files with “var”
- Changes them to “const”
- Runs your tests
- If a test fails, fixes the issue
- Shows you what changed
Example 2 — Add a feature:
> Add a search box to the home page.
> It should search through the product list.
> Style it with our existing CSS.
Claude Code:
- Finds the home page file
- Finds the product list
- Adds search logic
- Adds the search box HTML
- Makes it match your existing style
- Runs tests
Example 3 — Fix a bug:
> The login page shows a white screen on mobile.
> Find and fix it.
Claude Code:
- Looks at the login page code
- Finds the CSS that breaks on small screens
- Fixes it
- Shows you the change
Way 2: Show It an Error
Copy an error message. Paste it. Claude Code figures out the cause.
> This error keeps happening:
> TypeError: Cannot read property 'map' of undefined
> at Dashboard.js:47
Claude Code:
- Goes to Dashboard.js line 47
- Finds where the data comes from
- Sees the data is sometimes empty
- Adds a safety check
- Runs the test to confirm it’s fixed
Way 3: Work Step by Step
For big changes, Claude Code works in steps:
> I want to add user profiles to the app.
> This will need:
> - A profile page
> - A way to edit the profile
> - Save changes to the database
> - Show the profile in the navigation
>
> Plan it out first. I'll approve each step.
Claude Code shows a plan:
Step 1: Add profile fields to the user model
Step 2: Create the profile page component
Step 3: Add the edit form
Step 4: Connect to the API
Step 5: Add navigation link
Step 6: Write tests
You say “yes” to each step. Claude Code does it and shows you what changed.
Key Commands
| Command | What It Does |
|---|---|
claude-code | Start Claude Code in your project |
/diff | Show all changes before applying |
/commit | Make a Git commit with a good message |
/test | Run your project’s tests |
/explain | Explain what a file or function does |
/search | Search your whole codebase |
Safety tip: Use /diff before big changes. It shows you exactly what will change. Say “no” if you don’t like it.
When to Use Claude Code
Use it when:
- You need to change many files at once
- You want to refactor old code
- You’re fixing a bug that spans multiple files
- You’re adding a feature and aren’t sure where to start
- You want to write tests for existing code
Don’t use it when:
- You’re learning a new concept (Claude Code does; you don’t learn)
- The change is tiny (just edit it yourself, faster)
- You need creative design decisions (AI has no taste)
- Security is critical (always review AI changes yourself)
Real Example: A Full Refactor
Before:
A React app with old-style class components. 15 files. Hard to maintain.
What you type:
> Convert all class components to function components.
> Use hooks (useState, useEffect).
> Keep all the same behavior.
> Add tests for each converted component.
What Claude Code does:
- Lists all 15 files with class components
- Converts each one to a function component
- Replaces lifecycle methods with hooks
- Keeps all props and state the same
- Writes a test for each component
- Runs all tests
- If a test fails, fixes it
- Commits everything with a clear message
Time: 20 minutes instead of 4 hours.
Claude Code vs. Other Tools
| Tool | Best For | Where It Works |
|---|---|---|
| Claude Code | Big changes across files | Terminal (command line) |
| Cursor | Daily coding with AI help | Code editor with GUI |
| GitHub Copilot | Auto-complete while typing | Inside your code editor |
| ChatGPT | Quick questions, learning | Web browser |
Best combo: Cursor for daily coding + Claude Code for big refactors.
Safety Tips
- Always review changes — Don’t blindly accept everything
- Run tests after — Claude Code can make mistakes
- Use
/difffor big changes — See what will change before it happens - Commit before big changes — You can undo if something goes wrong
- Don’t give it production secrets — API keys, passwords should stay private
Try It Now
- Install:
npm install -g @anthropic-ai/claude-code - Go to a project:
cd my-project - Start:
claude-code - Ask: “What does this project do?”
- Then ask: “Find one thing that could be better and fix it”
Free to try. $20/month for heavy use.
This guide is part of our How-To series. We test every tool before we write about it.