BeClaude
GuideBeginnerBest Practices2026-05-22

Building with Claude: A Practical Guide to the Anthropic Cookbook

Learn how to use the Anthropic Cookbook to build Claude-powered applications. Covers setup, code style, model selection, and project structure for developers.

Quick Answer

This guide walks you through the Anthropic Cookbook repository — a collection of Jupyter notebooks and Python examples for building with the Claude API. You'll learn how to set up the environment, follow code conventions, choose the right Claude model, and navigate the project structure to accelerate your development.

Claude APICookbookDevelopment WorkflowBest PracticesPython

Building with Claude: A Practical Guide to the Anthropic Cookbook

If you're building applications with Claude, you need more than just the API reference — you need real, working examples that demonstrate best practices. That's exactly what the Anthropic Cookbook provides. This repository is a curated collection of Jupyter notebooks and Python examples that show you how to implement everything from basic classification to advanced tool use and multimodal processing.

In this guide, I'll walk you through how to get started with the Cookbook, understand its structure, follow its conventions, and apply its patterns to your own Claude-powered projects.

Getting Started with the Cookbook

Before you can run any of the examples, you need to set up your environment. The Cookbook uses uv — a fast Python package manager — to manage dependencies.

Step 1: Clone the Repository

git clone https://github.com/anthropics/anthropic-cookbook.git
cd anthropic-cookbook

Step 2: Install Dependencies

The Cookbook uses uv sync to install all required packages, including optional extras:

uv sync --all-extras

This command reads the pyproject.toml file and installs everything you need, from the Anthropic SDK to libraries for vector databases and image processing.

Step 3: Set Up Your API Key

cp .env.example .env

Then edit the .env file and add your ANTHROPIC_API_KEY. Never commit this file — it's already in .gitignore, but always double-check before pushing.

Step 4: Install Pre-commit Hooks (Optional but Recommended)

uv run pre-commit install

This ensures your code meets the project's formatting and linting standards before every commit.

Development Commands You'll Use Daily

The Cookbook provides a Makefile with convenient shortcuts. Here are the most important ones:

CommandWhat It Does
make formatFormats all Python code with Ruff
make lintRuns Ruff linting checks
make checkRuns format-check + lint together
make fixAuto-fixes lint issues and formats
make testRuns pytest test suite
If you prefer working directly with uv, the equivalent commands are:
uv run ruff format .           # Format all files
uv run ruff check .            # Lint all files
uv run ruff check --fix .      # Auto-fix issues
uv run pre-commit run --all-files  # Run all pre-commit hooks

Code Style and Conventions

Consistency matters when you're collaborating or sharing examples. The Cookbook enforces a clean, readable style:

  • Line length: 100 characters (not the traditional 88)
  • Quotes: Double quotes everywhere
  • Formatter: Ruff (replaces Black and Flake8)
Notebooks get a bit more flexibility. They allow:
  • Mid-file imports (E402) — useful for demonstrating concepts step by step
  • Function redefinitions (F811) — common in exploratory notebooks
  • Relaxed variable naming (N803, N806) — so you can use descriptive names without linting errors

A Quick Example

Here's how a typical code cell in a Cookbook notebook might look:

import os
from dotenv import load_dotenv
from anthropic import Anthropic

load_dotenv() client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))

response = client.messages.create( model="claude-sonnet-4-6", max_tokens=1024, messages=[ {"role": "user", "content": "Explain the Cookbook in one sentence."} ] )

print(response.content[0].text)

Notice the use of double quotes and the non-dated model alias — both are required conventions.

Choosing the Right Claude Model

One of the most important rules in the Cookbook is never use dated model IDs. Instead, always use the non-dated alias. This ensures your code automatically uses the latest version of the model.

API Model IDs

ModelAlias to Use
Sonnetclaude-sonnet-4-6
Haikuclaude-haiku-4-5
Opusclaude-opus-4-6
Don't do this:
model="claude-sonnet-4-6-20250514"  # Wrong! Dated ID
Do this instead:
model="claude-sonnet-4-6"  # Correct! Non-dated alias

Bedrock Model IDs

If you're using Claude through AWS Bedrock, the model IDs follow a different format. Here are the current ones:

# Opus 4.6
model_id = "global.anthropic.claude-opus-4-6-v1"

Sonnet 4.5

model_id = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"

Haiku 4.5

model_id = "global.anthropic.claude-haiku-4-5-20251001-v1:0"

Note that Bedrock models before Opus 4.6 require dated IDs in their Bedrock model ID. Always check docs.anthropic.com for the latest versions.

Navigating the Project Structure

The Cookbook is organized into clear directories, each focusing on a different capability:

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

This structure makes it easy to find exactly what you need. Building a RAG application? Head to capabilities/. Working with images? Check multimodal/. Need to integrate with a vector database? Look in third_party/.

Adding Your Own Cookbook

Once you're comfortable with the patterns, you might want to contribute your own notebook. Here's the process:

  • Create your notebook in the appropriate directory (e.g., capabilities/my_classifier.ipynb)
  • Add an entry to registry.yaml with:
- Title - Description - Path to the notebook - Author(s) - Categories
  • Add author info to authors.yaml if you're a new contributor
  • Run quality checks with make check
  • Submit a PR following the conventional commit format

Commit Message Format

The Cookbook uses conventional commits:

feat(capabilities): add text classifier notebook
fix(tool_use): correct API endpoint in weather example
docs: update README with new model versions
style: apply ruff formatting

Branch names follow the pattern <username>/<feature-description>.

Quality Checks and Slash Commands

Before submitting any changes, run make check to ensure everything is clean. The pre-commit hooks will validate:

  • Code formatting (Ruff)
  • Notebook structure
  • Model references
  • Link validity
Claude Code users can also use these slash commands:

  • /notebook-review — Reviews notebook quality
  • /model-check — Validates Claude model references in your code
  • /link-review — Checks links in changed files

Key Takeaways

  • Use the Cookbook as your starting point for any Claude integration — it contains battle-tested examples for RAG, tool use, multimodal processing, and more.
  • Always use non-dated model aliases (e.g., claude-sonnet-4-6) to ensure your code stays up-to-date with the latest model versions.
  • Follow the code conventions — double quotes, 100-character line length, Ruff formatting — to keep your code consistent with the ecosystem.
  • Run make check before every commit to catch formatting issues, broken links, and invalid model references early.
  • Contribute back by adding notebooks to the appropriate directory and registering them in registry.yaml — the community grows stronger with every shared example.