BeClaude
Guide2026-04-21

How to Contribute to the Claude Cookbook: A Complete Developer Guide

Learn how to set up your development environment, follow quality standards, and submit successful contributions to the official Claude Cookbook repository with this practical guide.

Quick Answer

This guide walks you through contributing to the Claude Cookbook, covering environment setup with uv, notebook best practices, quality checks with Claude slash commands, and the Git workflow for submitting successful pull requests.

claude-cookbookopen-sourcedevelopmentcontributingnotebooks

How to Contribute to the Claude Cookbook: A Complete Developer Guide

The Claude Cookbook is an invaluable resource for developers working with Claude AI, providing practical examples, tutorials, and implementation patterns. Contributing to this repository not only helps the broader Claude community but also deepens your understanding of Claude's capabilities. This comprehensive guide walks you through the entire contribution process, from setting up your development environment to submitting polished pull requests.

Setting Up Your Development Environment

Before you start contributing, you'll need to properly configure your development environment. The Claude Cookbook uses modern Python tooling to ensure consistency and quality across all contributions.

Prerequisites and Installation

First, ensure you have Python 3.11 or higher installed. The repository strongly recommends using uv, a fast Python package manager and resolver, for dependency management.

# Install uv (recommended method)
curl -LsSf https://astral.sh/uv/install.sh | sh

Or install with Homebrew on macOS

brew install uv

Once uv is installed, clone the repository and set up your environment:

# Clone the repository
git clone https://github.com/anthropics/anthropic-cookbook.git
cd anthropic-cookbook

Create virtual environment and install all dependencies

uv sync --all-extras

Install pre-commit hooks for automatic quality checks

uv run pre-commit install

Set up your API key for testing

cp .env.example .env

Edit .env and add your ANTHROPIC_API_KEY

If you prefer using pip instead of uv, you can set up the environment with:

pip install -e ".[dev]"
pre-commit install

The --all-extras flag ensures you install all development dependencies, including tools for notebook validation, linting, and testing.

Understanding the Quality Standards

The Claude Cookbook maintains high quality standards through an automated validation stack. Understanding these standards is crucial for creating contributions that will be accepted.

The Notebook Validation Stack

The repository uses three key tools to ensure notebook quality:

  • nbconvert: Executes notebooks to verify they run without errors
  • ruff: A fast Python linter and formatter with native Jupyter notebook support
  • Claude AI Review: Intelligent code review using Claude itself
Important Note: Unlike many repositories that clear notebook outputs, the Claude Cookbook intentionally keeps outputs in notebooks. These outputs demonstrate expected results to users and serve as documentation of what successful execution looks like.

Claude Code Slash Commands

One of the most powerful features for contributors is the built-in Claude slash commands. These commands work both locally in Claude Code and in GitHub Actions CI, ensuring consistent validation across environments.

The repository includes these essential commands:

  • /link-review: Validates links in markdown files and notebooks
  • /model-check: Verifies that Claude model usage references current models
  • /notebook-review: Comprehensive notebook quality check
You can use these commands directly in your terminal when working with the repository:
# Run comprehensive notebook review
/notebook-review skills/my-notebook.ipynb

Check model usage across the repository

/model-check

Validate links in documentation

/link-review README.md

These commands use the exact same validation logic as the CI pipeline, helping you catch issues before pushing your code. The command definitions are stored in .claude/commands/ and are automatically available when you work in this repository with Claude Code.

Notebook Best Practices for Contributors

Creating effective cookbook notebooks requires following specific guidelines to ensure they're useful, maintainable, and educational.

API Key Management

Always use environment variables for API keys to keep notebooks secure and portable:

import os
from anthropic import Anthropic

Correct: Use environment variables

api_key = os.environ.get("ANTHROPIC_API_KEY") client = Anthropic(api_key=api_key)

Avoid hardcoding API keys

client = Anthropic(api_key="your-key-here") # Don't do this!

Model Selection Guidelines

Use current Claude models and follow these practices:

# Use model aliases when available for better maintainability
model = "claude-haiku-4-5"  # Latest Haiku model

For other models, reference the current documentation

Check: https://docs.claude.com/en/docs/about-claude/models/overview

model = "claude-3-5-sonnet-20241022"

Claude will automatically validate model usage in PR reviews

response = client.messages.create( model=model, max_tokens=1000, messages=[{"role": "user", "content": "Hello, Claude!"}] )

Notebook Structure and Content

Follow these structural guidelines for effective notebooks:

  • One concept per notebook: Keep notebooks focused on a single technique or use case
  • Clear explanations: Include markdown cells that explain the "why" behind the code
  • Expected outputs: Show what successful execution looks like
  • Error handling: Include examples of common errors and how to handle them
  • Minimal tokens: Use small examples for API calls to conserve tokens
Here's an example of a well-structured notebook section:
# Example: Text classification with Claude
import pandas as pd

Load example data

data = [ {"text": "I love this product!", "label": "positive"}, {"text": "Terrible experience, would not recommend", "label": "negative"}, {"text": "It's okay, nothing special", "label": "neutral"} ] df = pd.DataFrame(data)

