Lộ trình học›Claude API›Building with the Claude API Mở bản đồ

6.79 · Claude Code setup

Bài viếtCơ bản → Trung c15 phút đọc

Claude Code = CLI agent cho coding. Sống trong terminal, tích hợp với filesystem, shell, git, web.

Sau bài này, bạn sẽ
  1. Install Claude Code trên máy
  2. Login lần đầu
  3. Biết các tính năng built-in
  4. Setup đầu tiên cho 1 project

Mở đầu: Agent chạy trong terminal

Chạy trên: macOS, Linux, Windows (WSL).

Tính năng built-in

┌──────────────────────────────────────────┐
│                                          │
│   CLAUDE CODE TOOLS (built-in)           │
│                                          │
│   File ops:                              │
│     - Glob    (tìm file)                 │
│     - Grep    (search content)           │
│     - Read    (đọc file)                 │
│     - Edit    (sửa file)                 │
│     - Write   (tạo file)                 │
│                                          │
│   Shell:                                 │
│     - Bash    (chạy command)             │
│                                          │
│   Web:                                   │
│     - WebFetch                           │
│     - WebSearch                          │
│                                          │
│   Agent:                                 │
│     - Task    (sub-agent)                │
│     - TodoWrite                          │
│                                          │
│   Plus: MCP servers (extend)             │
│                                          │
└──────────────────────────────────────────┘

Ready to use ngay sau install.

Install (3 bước)

Bước 1: Node.js

Check đã có chưa:

npm help

Nếu error → install Node:

Bước 2: Claude Code

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

Có thể cần sudo trên Linux/macOS.

Bước 3: Login

claude

First run → prompt login. Đăng nhập account Anthropic (same as console.anthropic.com).

Subscription

Claude Code có 2 cách billing:

Option 1: Claude Max subscription

  • $100-200/tháng
  • Include Claude Code usage
  • Best cho individual / small team

Option 2: API key billing

  • Pay-per-use
  • Scale với traffic
  • Best cho CI/CD, headless usage

Check subscription options: anthropic.com/pricing

First session

cd my-project
claude

Output:

Welcome to Claude Code (v1.x)
Connected to: my-project

Type your request, or /help for commands.

>

Try:

Prompt trong Claude Code
What does this project do? Give me 3-bullet summary.

Claude Code scan codebase → answer.

Useful commands (slash)

CommandPurpose
/helpList all commands
/clearReset conversation
/initScan codebase, create CLAUDE.md
/compactSummarize history to save tokens
/costShow session cost
/exitQuit

/init đặc biệt quan trọng — bài tiếp theo.

# command cho CLAUDE.md

Type # + rule → saved to CLAUDE.md:

Claude Code asks to add to project / local / user CLAUDE.md.

  • Project: shared team, commit git
  • Local: your notes, gitignored
  • User: cross-projects

Check install

claude --version

claude --help

Config

Config file: ~/.claude/settings.json

{
  "defaultModel": "claude-sonnet-4-6-20260205",
  "permissions": {
    "allow": ["Bash(git:*)", "Read(**)"],
    "ask": ["Write(**)", "Bash(**)"]
  }
}

permissions control what Claude Code can do without confirm. Important for safety.

MCP extend (from bài 6.77)

Add tools beyond built-in:

claude mcp add sentry npx @sentry/mcp-server
claude mcp list
claude mcp remove sentry

MCP servers available in all Claude Code sessions.

Troubleshoot install

command not found: claude

Fix:

  • Check $PATH includes npm global bin
  • npm bin -g → add to PATH
  • Or reinstall: npm uninstall -g && npm install -g @anthropic-ai/claude-code

Login fail

Fix:

  • Check internet
  • Try different browser for OAuth
  • Clear local: rm -rf ~/.claude/cache (careful with settings!)

Permission denied

Fix: npm global install cần privilege.

  • macOS/Linux: sudo npm install -g ...
  • Or use nvm/fnm for user-level node.

Best first session

cd interesting-project
claude
Prompt trong Claude Code
/init

Claude scan code → create CLAUDE.md. Review + commit.

Prompt trong Claude Code
Summarize the main components of this project

Get overview.

Prompt trong Claude Code
What are the 3 most complex files? Why?

Claude identify complexity. Useful cho onboarding.

Compared với alternatives

Claude CodeCursorGitHub CopilotChatGPT desktop
InterfaceTerminalIDE integratedIDE inlineStandalone app
Agent modeYes (full)YesNoLimited
File opsFullFullSuggest onlyManual copy
MCPNativeYesNoNo
Cost$100+/mo OR API$20/mo$10/mo$20/mo
Best forAgent workflows, power usersIDE usersLine-by-lineChat-like

Claude Code best cho agent-driven workflows.

Safety warning

Claude Code có full filesystem + shell access. Treat with respect:

  • Use on projects you own
  • Commit often (easy rollback)
  • Review plans before complex ops
  • Don't give production creds
  • Don't run untrusted prompts (prompt injection via README)

Use in sandboxed/dev environments for experiments.

Áp dụng ngay

Bài tập: Install + run (20 phút)

  1. Install Claude Code
  2. Navigate to 1 of your projects
  3. claude
  4. /init — create CLAUDE.md
  5. Ask 3 questions about project
  6. Quit

Verify flow. Tomorrow: use cho real task.

Tóm tắt bài học

Những điều cốt lõi
  • Claude Code = CLI agent cho coding.
  • Install 3 bước: Node.js → npm install → claude login.
  • Built-in tools: file ops, bash, web, agent.
  • Slash commands: /help, /init, /clear, /cost.
  • MCP extend cho custom tools.
Bạn đã hoàn thành bài này chưa?Tiến độ lưu trên trình duyệt của bạn.