跪拜 Guibai
← Back to the summary

Claude Code: The Terminal-Native AI Agent That Reads Your Whole Codebase and Fixes Bugs While You Drink Coffee

Claude Code: From Beginner to Pro, All in One Go

Author: AI Tool Explorer (Heavy user of mainstream AI coding tools like Cursor, Copilot, Claude Code)


1. Scenario: Why You Need Claude Code

Last week my server suddenly crashed — not a code bug, but a database connection pool exhaustion. At 2 AM, staring at a screen full of error logs, I had only one thought: I wish I had an AI assistant to help me quickly locate the problem.

That's when I remembered Claude Code.

To be honest, I didn't have high expectations at first. I've used too many AI coding tools before — either "smart autocomplete" or "chatbots" — very few can truly autonomously complete complex tasks. But Claude Code is different — it's Anthropic's terminal-native AI coding agent, not a simple code completion tool.

One sentence summary: Claude Code can read your entire codebase, understand the context, and then autonomously execute multi-step tasks. You only need to say "approve" or "reject" at key nodes.


2. Environment Setup

2.1 Installation

# Global installation (recommended)
npm install -g @anthropic-ai/claude-code

# Verify installation
claude --version

If you get command not found, it means your npm global bin directory is not in your PATH. Check:

echo $PATH
# Make sure it includes paths like ~/.npm-global/bin or ~/.nvm/versions/node/v*/bin

2.2 Authentication

After running the claude command, it will pop up a URL for you to log in via browser:

🔐 Authenticate with Anthropic
Open this URL in your browser: https://claude.ai/authorize...

After logging in, return to the terminal and you're authenticated.

2.3 Project Configuration (Critical!)

Create a CLAUDE.md file in the project root directory:

# Project Tech Stack
- Language: Python 3.11
- Framework: FastAPI + SQLAlchemy
- Database: PostgreSQL 15
- Testing: pytest

# Coding Standards
- Use type annotations
- Function names: snake_case, Class names: PascalCase
- Error handling: prefer try-except, no bare except
- Logging: use logging module, not print

# Project Structure
src/          # Main code
tests/        # Test files
config/       # Configuration files

This file is very important — Claude Code will treat it as "project memory" and reference it in every conversation. Without it, Claude Code is like a fresh intern who knows nothing.

2.4 Permission Configuration

Configure permissions in .claude/settings.json:

{
  "allowed_tools": ["read", "edit", "execute", "bash"],
  "disallowed_tools": ["delete"],
  "auto_approve": ["format", "lint"]
}

This way Claude Code will ask you before modifying files, but safe operations like formatting can pass automatically.


3. Hands-on: Using Claude Code to Complete a Real Task

Task Background

My FastAPI project has a bug: when a user registers with an existing email, the system throws a 500 error instead of a friendly message. I want Claude Code to fix it.

3.1 Start Claude Code

cd my-fastapi-project
claude

The terminal enters interactive mode:

╭────────────────────────────────────────────╮
│  Claude Code  v1.2.3                       │
│  Model: Claude Opus 4.6                    │
│  Context: 1,000,000 tokens                 │
╰────────────────────────────────────────────╯

3.2 Describe the Problem

Help me fix the duplicate email issue during user registration.
Currently, if the email already exists, it throws a 500 error.
It should return a 400 status code with the message "This email is already registered."

3.3 Observe Claude Code's Thought Process

Claude Code doesn't modify code directly; it first plans:

🔍 Analyzing...

1. Find the user registration route handler
2. Locate the email check logic
3. Modify exception handling to return 400 instead of 500
4. Add test cases to verify the fix

Estimated modification of 3 files. Continue?

Key point here: Claude Code shows you the list of files it will modify, and you have the right to reject.

3.4 View Modification Preview

📝 Modification Preview:

src/api/routes/auth.py
@@ -45,7 +45,10 @@
     if await user_exists(email):
-        raise InternalServerError("Database error")
+        raise HTTPException(
+            status_code=400,
+            detail="This email is already registered"
+        )