Demonstrate classification with minimal tokens

for text in df['text'][:2]: # Limit to 2 examples response = client.messages.create( model="claude-haiku-4-5", max_tokens=50, messages=[{ "role": "user", "content": f"Classify this sentiment: '{text}'" }] ) print(f"Text: {text}") print(f"Claude's classification: {response.content[0].text}") print("-" * 50)

The Git Workflow for Contributions

Following a structured Git workflow ensures your contributions integrate smoothly with the repository.

Branching and Committing

Start by creating a descriptive feature branch:

# Create a new branch with your name and feature description
git checkout -b alice/add-rag-example

Or: git checkout -b bob/fix-api-key-docs

Use conventional commits for clear commit messages:

# Commit format: <type>(<scope>): <subject>

git commit -m "feat(skills): add retrieval-augmented-generation example" git commit -m "fix(api): use environment variable for API key in all examples" git commit -m "docs(readme): update installation instructions for uv" git commit -m "test(validation): add notebook execution test"

Commit types to use:
  • feat: New feature or notebook
  • fix: Bug fix
  • docs: Documentation changes
  • style: Formatting changes
  • refactor: Code restructuring
  • test: Adding or updating tests
  • chore: Maintenance tasks
  • ci: CI/CD changes

Running Quality Checks Before Committing

Before you commit your changes, run these quality checks:

# Format and lint Python code in notebooks
uv run ruff check skills/ --fix
uv run ruff format skills/

Validate notebook structure

uv run python scripts/validate_notebooks.py

Optional: Test notebook execution (requires API key)

uv run jupyter nbconvert --to notebook \ --execute skills/your-notebook.ipynb \ --ExecutePreprocessor.kernel_name=python3 \ --output test_output.ipynb

The pre-commit hooks will automatically run when you commit, but running these checks manually first helps catch issues early.

Creating Your Pull Request

Once your changes are ready and tested:

# Push your branch to GitHub
git push -u origin your-branch-name

Create a pull request (using GitHub CLI)

gh pr create

Or use the GitHub web interface

Pull Request Requirements:
  • Title: Use conventional commit format (e.g., "feat(skills): Add text-to-SQL notebook")
  • Description: Clearly explain what you changed and why
  • Linked Issues: Reference any related issues
  • Testing: Mention any testing you performed

Testing Your Contributions

Thorough testing ensures your notebooks work correctly and provide value to users.

Notebook Execution Testing

Test that your notebook runs from top to bottom without errors:

# Add this test cell at the end of your notebook

This verifies all imports work and basic functionality is intact

import sys print(f"Python version: {sys.version}")

Test Anthropic client initialization (without making API calls)

try: from anthropic import Anthropic client = Anthropic() print("✓ Anthropic client initialized successfully") except Exception as e: print(f"✗ Error initializing client: {e}")

Verify environment variables are used

import os if os.environ.get("ANTHROPIC_API_KEY"): print("✓ API key found in environment") else: print("⚠ API key not set in environment (expected for CI)")

Minimal Token Usage

When creating examples, use minimal tokens to keep costs low and execution fast:

# Good: Minimal example
response = client.messages.create(
    model="claude-haiku-4-5",
    max_tokens=100,  # Keep it small
    messages=[{
        "role": "user", 
        "content": "Summarize in one sentence: Artificial intelligence..."
    }]
)

Avoid: Unnecessarily long examples

response = client.messages.create(

model="claude-3-5-sonnet-20241022",

max_tokens=4000, # Too large for an example

messages=[...]

)

Common Pitfalls and How to Avoid Them

Based on frequent issues in contributions, watch out for these common problems:

  • Hardcoded API keys: Always use environment variables
  • Outdated model references: Check the current models documentation
  • Missing dependencies: Ensure all imports are documented
  • Overly complex examples: Keep notebooks focused and simple
  • Missing error handling: Show how to handle common errors
  • Inconsistent formatting: Let ruff handle formatting automatically

Key Takeaways

  • Use uv for dependency management to ensure consistency with the repository's tooling and benefit from faster package installation
  • Leverage Claude slash commands (/notebook-review, /model-check, /link-review) to validate your contributions using the same checks that run in CI
  • Follow notebook best practices: use environment variables for API keys, reference current Claude models, keep examples minimal, and maintain clear notebook structure
  • Adhere to the Git workflow: create descriptive branches, use conventional commits, and provide comprehensive PR descriptions
  • Test thoroughly: ensure notebooks execute completely, use minimal tokens in examples, and verify all dependencies are properly documented
By following this guide, you'll create high-quality contributions that enhance the Claude Cookbook and help the entire Claude developer community. Your well-structured, tested notebooks will serve as valuable learning resources for developers exploring Claude's capabilities.

Ready to contribute? Clone the repository, set up your environment, and start exploring the existing notebooks to understand the patterns and standards. The Claude Cookbook team welcomes contributions that demonstrate innovative uses of Claude AI while following the quality standards outlined in this guide.