🇹🇼 中文 🇺🇸 English 🇯🇵 日本語 🇪🇸 Español
📖 Complete Guide

Claude Code
Complete Guide

From installation to advanced orchestration, master the core architecture and practical techniques of this CLI AI coding assistant.

1. What is Claude Code?

Claude Code is a CLI AI coding assistant by Anthropic that runs directly in your terminal — reading/writing files, executing commands, managing Git. Not just code completion, but a true AI development agent.

💡 Why Claude Code?

Estimated annual revenue of $2.5 billion, making it the fastest-growing AI development tool. Supports parallel Sub-agents, complete Hooks system, CLAUDE.md persistent memory, and Command → Agent → Skill orchestration workflow.

vs Other Tools

Claude Code
CLI AI Agent
  • Full terminal access
  • Parallel Sub-agents
  • Complete Hooks system
  • CLAUDE.md memory
  • $2.5B revenue (est.)
✈️
GitHub Copilot
IDE Plugin
  • IDE inline completion
  • Inline code suggestions
  • No agent capabilities
  • No custom Hooks
  • No memory system
🖱️
Cursor
AI IDE
  • Graphical IDE interface
  • Built-in AI chat
  • Limited agent features
  • 無 Hooks 系統
  • No native orchestration

2. Core Architecture: The Three Cs

Claude Code's extensibility is built on three components: Agents, Commands, and Skills.

🤖

Agents

16 Fields · 6 Official Built-in
  • Custom models & tools
  • Background execution mode
  • Hooks lifecycle
  • Git Worktree isolation
  • Skill preloading
⌨️

Commands

13 Fields · 64 Official Commands
  • /slash command trigger
  • Context fork isolation
  • Model & effort override
  • Tool permission control
  • Shell script embedding
🧩

Skills

13 Fields · 5 Official Built-in
  • Path-matching auto-load
  • Agent preloading
  • Independent fork execution
  • simplify / batch / debug
  • loop scheduled repeat

🤖 Agents — 16 Frontmatter Fields

