Your Complete Guide to the Anthropic Cookbook: Building with Claude AI
Learn how to set up, develop, and contribute to the Anthropic Cookbook repository. Includes setup instructions, code style rules, model best practices, and workflow tips for Claude API projects.
This guide walks you through setting up the Anthropic Cookbook repository, understanding its structure, following code style rules, using correct Claude model IDs, and contributing new cookbook notebooks.
Your Complete Guide to the Anthropic Cookbook: Building with Claude AI
If you're serious about building applications with Claude AI, the Anthropic Cookbook is one of the most valuable resources available. It's a curated collection of Jupyter notebooks and Python examples that demonstrate everything from basic API usage to advanced patterns like tool use, multimodal processing, and extended reasoning.
But the cookbook isn't just about reading code—it's about building. Whether you're contributing your own notebook or simply running the examples locally, understanding the project's structure, conventions, and workflow is essential. This guide covers everything you need to get started.
What Is the Anthropic Cookbook?
The Anthropic Cookbook is an open-source repository maintained by Anthropic. It contains practical, runnable examples organized by capability and use case. Each notebook is designed to demonstrate one clear concept, making it easy to learn and adapt for your own projects.
The cookbook covers:
- Core capabilities: RAG, classification, summarization
- Advanced skills: Agentic patterns, extended thinking
- Tool use: Function calling and integration patterns
- Multimodal: Vision and image processing with Claude
- Third-party integrations: Pinecone, Voyage AI, Wikipedia
- Utilities: Batch processing, caching, and more
Setting Up the Cookbook Locally
Before you can run any notebooks, you need to set up the development environment. The cookbook uses uv (a fast Python package manager) and Ruff for formatting and linting.
Step 1: Clone the Repository
git clone https://github.com/anthropics/anthropic-cookbook.git
cd anthropic-cookbook
Step 2: Install Dependencies
uv sync --all-extras
This installs all required packages, including Jupyter, the Anthropic SDK, and third-party libraries.
Step 3: Install Pre-commit Hooks
uv run pre-commit install
Pre-commit hooks automatically check your code for formatting and structural issues before each commit.
Step 4: Set Up Your API Key
cp .env.example .env
Then edit .env and add your ANTHROPIC_API_KEY. Never commit your .env file—it's already in .gitignore.
In your notebooks, load the key like this:
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("ANTHROPIC_API_KEY")
Understanding the Code Style
The cookbook enforces consistent code style to keep notebooks clean and maintainable. Here are the key rules:
| Rule | Standard |
|---|---|
| Line length | 100 characters |
| Quotes | Double quotes (") |
| Formatter | Ruff |
- Mid-file imports (E402)
- Redefinitions (F811)
- Variable naming (N803, N806)
Running Quality Checks
Before submitting any changes, run the full quality check suite:
make check
Or use uv directly:
uv run ruff format . # Format code
uv run ruff check . # Lint
uv run ruff check --fix . # Auto-fix issues
uv run pre-commit run --all-files
Claude Model Best Practices
One of the most important rules in the cookbook is never use dated model IDs. Always use the non-dated alias. This ensures your code stays compatible as Anthropic releases updates.
Correct Model IDs (API)
| Model | Correct ID |
|---|---|
| Sonnet | claude-sonnet-4-6 |
| Haiku | claude-haiku-4-5 |
| Opus | claude-opus-4-6 |
claude-sonnet-4-6-20250514 (dated)
Correct Model IDs (Bedrock)
Bedrock model IDs follow a different format. Always check the latest docs, but here's the current pattern:
| Model | Bedrock ID |
|---|---|
| Opus 4.6 | anthropic.claude-opus-4-6-v1 |
| Sonnet 4.5 | anthropic.claude-sonnet-4-5-20250929-v1:0 |
| Haiku 4.5 | anthropic.claude-haiku-4-5-20251001-v1:0 |
global.:
model_id = "global.anthropic.claude-opus-4-6-v1"
Note: Bedrock models before Opus 4.6 require dated IDs.
Example: Making an API Call
import anthropic
client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
message = client.messages.create(
model="claude-sonnet-4-6", # Never use dated IDs
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain the Anthropic Cookbook in one sentence."}
]
)
print(message.content[0].text)
Git Workflow and Commit Conventions
The cookbook follows a clean Git workflow with conventional commits.
Branch Naming
<username>/<feature-description>
Example: jdoe/add-rag-notebook
Commit Format
Use conventional commits for clarity:
feat(scope): add new feature
fix(scope): fix bug
docs(scope): update documentation
style: lint/format
Examples:
feat(tool_use): add weather API integration notebookdocs(capabilities): fix typo in RAG examplestyle: apply ruff formatting
Project Structure
The cookbook is organized into clear directories:
capabilities/ # Core Claude capabilities (RAG, classification, etc.)
skills/ # Advanced skill-based notebooks
tool_use/ # Tool use and integration patterns
multimodal/ # Vision and image processing
misc/ # Batch processing, caching, utilities
third_party/ # Pinecone, Voyage, Wikipedia integrations
extended_thinking/ # Extended reasoning patterns
scripts/ # Validation scripts
.claude/ # Claude Code commands and skills
How to Add a New Cookbook Notebook
Contributing a new notebook is straightforward. Follow these steps:
1. Create Your Notebook
Place it in the appropriate directory. For example, a tool-use notebook goes in tool_use/.
- Keep outputs in the notebook (they're intentional for demonstration)
- One concept per notebook
- Test that the notebook runs top-to-bottom without errors
2. Register the Notebook
Add an entry to registry.yaml with:
title: Clear, descriptive titledescription: Brief summarypath: Relative path to the notebookauthors: Your name (or GitHub handle)categories: One or more relevant categories
3. Add Author Info (If New Contributor)
If you're a first-time contributor, add your details to authors.yaml.
4. Run Quality Checks
make check
This validates formatting, notebook structure, and model references.
5. Submit a PR
Push your branch and open a pull request against the main repository.
Slash Commands for Claude Code
The cookbook includes custom slash commands for Claude Code and CI:
/notebook-review— Review notebook quality/model-check— Validate Claude model references/link-review— Check links in changed files
.claude/ directory and make it easy to automate quality checks.
Practical Tips for Working with the Cookbook
1. Use Virtual Environments
While uv handles dependencies, it's still good practice to work in a clean environment. The uv sync command creates a virtual environment automatically.
2. Keep Dependencies Clean
Never edit pyproject.toml directly. Instead, use:
uv add <package> # For runtime dependencies
uv add --dev <package> # For development dependencies
3. Test Notebooks Thoroughly
Before committing, restart the kernel and run the notebook from top to bottom. This ensures all cells execute correctly in sequence.
4. Follow the One-Concept Rule
Each notebook should demonstrate exactly one concept. If you find yourself explaining multiple ideas, split them into separate notebooks.
Conclusion
The Anthropic Cookbook is more than just a collection of examples—it's a community resource for learning and building with Claude AI. By following the setup instructions, code style rules, and contribution guidelines in this guide, you'll be able to run existing notebooks, create your own, and contribute back to the ecosystem.
Whether you're exploring tool use, multimodal processing, or extended reasoning, the cookbook provides a solid foundation. Start by cloning the repo, running a few notebooks, and soon you'll be building your own Claude-powered applications.
Key Takeaways
- Set up correctly: Use
uv sync --all-extrasand pre-commit hooks to ensure a clean development environment. - Never use dated model IDs: Always use non-dated aliases like
claude-sonnet-4-6for API calls. - Follow the code style: Ruff formatting, double quotes, and 100-character line limits keep notebooks consistent.
- One concept per notebook: Keep notebooks focused and test them top-to-bottom before committing.
- Contribute responsibly: Register notebooks in
registry.yaml, runmake check, and use conventional commits for PRs.