這個快速開始指南將讓您在短短幾分鐘內使用 AI 驅動的編程輔助。完成後,您將了解如何使用 Claude Code 進行常見的開發任務。

開始之前

確保您有:

  • 打開的終端或命令提示符
  • 要使用的代碼項目

步驟 1:安裝 Claude Code

NPM 安裝

如果您已經安裝了 Node.js 18 或更新版本

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

原生安裝

或者,試試我們新的原生安裝,現在處於測試階段。

macOS、Linux、WSL:

curl -fsSL claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

步驟 2:開始您的第一個會話

在任何項目目錄中打開您的終端並啟動 Claude Code:

cd /path/to/your/project
claude

您將在新的互動會話中看到 Claude Code 提示符:

✻ 歡迎使用 Claude Code!

...

> 試試 "create a util logging.py that..." 

您的憑證安全地存儲在您的系統上。在憑證管理中了解更多。

步驟 3:提出您的第一個問題

讓我們從了解您的代碼庫開始。試試這些命令之一:

> what does this project do?

Claude 將分析您的文件並提供摘要。您也可以提出更具體的問題:

> what technologies does this project use?
> where is the main entry point?
> explain the folder structure

您也可以詢問 Claude 關於其自身能力的問題:

> what can Claude Code do?
> how do I use slash commands in Claude Code?
> can Claude Code work with Docker?

Claude Code 會根據需要讀取您的文件 - 您不必手動添加上下文。Claude 還可以訪問其自己的文檔,並可以回答有關其功能和能力的問題。

步驟 4:進行您的第一次代碼更改

現在讓我們讓 Claude Code 做一些實際的編程工作。試試一個簡單的任務:

> add a hello world function to the main file

Claude Code 將:

  1. 找到適當的文件
  2. 向您展示建議的更改
  3. 請求您的批准
  4. 進行編輯

Claude Code 在修改文件之前總是請求許可。您可以批准個別更改或為會話啟用「全部接受」模式。

步驟 5:在 Claude Code 中使用 Git

Claude Code 使 Git 操作變得對話化:

> what files have I changed?
> commit my changes with a descriptive message

您也可以提示更複雜的 Git 操作:

> create a new branch called feature/quickstart
> show me the last 5 commits
> help me resolve merge conflicts

步驟 6:修復錯誤或添加功能

Claude 擅長調試和功能實現。

用自然語言描述您想要的:

> add input validation to the user registration form

或修復現有問題:

> there's a bug where users can submit empty forms - fix it

Claude Code 將:

  • 定位相關代碼
  • 理解上下文
  • 實現解決方案
  • 如果可用則運行測試

步驟 7:測試其他常見工作流程

有多種方式與 Claude 合作:

重構代碼

> refactor the authentication module to use async/await instead of callbacks

編寫測試

> write unit tests for the calculator functions

更新文檔

> update the README with installation instructions

代碼審查

> review my changes and suggest improvements

記住:Claude Code 是您的 AI 結對程序員。像與有用的同事交談一樣與它交談 - 描述您想要實現的目標,它將幫助您達到目標。

基本命令

以下是日常使用最重要的命令:

命令功能示例
claude啟動互動模式claude
claude "task"運行一次性任務claude "fix the build error"
claude -p "query"運行一次性查詢,然後退出claude -p "explain this function"
claude -c繼續最近的對話claude -c
claude -r恢復之前的對話claude -r
claude commit創建 Git 提交claude commit
/clear清除對話歷史> /clear
/help顯示可用命令> /help
exit 或 Ctrl+C退出 Claude Code> exit

查看CLI 參考獲取完整的命令列表。

初學者專業提示

下一步是什麼?

現在您已經學會了基礎知識,探索更高級的功能:

獲取幫助

  • 在 Claude Code 中:輸入 /help 或詢問「how do I…」
  • 文檔:您就在這裡!瀏覽其他指南
  • 社區:加入我們的 Discord 獲取提示和支持