FieldTypeDescription
namestringUnique identifier (lowercase + hyphens)
descriptionstringWhen to invoke. Use "PROACTIVELY" for auto-invocation
toolsstring/listTool allowlist, supports Agent(type) syntax
disallowedToolsstring/listTools removed from inherited list
modelstringhaikusonnetopusinherit
permissionModestringdefaultacceptEditsdontAskbypassPermissionsplan
maxTurnsintegerMaximum agentic turns
skillslistSkill names preloaded at startup
mcpServerslistMCP server connections
hooksobjectLifecycle Hooks
memorystringMemory scope: userprojectlocal
backgroundbooleanSet to true for background task execution
effortstringlowmediumhighmax
isolationstringSet "worktree" to run in temporary git worktree
initialPromptstringFirst prompt auto-submitted when running as main agent
colorstringCLI output color (e.g. greenmagenta

6 Official Built-in Agents

#AgentModelToolsPurpose
1general-purposeinheritAll複雜多步驟任務 — 預Set 代理類型
2ExplorehaikuRead-onlyFast code search and exploration
3PlaninheritRead-onlyPre-implementation planning
4BashinheritBashExecute terminal commands in separate context
5statusline-setupsonnetRead, EditSet 定狀態列
6claude-code-guidehaikuGlob, Grep, Read, WebFetch, WebSearchAnswer Claude Code feature questions

⌨️ Commands — 13 Frontmatter Fields

FieldTypeDescription
namestringDisplay name and /slash-command ID
descriptionstringDescription shown in autocomplete
argument-hintstringArgument hint for autocomplete
disable-model-invocationbooleanPrevent Claude from auto-invoking this command
user-invocablebooleanSet false to hide from menu
pathsstring/listGlob patterns to limit loading
allowed-toolsstringTools allowed without permission prompts
modelstringModel used when running
effortstringOverride effort level
contextstringSet fork to run in isolated subagent
agentstringSubagent type when context: fork
shellstringbash(預Set )或 powershell
hooksobjectLifecycle hooks scoped to this command

64 Official Commands (by Category)

#CommandCategoryDescription
1-3/login /logout /upgradeAuthAccount login, logout, upgrade plan
4-15/color /config /keybindings /permissions /privacy-settings /sandbox /statusline /stickers /terminal-setup /theme /vim /voiceConfig主題、按鍵、權限、沙盒、語音等Set 定
16-22/context /cost /extra-usage /insights /stats /status /usageContextContext visualization, token usage, analytics
23-27/doctor /feedback /help /release-notes /tasksDebugDiagnostics, bug reports, background tasks
28-29/copy /exportExportCopy response to clipboard, export conversation
30-37/agents /chrome /hooks /ide /mcp /plugin /reload-plugins /skillsExtensionsAgent, MCP, Plugin, Hooks management
38/memoryMemory編輯 CLAUDE.md memory檔、管理 auto-memory
39-43/effort /fast /model /passes /planModelModel switching, effort adjustment, Plan mode
44-49/add-dir /diff /init /pr-comments /review /security-reviewProjectWorking directory, Diff viewer, PR, security review
50-56/desktop /install-github-app /install-slack-app /mobile /remote-control /remote-env /scheduleRemoteDesktop App, Slack, GitHub, remote control, cloud scheduling
57-64/branch /btw /clear /compact /exit /rename /resume /rewindSessionBranch, compact, rewind, Session management

🧩 Skills — 13 Frontmatter Fields

FieldTypeDescription
namestringDisplay name and /slash-command ID
descriptionstringDescription for auto-discovery
argument-hintstringArgument hint for autocomplete
disable-model-invocationbooleanPrevent Claude from auto-invoking
user-invocablebooleanSet false to hide (agent preload only)
allowed-toolsstringTools allowed without permission prompts
modelstringModel used when running
effortstringOverride effort level
contextstringSet fork to run in isolated subagent
agentstringSubagent type when context: fork
hooksobjectLifecycle hooks scoped to this skill
pathsstring/listGlob patterns to limit auto-loading
shellstringbash(預Set )或 powershell

5 Official Built-in Skills

#SkillPurpose
1simplifyReview changed code — refactor to eliminate duplication, improve quality
2batchRun commands across multiple files in bulk
3debugDebug failing commands or code issues
4loopRun prompts on a recurring schedule (up to 3 days)
5claude-apiBuild apps with Claude API / Anthropic SDK

3. Memory System

CLAUDE.md is Claude Code's persistent memory — loaded on every startup, letting Claude remember your project conventions, preferences, and workflows.

📝

Writing a Good CLAUDE.md

CLAUDE.md is the most impactful way to improve Claude Code output:

  • Project structure
  • Code style conventions
  • Common commands & paths
  • Test & deploy workflows
  • Personal preferences via CLAUDE.local.md
🗂️

Three-Layer Loading

Claude Code loads memory in two directions:

  • Ancestor loading (UP) — walks up from cwd at startup, loads all CLAUDE.md files
  • Descendant loading (DOWN) — subdirectory files only load when accessed
  • Global~/.claude/CLAUDE.md applies to all sessions
  • Sibling directoriesnever load

Monorepo Structure Example

/mymonorepo/
├── CLAUDE.md ← 根層共用(啟動即 load)
├── frontend/
│   └── CLAUDE.md ← before端專屬(讀取時才 load)
├── backend/
│   └── CLAUDE.md ← after端專屬(讀取時才 load)
└── api/
    └── CLAUDE.md ← API 專屬(讀取時才 load)
💡 load範例

/mymonorepo/frontend/ Starting from here:
/mymonorepo/CLAUDE.md — 祖先目錄,啟動即 load
frontend/CLAUDE.md — 當before目錄,啟動即 load
backend/CLAUDE.md — 不同分支,不 load
api/CLAUDE.md — 不同分支,不 load

4. Hooks: Deterministic Guardrails

Hooks are deterministic scripts that run outside the agentic loop — triggered on specific events, providing safety guardrails and automation.

⚠️ Core Principle

Hooks trigger after tool operationscompletetriggers (PostToolUse), not before.PreToolUse is the exception — it can intercept before execution.

6 Hook Types Supported by Agents

🔍

PreToolUse

Triggersbeforetool execution. Can block, modify, or log pending operations.

PostToolUse

Triggersaftertool execution. Validate output, run linters, send notifications.

🔔

Notification

Triggers when Claude needs user attention. Connect to sounds, desktop notifications.

🛑

Stop

Triggers when agent completes a turn. Run final checks or cleanup.

🔐

SubagentStop

Triggers when subagent stops. Collect child agent results.

🌐

HTTP Hooks

Trigger external webhooks via HTTP POST with JSON payload.

Set 定範例

settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "npx eslint --fix $CLAUDE_FILE_PATHS"
          }
        ]
      }
    ],
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "afplay /System/Library/Sounds/Glass.aiff"
          }
        ]
      }
    ]
  }
}

