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

開始之前

確保您有:

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

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

cd /path/to/your/project
claude

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

✻ Welcome to Claude Code!

...

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

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

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

> what does this project do?

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

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

Claude Code 會根據需要讀取您的文件 - 您不必手動添加上下文。

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

現在讓我們讓 Claude Code 進行一些實際的編程。嘗試一個簡單的任務:

> add a hello world function to the main file

Claude Code 將:

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

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

步驟 4:將 Git 與 Claude Code 一起使用

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

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

Claude 精通調試和功能實現。

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

> add input validation to the user registration form

或修復現有問題:

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

Claude Code 將:

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

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

有多種方式與 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

初學者專業提示

下一步是什麼?

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

獲得幫助

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