Claude Code setup

10 — Claude CodeCơ bản15 phút

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

Bạn sẽ học được
  • Install Claude Code trên máy
  • Login lần đầu
  • Biết các tính năng built-in
  • Setup đầu tiên cho 1 project

Tính năng built-in

Ready to use ngay sau install.

┌──────────────────────────────────────────┐
│                                          │
│   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)             │
│                                          │
└──────────────────────────────────────────┘

Install (3 bước)

Bước 1: Node.js

Check đã có chưa:

Nếu error → install Node:

Bước 2: Claude Code

  • macOS: brew install node
  • Linux: nodesource instructions
  • Windows: Download từ nodejs.org
npm help

Bước 2: Claude Code

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

Bước 3: Login

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

Bước 3: Login

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

claude

Subscription

Claude Code có 2 cách billing:

Option 1: Claude Max subscription

Option 2: API key billing

Check subscription options: anthropic.com/pricing

  • $100-200/tháng
  • Include Claude Code usage
  • Best cho individual / small team
  • Pay-per-use
  • Scale với traffic
  • Best cho CI/CD, headless usage

First session

Output:

cd my-project
claude

First session (tiếp)

Try:

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

Type your request, or /help for commands.

> 

First session (tiếp)

Claude Code scan codebase → answer.

> What does this project do? Give me 3-bullet summary.

Useful commands (slash)

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

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

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
# Always use type hints in Python code
# Prefer list comprehensions over map/filter

Check install

claude --version
# Output: 1.x.x

claude --help
# Show all flags

Config

Config file: ~/.claude/settings.json

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

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

MCP extend (from bài 6.77)

Add tools beyond built-in:

MCP servers available in all Claude Code sessions.

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

Troubleshoot install

command not found: claude

Fix:

Login fail

Fix:

Permission denied

Fix: npm global install cần privilege.

  • Check $PATH includes npm global bin
  • npm bin -g → add to PATH
  • Or reinstall: npm uninstall -g && npm install -g @anthropic-ai/claude-code
  • Check internet
  • Try different browser for OAuth
  • Clear local: rm -rf ~/.claude/cache (careful with settings!)
  • macOS/Linux: sudo npm install -g ...
  • Or use nvm/fnm for user-level node.

Best first session

cd interesting-project
claude

Best first session (tiếp)

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

> /init

Best first session (tiếp)

Get overview.

> Summarize the main components of this project

Best first session (tiếp)

Claude identify complexity. Useful cho onboarding.

> What are the 3 most complex files? Why?

Compared với alternatives

Claude Code best cho agent-driven workflows.

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

Safety warning

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

Use in sandboxed/dev environments for experiments.

  • ✅ 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)

Áp dụng ngay

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

Verify flow. Tomorrow: use cho real task.

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

Tóm tắt

🎯 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.

Nội dung này có hữu ích không?