Beginner · Developer

Claude Code 入門

Anthropic 的 AI 程式代理住在你的終端機裡。不是一個聊天視窗、不是自動完成 — 而是一個完整的代理,它會讀你的程式碼庫、寫程式、執行指令、做 commit。這裡說明真正的使用方式。
Sarah Chen 2026 年 4 月 12 分鐘閱讀

Claude Code is different from other AI coding tools. Cursor and Copilot live inside your editor, suggesting lines as you type. Claude Code lives in your terminal, like a colleague sitting next to you who can read your entire project, write files, run tests, search the web, and execute shell commands — all while you describe what you want in plain English.

This guide gets you from zero to productive. No fluff, no theory — just what you need to know to start using it effectively today.

安裝 Claude Code

Claude Code requires Node.js 18+ and an Anthropic API key (or a Max subscription). Install it globally:

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

Then navigate to any project directory and launch it:

cd your-project
claude

That’s it. Claude Code starts, scans your project structure, and presents a prompt. You’re ready to go.

First launch: Claude Code will ask you to authenticate. If you have an Anthropic API key, it’ll prompt for it. If you have a Claude Max subscription, you can use that instead. The tool remembers your credentials for future sessions.

你的第一次對話

The best way to learn Claude Code is to give it a real task. Don’t start with “hello” — start with something you actually need done.

不錯的第一個提示詞

Explain the structure of this project. What does each directory do?

Find all TODO comments in the codebase and summarize them

Add input validation to the signup form in src/auth/register.ts

The tests in tests/api/ are failing. Diagnose and fix.

Claude Code will read the relevant files, understand the context, propose changes, and — with your permission — make them. You approve each action: file reads happen automatically, but writes and shell commands ask for confirmation.

權限系統

Claude Code uses a layered permission model. Understanding it saves you from clicking “approve” a hundred times.

Pro tip: Press Shift+Tab to cycle through permission modes. “Auto-accept edits” mode lets Claude Code write files without asking each time — useful when you trust it on a well-scoped task. You can always switch back.

CLAUDE.md 檔案

This is the most important file most people don’t know about. Create a CLAUDE.md in your project root with instructions that persist across sessions:

# CLAUDE.md

## Project context
This is a Next.js 14 app with TypeScript, Prisma ORM, and Tailwind CSS.
The API routes are in app/api/. Auth uses NextAuth v5.

## Conventions
- Use server components by default, client components only when needed
- All database queries go through the service layer in src/services/
- Tests use Vitest, run with `npm test`
- Never modify the migration files directly

## Current work
- We're migrating from Pages Router to App Router
- The /dashboard route is the active focus

Claude Code reads this file automatically at the start of every session. It’s your way of giving Claude persistent context about your project without repeating yourself. Think of it as the onboarding doc you’d write for a new team member.

必備的斜線指令

Type / in the prompt to see all commands. The ones you’ll use most:

/help Show all available commands and keyboard shortcuts /clear Clear the conversation and start fresh (keeps CLAUDE.md context) /compact Compress the conversation to save context space /cost Show how much the current session has cost in API tokens /commit Create a git commit with an auto-generated message /review Review your current changes (like a code review)

重要的鍵盤快捷鍵

Enter Send your message Shift+Enter New line (for multi-line prompts) Shift+Tab Cycle permission modes Ctrl+C Cancel current generation Escape Interrupt and give new instructions Up arrow Recall previous messages

怎麼有效地下提示詞

Claude Code understands your codebase, so you don’t need to explain your project from scratch. But how you phrase requests dramatically affects results.

對結果要具體

模糊

Make the API better

具體

Add rate limiting to the /api/search endpoint. Use a sliding window of 60 requests per minute per API key. Return 429 with a Retry-After header when exceeded.

不明顯時就給上下文

好的上下文

The login page is showing a blank screen on mobile Safari. Desktop works fine. The component is in src/app/login/page.tsx. I think it might be related to the CSS grid layout but I'm not sure.

You don’t need to describe your project structure (Claude Code can read it), but you should share information it can’t see: error messages, browser-specific behavior, what you’ve already tried, and what you suspect.

用迭代式精修

Don’t try to get everything right in one prompt. Start with the main task, review the result, then refine:

  1. Add a dark mode toggle to the settings page
  2. (reviews the implementation)
  3. Good, but persist the preference in localStorage and apply it on page load before render to prevent flash
  4. Now add a system preference detection fallback for first-time users

Each follow-up builds on the context of what Claude Code just did. This iterative approach produces better results than a single massive prompt.

真實工作流

修 bug

Paste the error message or describe the symptom. Claude Code will search your codebase for relevant code, identify the root cause, and propose a fix.

Users are reporting that the checkout total shows $0 when they have
items in cart. Here's the error from the console:

TypeError: Cannot read property 'price' of undefined
at calculateTotal (src/utils/cart.ts:42)

Claude Code will read cart.ts, trace the data flow, find why price is undefined, and fix it.

實作功能

Describe what you want. Be clear about the scope — a feature that touches one file is easier to get right than one that touches twenty.

Add a "forgot password" flow:
1. A "Forgot password?" link on the login page
2. A form that accepts email and sends a reset link
3. A reset page where users enter a new password
4. Use the existing email service in src/services/email.ts
5. Tokens should expire after 1 hour

程式碼審查

The /review command reviews your uncommitted changes. Or be more specific:

Review the changes in src/api/ for security issues.
Focus on: input validation, SQL injection, auth bypass, and rate limiting.

重構

Refactor src/utils/helpers.ts — it's 800 lines of unrelated functions.
Split it into focused modules: string-utils.ts, date-utils.ts,
validation.ts, and formatting.ts. Update all imports across the codebase.

Claude Code handles multi-file refactors well because it can read and modify all the affected files in one session.

理解陌生程式碼

I just joined this project. Walk me through how a request flows from
the API endpoint in src/app/api/orders/route.ts to the database.
What middleware does it pass through? How is auth handled?

Claude Code 擅長的地方

要留意的地方

進階:hooks

Hooks let you run custom commands automatically in response to Claude Code’s actions. They’re defined in your settings and trigger before or after specific events.

Example: automatically run your linter after every file edit:

// In .claude/settings.json
{
  "hooks": {
    "afterEdit": {
      "command": "npx eslint --fix ${file}",
      "description": "Auto-lint after edits"
    }
  }
}

Hooks are powerful for enforcing project standards without relying on Claude Code to remember them.

Claude Code vs. 其他 AI 程式工具

The landscape is competitive. Here’s how they compare:

They’re not mutually exclusive. Many developers use Copilot for inline autocomplete and Claude Code for larger tasks — like having both a spellchecker and a writing partner.

精簡版

  1. Install: npm install -g @anthropic-ai/claude-code
  2. Launch in your project: cd your-project && claude
  3. Create a CLAUDE.md with project context and conventions
  4. Start with a real task, not “hello”
  5. Be specific about what you want
  6. Iterate: first pass, review, refine
  7. Use /compact when context gets long
  8. Trust but verify — review changes like any PR

Claude Code is most powerful when you treat it like a capable but junior colleague: give it clear instructions, review its work, and build trust incrementally. The more context you provide (through CLAUDE.md and specific prompts), the better the results.

The cursor is blinking. What do you want to build?