SpyBara
Go Premium

common-workflows.md 2026-06-09 06:34 UTC to 2026-06-10 23:57 UTC

65 added, 21 removed.

2026
Sat 27 01:01 Fri 26 23:00 Thu 25 23:58 Wed 24 22:02 Tue 23 22:00 Mon 22 23:59 Fri 19 22:58 Thu 18 22:00 Wed 17 17:02 Tue 16 21:57 Mon 15 23:02 Sat 13 21:59 Fri 12 22:00 Thu 11 23:01 Wed 10 23:57 Tue 9 06:34 Mon 8 06:52 Sat 6 06:24 Fri 5 06:45 Thu 4 06:52 Wed 3 06:53 Tue 2 06:51

常見工作流程

使用 Claude Code 探索程式碼庫、修復錯誤、重構、測試和其他日常任務的逐步指南。

本頁涵蓋日常開發的簡短食譜。如需更高層級的提示和背景資訊管理指導,請參閱最佳實踐

本頁涵蓋:

提示食譜

這些是日常任務的提示模式,例如探索陌生程式碼、除錯、重構、編寫測試和建立 PR。每個都可在任何 Claude Code 介面中工作;根據您的專案調整措辭。

了解新的程式碼庫

如需在 monorepo 或大型程式碼庫中配置 Claude Code,請參閱 Monorepos 和大型儲存庫

快速取得程式碼庫概覽

假設您剛加入一個新專案,需要快速了解其結構。

1

導航到專案根目錄

cd /path/to/project 
2

啟動 Claude Code

claude 
3

要求高層級概覽

give me an overview of this codebase
4

深入探討特定元件

explain the main architecture patterns used here
what are the key data models?
how is authentication handled?

尋找相關程式碼

假設您需要找到與特定功能或功能相關的程式碼。

1

要求 Claude 尋找相關檔案

find the files that handle user authentication
2

取得元件如何互動的背景資訊

how do these authentication files work together?
3

了解執行流程

trace the login process from front-end to database

有效地修復錯誤

假設您遇到了錯誤訊息,需要找到並修復其來源。

1

與 Claude 分享錯誤

I'm seeing an error when I run npm test
2

要求修復建議

suggest a few ways to fix the @ts-ignore in user.ts
3

應用修復

update user.ts to add the null check you suggested

重構程式碼

假設您需要更新舊程式碼以使用現代模式和實踐。

1

識別用於重構的舊版程式碼

find deprecated API usage in our codebase
2

取得重構建議

suggest how to refactor utils.js to use modern JavaScript features
3

安全地應用變更

refactor utils.js to use ES2024 features while maintaining the same behavior
4

驗證重構

run tests for the refactored code

使用測試

假設您需要為未涵蓋的程式碼新增測試。

1

識別未測試的程式碼

find functions in NotificationsService.swift that are not covered by tests
2

產生測試框架

add tests for the notification service
3

新增有意義的測試案例

add test cases for edge conditions in the notification service
4

執行並驗證測試

run the new tests and fix any failures

Claude 可以產生遵循您專案現有模式和慣例的測試。要求測試時,請明確說明您想驗證的行為。Claude 會檢查您現有的測試檔案,以符合已在使用的風格、框架和斷言模式。

為了獲得全面的涵蓋範圍,要求 Claude 識別您可能遺漏的邊界情況。Claude 可以分析您的程式碼路徑,並建議測試錯誤條件、邊界值和容易忽視的意外輸入。


建立提取請求

您可以直接要求 Claude 建立提取請求(「為我的變更建立 pr」),或逐步引導 Claude 完成:

1

總結您的變更

summarize the changes I've made to the authentication module
2

產生提取請求

create a pr
3

檢查並細化

enhance the PR description with more context about the security improvements

當您使用 gh pr create 建立 PR 時,會話會自動連結到該 PR。要稍後返回它,請執行 claude --from-pr <number> 或將 PR URL 貼到/resume 選擇器搜尋中。

處理文件

假設您需要為程式碼新增或更新文件。

1

識別未記錄的程式碼

find functions without proper JSDoc comments in the auth module
2

產生文件

add JSDoc comments to the undocumented functions in auth.js
3

檢查並增強

improve the generated documentation with more context and examples
4

驗證文件

check if the documentation follows our project standards

在筆記和非程式碼資料夾中工作

Claude Code 可在任何目錄中工作。在筆記保管庫、文件資料夾或任何 markdown 檔案集合中執行它,以搜尋、編輯和重新組織內容,就像您處理程式碼一樣。

.claude/ 目錄和 CLAUDE.md 與其他工具的配置目錄並存,不會產生衝突。Claude 在每次工具呼叫時都會重新讀取檔案,所以它會在下次讀取該檔案時看到您在另一個應用程式中所做的編輯。


使用影像

假設您需要在程式碼庫中使用影像,並希望 Claude 幫助分析影像內容。

1

將影像新增到對話中

您可以使用以下任何方法:

  1. 將影像拖放到 Claude Code 視窗中
  2. 複製影像並使用 ctrl+v 將其貼到 CLI 中(不要使用 cmd+v)
  3. 向 Claude 提供影像路徑。例如,「分析此影像:/path/to/your/image.png」
2

要求 Claude 分析影像

What does this image show?
Describe the UI elements in this screenshot
Are there any problematic elements in this diagram?
3

使用影像作為背景資訊

Here's a screenshot of the error. What's causing it?
This is our current database schema. How should we modify it for the new feature?
4

從視覺內容取得程式碼建議

Generate CSS to match this design mockup
What HTML structure would recreate this component?

參考檔案和目錄

使用 @ 快速包含檔案或目錄,無需等待 Claude 讀取它們。

1

參考單個檔案

Explain the logic in @src/utils/auth.js

這會在對話中包含檔案的完整內容。

2

參考目錄

What's the structure of @src/components?

這提供了帶有檔案資訊的目錄清單。

3

參考 MCP 資源

Show me the data from @github:repos/owner/repo/issues

這使用 @server:resource 格式從連接的 MCP 伺服器取得資料。有關詳細資訊,請參閱 MCP 資源


按排程執行 Claude

假設您想讓 Claude 自動定期處理任務,例如每天早上檢查開放 PR、每週審計依賴項或在夜間檢查 CI 失敗。

根據您想讓任務執行的位置選擇排程選項:

選項 執行位置 最適合
Routines Anthropic 管理的基礎設施 應該在您的電腦關閉時執行的任務。也可以由 API 呼叫或 GitHub 事件觸發,除了排程。在 claude.ai/code/routines 配置。
桌面排程任務 您的機器,通過桌面應用 需要直接存取本地檔案、工具或未提交變更的任務。
GitHub Actions 您的 CI 管道 與儲存庫事件(如開啟的 PR)相關的任務,或應與工作流程配置一起存在的 cron 排程。
/loop 當前 CLI 會話 會話開啟時的快速輪詢。任務在您開始新對話時停止;--resume--continue 恢復未過期的任務。

詢問 Claude 其功能

Claude 內建存取其文件,可以回答有關其自身功能和限制的問題。

範例問題

can Claude Code create pull requests?
how does Claude Code handle permissions?
what skills are available?
how do I use MCP with Claude Code?
how do I configure Claude Code for Amazon Bedrock?
what are the limitations of Claude Code?

繼續之前的對話

當任務跨越多個會話時,從您停止的地方繼續,而不是重新解釋背景資訊。Claude Code 在本地儲存每個對話。

claude --continue

這會繼續當前目錄中最近的會話;如果還沒有,它會列印 No conversation found to continue 並退出。使用 claude --resume 從清單中選擇,或從執行中的會話內使用 /resume。有關命名、分支和完整選擇器參考,請參閱管理會話

使用 worktrees 執行平行會話

在一個終端中處理功能,同時 Claude 在另一個終端中修復錯誤,而不會編輯衝突。每個 worktree 是其自己分支上的單獨簽出。

claude --worktree feature-auth

在第二個終端中使用不同的名稱執行相同的命令以啟動隔離的平行會話。有關清理、.worktreeinclude 和非 git VCS 支援,請參閱 Worktrees。要從一個螢幕而不是單獨的終端監視平行會話,請參閱背景代理

編輯前規劃

對於您想在變更觸及磁碟前檢查的變更,切換到 plan mode。Claude 讀取檔案並提出計畫,但在您批准前不進行編輯。

claude --permission-mode plan

您也可以在會話期間按 Shift+Tab 切換到 plan mode。有關批准流程和在文字編輯器中編輯計畫,請參閱 Plan mode

將研究委派給 subagents

探索大型程式碼庫會用檔案讀取填滿您的背景資訊。委派探索,以便只有發現結果返回。

use a subagent to investigate how our auth system handles token refresh

subagent 在其自己的背景資訊視窗中讀取檔案並報告摘要。有關定義具有自己工具和提示的自訂代理,請參閱 Subagents

將 Claude 管道輸入指令碼

以非互動方式執行 Claude,用於 CI、提交前 hooks 或批次處理。Stdin 和 stdout 像任何 Unix 工具一樣工作。

git log --oneline -20 | claude -p "summarize these recent commits"

有關輸出格式、權限標誌和扇出模式,請參閱非互動模式

後續步驟