5. Orchestration Workflow

Command → Agent → Skill is Claude Code's core orchestration pattern. A Command starts the flow, Agent handles execution, Skill provides domain knowledge.

⌨️
Command
Entry point · User interaction
🤖
Agent
Execute tasks · Preloaded Skill
🧩
Skill
Domain knowledge · Output results

Example: Weather System

ComponentRoleExample
CommandEntry point, user interaction/weather-orchestrator
AgentFetch data with preloaded skillweather-agent(preloaded weather-fetcher)
SkillIndependent visual outputweather-svg-creator

Execution Flow

Execution Flow
// User input
/weather-orchestrator

// Step 1: Command asks user preference
├─ AskUser: "Celsius or Fahrenheit?"
│  └─ User: "Celsius"

// Step 2: Command invokes agent via Agent tool
├─ Agent tool → weather-agent
│  ├─ Preloaded Skill: weather-fetcher(domain knowledge)
│  ├─ Fetches from Open-Meteo API → 26°C
│  └─ Returns temperature to Command

// Step 3: Command invokes skill via Skill tool
├─ Skill tool → weather-svg-creator
│  ├─ Output → weather.svg(weather card)
│  └─ Output → output.md(summary)

// Done
└─ Display results to user
💡 Two Skill Usage Patterns

Agent Skill(預載): Injected via agent's skills field as domain knowledge.
Skill(獨立): Invoked independently via Skill tool, produces output directly.

6. Practical Tips

Practical tips for everyday Claude Code usage to boost your productivity.

📊

/context — Context Visualization

查看當before context 使用量的彩色格狀圖。顯示哪些工具佔用最多空間,建議如何優化。

🔀

context: fork

在 command 或 skill 中Set context: fork,讓它 to run in isolated subagent,不污染主對話。

📂

paths Pattern Matching

paths 欄位Set 定 glob 模式,讓 skill 只在操作特定檔案時自動 load。

🤖

Auto Mode

claude --enable-auto-mode to start. Background safety classifier replaces manual permission prompts.

effort Adjustment

/effort low|medium|high|max to adjust thinking depth.max requires Opus 4.6.

🔄

/compact — Compress Conversation

When context is nearly full, use /compact to compress. Add focus:/compact keep API content

Common CLI Startup Flags

FlagShortDescription
--continue-cContinue most recent conversation
--resume-rResume specific session
--model <NAME>Specify model (sonnet, opus, haiku)
--print-pNon-interactive output (headless / SDK)
--permission-modedefault、plan、acceptEdits、bypassPermissions
--allowedToolsTools allowed without permission prompts清單
--add-dir <path>Add working directory to session
--worktreeRun in git worktree
--enable-auto-modeEnable Auto Mode (beta)

7. Installation & Getting Started

Three steps to start using Claude Code.

Terminal
# 1. Install Claude Code
npm install -g @anthropic-ai/claude-code

# 2. Navigate to your project
cd your-project

# 3. Start Claude Code
claude

Quick Reference

🚀 Basic Operations

claude                # Start interactive mode
claude -c             # Continue last conversation
claude -r             # Resume specific session
claude -p "問題"     # One-shot Q&A
claude /init          # Initialize CLAUDE.md

⚙️ Advanced Operations

claude --model opus   # Specify model
claude --worktree     # Git worktree isolation
claude --enable-auto-mode  # Auto Mode
/context               # Check context usage
/compact               # Compress conversation
/effort max            # Maximum thinking depth
💡 808AI Recommendation

First time? Run claude /init to create CLAUDE.md and write your project conventions in it.
This is the highest ROI step — Claude remembers your preferences, making every conversation more precise.

💬 Join the 808 AI Tool Shop LINE Community 🟢 Join