tests/test_auth.py
@@ -12,3 +12,15 @@
+async def test_duplicate_email_returns_400():
+    response = await client.post("/register", json={
+        "email": "[email protected]",
+        "password": "password123"
+    })
+    assert response.status_code == 400
+    assert "This email is already registered" in response.json()["detail"]

3.5 Confirm and Execute

Type y to confirm, and Claude Code starts executing:

✅ Modified src/api/routes/auth.py
✅ Modified tests/test_auth.py
🔧 Running tests...

tests/test_auth.py::test_duplicate_email_returns_400 PASSED

Done. The whole process took less than 3 minutes.


4. Effectiveness Comparison

Metric Traditional Approach Claude Code
Time to locate issue 15-30 minutes 30 seconds
Writing fix code 10 minutes Auto-completed
Writing test cases 5-10 minutes Auto-generated
Running verification Manual execution Auto-run
Total 30-50 minutes 2-3 minutes

This is not an exaggeration. Last week I refactored a module's exception handling logic, involving 8 files and 23 changes. Using Cursor's Agent mode, I spent 40 minutes going back and forth confirming each step; using Claude Code, I spent 5 minutes — most of it drinking coffee.


5. FAQ

Q1: What's the difference between Claude Code and Cursor?

Simply put:

For example:

Measured data: Independent tests show Claude Code's agent approach reduces code rework by about 30% compared to Cursor. A task that takes 15 minutes of back-and-forth confirmation in Cursor can usually be done in one go with Claude Code.

Q2: Is Claude Code paid?

There's a free tier, but deep usage requires a subscription:

Plan Price Use Case
Free $0 Light daily use
Pro $20/month Individual developer
Team $40/person/month Team collaboration

Money-saving tip: Use Claude Sonnet 4.6 for daily simple tasks (fast, cheap), and Claude Opus 4.6 for complex architectural decisions (powerful, expensive). Rough ratio: 80% Sonnet + 20% Opus.

Q3: Can Claude Code handle large projects?

Yes. It supports 1 million token context, meaning it can "remember" the entire codebase at once.

But I have an experience: When the project is too large, CLAUDE.md needs to be more detailed. For example:

# Core Modules
- auth/: User authentication, based on JWT
- api/: REST API routes
- models/: SQLAlchemy models

# Files NOT to touch
- config/settings.py (production configuration)
- scripts/deploy.sh (deployment script)

# Dependencies
auth depends on models
api depends on auth and models

Q4: Will Claude Code mess up my code?

Yes, but it's controllable.

Its permission system gives you veto power at every key step:

If you're worried, you can set disallowed_tools more strictly in .claude/settings.json:

{
  "disallowed_tools": ["delete", "execute"]
}

This way it can only read and modify files, not execute shell commands.

Q5: Why does Claude Code sometimes "get dumber"?

Most common reason: CLAUDE.md is not well written.

Claude Code references this file in every conversation. If the file says "Project uses Python" but the actual project is Python+FastAPI+PostgreSQL+Redis, it's like an interviewer who only read the resume but never saw the project.

Solution: Spend 10 minutes writing a detailed CLAUDE.md. Include:


6. Advanced Tips

6.1 Plan Mode

For complex tasks, use /plan to let Claude Code plan the steps:

/plan Refactor the user authentication module from JWT to OAuth2

It will output a detailed execution plan, and you confirm before letting it proceed.

6.2 Multi-model Switching

/model opus   # Switch to Opus for complex tasks
/model sonnet # Switch back to Sonnet for daily use

6.3 Agent Teams

Claude Code 1.2+ supports parallel execution of multiple sub-tasks:

/agents 3 Test all modules in parallel

It will start 3 sub-agents working simultaneously and aggregate the results.


7. Summary

Claude Code is not a silver bullet, but it has indeed changed my workflow. Bugs that used to take hours to debug, I now hand over to it and go grab a coffee.

My usage habits:

If you haven't tried it yet, I recommend spending 10 minutes to install it. There's a free tier anyway, so it's worth a shot.


If you found this helpful, feel free to like and bookmark ❤️ For more AI tool practical tutorials, follow me to get them first~