/ 目录 / 演练场 / Anthropic Cookbook
● 官方 anthropics ⚡ 即开即用

Anthropic Cookbook

作者 anthropics · anthropics/anthropic-cookbook

Anthropic 官方 Claude 配方书——缓存、批处理、RAG、agent、多模态、引用——附可运行 notebook。

anthropics/anthropic-cookbook 是 Claude API 的官方配方合集。每个配方都是一个专注的 notebook:prompt 缓存、消息批处理、agent 循环、带引用的 RAG、多模态视觉、分类和评估。作为 skill 资源使用,让 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

添加 prompt 缓存以降低 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.✓ 已复制
    → 缓存的系统 prompt;费用预测
  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 变化可能需要两行代码修改

生产环境缓存命中率为 0

缓存 key 对内容敏感;哪怕一个 token 不同就会 miss。稳定前缀。

替代方案

Anthropic Cookbook 对比其他方案

替代方案何时用它替代权衡
anthropics/anthropic-quickstarts你想要完整应用,不想要配方不同粒度
anthropics/courses你想要教学法,不想要实现理论 vs 实践

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills