Claude Code Tips

Claude Code的實用指令

初始架構

/init 分析當前專案目錄,自動偵測技術棧並建立基礎設定。

掃描整個 codebase,在專案根目錄生成 CLAUDE.md(如果已存在則更新),內容包含:

  • 技術架構摘要(Next.js、Prisma、TypeScript…)
  • 常用指令(npm run build:frontendnpm run build:backend…)
  • 專案慣例(DB 讀寫分離規則、資料夾結構…)
  • Claude 每次開新 session 會自動讀取它,不需要重新說明背景

如何安裝Claude Code CLI

透過 PowerShell

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

安裝完成後關閉PowerShell,並重新開啟,執行 claude 即可啟動

若出現 claude is not recognized 錯誤,手動加入 PATH

[Environment]::SetEnvironmentVariable("PATH", "$env:PATH;$env:USERPROFILE\.local\bin", [EnvironmentVariableTarget]::User)

以上,即完成安裝。

程式碼審查

/review 對當前檔案或 Git 變更進行代碼品質審查。

/undo (或 /rewind): 撤銷上一步 AI 所做的代碼修改。

/iterate

technical-writing-improver.SKILL.md

# SKILL.md using Iterative Refinement pattern
# Example technical-writing-improver skill

You improve technical writing through iterative refinement.
Your workflow has explicit quality gates at each iteration.

## Iteration 1: Structural review
- Read the draft and check overall structure
- Verify introduction states the problem clearly
- Check sections follow logical flow
- Ensure conclusion summarizes key points
- Score structure 1-10 and explain reasoning

## Iteration 2: Clarity review
- For each paragraph check readability score
- Identify sentences with Flesch-Kincaid above grade 12
- Suggest simpler phrasings without losing accuracy
- Score clarity 1-10 and list improvements

## Iteration 3: Technical accuracy
- Verify all code examples compile and run
- Check API references against current documentation
- Validate command flags and options exist
- Cross-reference version numbers
- Flag any factual errors found

## Iteration 4: Examples and context
- Every technical concept should have example
- Examples should use realistic data not foo bar
- Add common pitfalls section if missing
- Check external links are not broken

## Validation script for each iteration
Run `scripts/validate-markdown.py content.md`
- Reports issues and blocks progression if severity high
- Provides numeric score for tracking

## Stop iterating when
- All iterations reach score 8+
- No validation script failures
- User approves quality gate

Do not iterate indefinitely.
Maximum 5 total iterations.

使用方式:/iterate improve docs/content.md using technical-writing-improver

執行流程:

  1. Claude載入SKILL.md(Progressive Disclosure,只在相關時載入)。
  2. Iteration 1:結構審查,得分9/10,輸出改版content.md。
  3. 執行validate-markdown.py,若通過進Iteration 2;否則重試。
  4. 依序進行至所有階段≥8分,或達5次上限停止。
  5. 總Token成本預測性高(每階段固定),品質優於單次prompt。

Token節省

/plan 進入「計畫模式」,只進行邏輯規劃而不實際修改代碼(節省 Token)。

/exit_plan 部分版本支援直接輸入指令退出計畫模式並返回一般模式。

/rewind 如果你發現計畫大錯特錯,可以用此指令回到計畫前的狀態重新開始。

/clear 完成任務後,可以透過這個指令清除之前的Context。

/compact 壓縮當前對話歷史,釋放上下文空間(Context Window)。

/effort low:

/effort high:

/btw:討論中,如果有想要詢問其他議題,可以透過這個指令避免這個討論被加入session memory。

GitHub – forrestchang/andrej-karpathy-skills
A single CLAUDE.md file to improve Claude Code behavior, derived from Andrej Karpathy’s observations on LLM coding pitfalls. · GitHub