The Complete Guide to Building with Claude: From Cookbook Setup to Production Patterns
Learn how to set up the Anthropic Cookbook environment, use Claude API best practices, and follow professional development workflows for building AI applications.
This guide walks you through setting up the Anthropic Cookbook repository, configuring your development environment with uv and Ruff, understanding Claude model aliases, and following professional coding standards for building Claude-powered applications.
The Complete Guide to Building with Claude: From Cookbook Setup to Production Patterns
If you're serious about building applications with Claude, the Anthropic Cookbook is your essential starting point. This official repository contains a collection of Jupyter notebooks and Python examples that demonstrate everything from basic API usage to advanced patterns like tool use, multimodal processing, and extended thinking.
But here's the thing: the Cookbook isn't just a collection of examples—it's a professional development environment with strict coding standards, validation tools, and workflows designed for production-quality AI applications. In this guide, I'll walk you through everything you need to know to set up, navigate, and contribute to the Anthropic Cookbook like a pro.
Getting Started: Environment Setup
Before you can run any of the cookbook examples, you need to set up your local environment. The Cookbook uses uv—a fast Python package manager—to handle dependencies.
Step 1: Install Dependencies
# Clone the repository first, then:
uv sync --all-extras
This command installs all required packages including Jupyter, the Anthropic SDK, and all third-party integrations (Pinecone, Voyage AI, Wikipedia API, etc.).
Step 2: Configure Your API Key
# Copy the example environment file
cp .env.example .env
Edit .env and add your ANTHROPIC_API_KEY
Critical rule: Never commit your .env file to version control. The repository is configured to ignore it, but always double-check. In your code, access the key like this:
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("ANTHROPIC_API_KEY")
Step 3: Install Pre-commit Hooks
uv run pre-commit install
This ensures every commit is automatically checked for formatting and structural issues.
Development Commands You'll Use Daily
The Cookbook provides a Makefile with convenient shortcuts, but you can also run commands directly with uv.
Using Make (Recommended)
make format # Auto-format all Python files with Ruff
make lint # Check for linting errors
make check # Run format-check + lint together
make fix # Auto-fix issues + format
make test # Run pytest suite
Using uv Directly
uv run ruff format . # Format code
uv run ruff check . # Lint code
uv run ruff check --fix . # Auto-fix lint issues
uv run pre-commit run --all-files # Run all pre-commit checks
Code Style: The Ruff Standard
The Cookbook enforces a consistent code style using Ruff, a fast Python linter and formatter. Here are the key rules:
- Line length: 100 characters (not the standard 88)
- Quotes: Double quotes everywhere
- Formatter: Ruff (replaces Black and isort)
- Mid-file imports are allowed (E402 suppressed)
- Variable redefinitions are permitted (F811 suppressed)
- Variable naming conventions are looser (N803, N806 suppressed)
Claude Model IDs: Use Aliases, Not Dates
One of the most important best practices in the Cookbook is never using dated model IDs. Instead, always use the non-dated alias. This ensures your code automatically uses the latest version of each model.
Correct API Usage
# ✅ CORRECT: Use non-dated aliases
model = "claude-sonnet-4-6"
model = "claude-haiku-4-5"
model = "claude-opus-4-6"
❌ WRONG: Never use dated IDs
model = "claude-sonnet-4-6-20250514" # Bad!
Bedrock Model IDs
If you're using Claude through AWS Bedrock, the model IDs follow a different format:
# Opus 4.6
model = "anthropic.claude-opus-4-6-v1"
Sonnet 4.5
model = "anthropic.claude-sonnet-4-5-20250929-v1:0"
Haiku 4.5
model = "anthropic.claude-haiku-4-5-20251001-v1:0"
For global endpoints (recommended)
model = "global.anthropic.claude-opus-4-6-v1"
Note: Bedrock models before Opus 4.6 require dated IDs. Always check docs.anthropic.com for the latest model IDs.
Project Structure: Where to Find What
The Cookbook is organized into clear directories, each focusing on a specific 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
extended_thinking/ # Extended reasoning patterns
misc/ # Batch processing, caching, utilities
third_party/ # Pinecone, Voyage, Wikipedia integrations
scripts/ # Validation scripts
.claude/ # Claude Code commands and skills
Slash Commands: Built-in Quality Tools
The Cookbook includes custom slash commands for Claude Code and CI pipelines:
/notebook-review— Reviews notebook quality/model-check— Validates Claude model references (ensures no dated IDs)/link-review— Checks links in changed files
.claude/ directory and can be run directly in Claude Code.
Git Workflow: Professional Standards
Branch Naming
<username>/<feature-description>
Example: johndoe/add-rag-notebook
Commit Messages (Conventional Commits)
feat(scope): add new feature
fix(scope): fix bug
docs(scope): update documentation
style: lint/format
Pre-commit Checklist
Before committing, always run:
make check
This runs format checking and linting. If you have issues, run make fix to auto-resolve them.
Adding a New Cookbook Notebook
If you want to contribute a new example, follow this workflow:
- Create your notebook in the appropriate directory (e.g.,
capabilities/,tool_use/) - Keep outputs — Notebooks should demonstrate results, so keep cell outputs intact
- One concept per notebook — Don't cram multiple ideas into one file
- Test top-to-bottom — Ensure the notebook runs without errors from start to finish
- Add to registry — Edit
registry.yamlwith:
- Update authors — If you're a new contributor, add your info to
authors.yaml - Run quality checks — Execute
make checkand fix any issues - Submit a PR — Follow the branch naming and commit conventions
Practical Example: Your First Cookbook Script
Here's a minimal example that follows all the Cookbook standards:
"""Example: Basic Claude API call following Cookbook standards."""
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", # Using alias, not dated ID
max_tokens=1024,
messages=[
{"role": "user", "content": "Explain the Cookbook setup process in one sentence."}
]
)
print(response.content[0].text)
Key Takeaways
- Always use model aliases (e.g.,
claude-sonnet-4-6) instead of dated IDs to ensure your code stays current with the latest Claude versions. - Set up the full development environment with
uv sync --all-extrasand pre-commit hooks to catch issues early. - Run
make checkbefore every commit to enforce code quality standards (Ruff formatting, linting, notebook structure). - Follow the Cookbook's project structure when adding new examples—place notebooks in the correct directory and register them in
registry.yaml. - Use slash commands (
/notebook-review,/model-check,/link-review) to automate quality checks in Claude Code and CI pipelines.