/ 目錄 / 演練場 / Anthropic Cookbook
● 官方 anthropics ⚡ 即開即用

Anthropic Cookbook

作者 anthropics · anthropics/anthropic-cookbook

Anthropic 官方 Claude 食譜書——快取、批次處理、RAG、代理、多模態、引用——附帶可執行的 notebook。

anthropics/anthropic-cookbook 是 Claude API 的官方食譜集。每個食譜都是一個專注的 notebook:提示快取、訊息批次處理、代理迴圈、帶引用的 RAG、多模態視覺、分類和評估。作為技能資源使用,讓 Claude 的實作建議能以測試過的範例為基礎。

為什麼要用

核心特性

即時演示

實際使用效果

就緒

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "anthropic-cookbook-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/anthropics/anthropic-cookbook",
        "~/.claude/skills/anthropic-cookbook"
      ],
      "_inferred": true
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "anthropic-cookbook-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/anthropics/anthropic-cookbook",
        "~/.claude/skills/anthropic-cookbook"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "anthropic-cookbook-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/anthropics/anthropic-cookbook",
        "~/.claude/skills/anthropic-cookbook"
      ],
      "_inferred": true
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "anthropic-cookbook-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/anthropics/anthropic-cookbook",
        "~/.claude/skills/anthropic-cookbook"
      ],
      "_inferred": true
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "anthropic-cookbook-skill",
      "command": "git",
      "args": [
        "clone",
        "https://github.com/anthropics/anthropic-cookbook",
        "~/.claude/skills/anthropic-cookbook"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "anthropic-cookbook-skill": {
      "command": {
        "path": "git",
        "args": [
          "clone",
          "https://github.com/anthropics/anthropic-cookbook",
          "~/.claude/skills/anthropic-cookbook"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add anthropic-cookbook-skill -- git clone https://github.com/anthropics/anthropic-cookbook ~/.claude/skills/anthropic-cookbook

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: Anthropic Cookbook

新增提示快取以降低 Claude API 費用

👤 在正式環境執行 Claude 的工程師 ⏱ ~60 min intermediate

何時使用: API 費用不斷上升,且每個請求都有重複的上下文。

步驟
  1. 閱讀食譜
    Use anthropic-cookbook. Show me the prompt caching pattern for repeated system prompts.✓ 已複製
    → cache_control 範例
  2. 套用到我的程式碼
    Adapt to my service that re-sends a 5k-token style guide every call.✓ 已複製
    → 快取的系統提示;費用預測
  3. 驗證節省效果
    Measure cache hit rate and cost delta over 100 calls.✓ 已複製
    → 具體的費用降低

結果: 真正的費用節省(快取部分約 50-80%)。

注意事項
  • 快取生命週期短——高流量工作負載受益最大 — 低流量 API 可能看不到命中;優化前先校準
搭配使用: anthropic-courses-skill

將離線評分工作移到訊息批次處理,降低 50% 費用

👤 執行大規模評估/分類工作的團隊 ⏱ ~45 min intermediate

何時使用: 工作是非同步的,且你有超過 100 個呼叫。

步驟
  1. 使用批次食譜
    Apply batching from the cookbook to my classification job.✓ 已複製
    → 顯示批次端點整合
  2. 驗證完成和費用
    Compare batched cost vs sync for 1000 prompts.✓ 已複製
    → 費用降低約 50%

結果: 更便宜的離線工作負載,相同的精確度。

建立能正確引用來源的 RAG 系統

👤 在文件上建構問答系統的開發者 ⏱ ~90 min intermediate

何時使用: 用戶會質疑答案;你需要他們可以驗證的引用。

步驟
  1. 採用引用模式
    Use the citations recipe. Apply to my doc set.✓ 已複製
    → 答案參照來源 ID
  2. 新增內聯連結
    Map source IDs to URLs so users can click through.✓ 已複製
    → 帶連結的引用

結果: 帶有稽核記錄的可信 RAG。

組合

與其他 MCP 搭配,撬動十倍槓桿

anthropic-cookbook-skill + anthropic-courses-skill

食譜 = 實踐,課程 = 理論

anthropic-cookbook-skill + anthropic-quickstarts-skill

應用骨架 + cookbook 食譜

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
(notebook recipes) natural lookup 面對已知的 Claude 模式時 0

成本與限制

運行它的成本

API 配額
食譜呼叫 API——執行時使用費用適用
每次呼叫 Token 數
每個食譜不同
費用
免費(MIT)
提示
開發期間使用 Sonnet;只在需要時切換到 Opus

安全

權限、密鑰、影響範圍

最小權限: anthropic-api-key
憑證儲存: ANTHROPIC_API_KEY 存於環境變數
資料出站: Anthropic API

故障排查

常見錯誤與修復

食譜使用舊版 SDK

升級 anthropic SDK;細微的 API 變更可能需要 2 行更新

正式環境中快取命中顯示為 0

快取鍵是內容敏感的;即使一個 token 不同也會造成未命中。穩定前綴。

替代方案

Anthropic Cookbook 對比其他方案

替代方案何時用它替代權衡
anthropics/anthropic-quickstarts你想要完整應用,而非食譜不同粒度
anthropics/courses你想要教學法,而非實作理論 vs 實踐

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills