BeClaude
Guide2026-04-19

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 step-by-step guide.

Quick Answer

This guide walks you through contributing to the Claude Cookbook repository. You'll learn how to set up your development environment, follow quality standards using automated tools, create effective notebooks, and submit pull requests that meet Anthropic's contribution guidelines.

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, offering practical examples, tutorials, and implementation patterns. As an open-source project, it thrives on community contributions. This comprehensive guide walks you through everything you need to know to contribute effectively, 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, though traditional pip is also supported.

Installing uv (Recommended):
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

Or with Homebrew on macOS

brew install uv
Cloning and Setting Up the Repository:
# Clone the repository
git clone https://github.com/anthropics/anthropic-cookbook.git
cd anthropic-cookbook

Set up the development environment with uv

uv sync --all-extras

Alternative with pip

pip install -e ".[dev]"
Configuring Pre-commit Hooks:

Pre-commit hooks automatically run quality checks before each commit, ensuring your code meets repository standards:

uv run pre-commit install

Or simply: pre-commit install

Setting Up Your API Key:

For testing notebooks that make API calls, you'll need to configure your Anthropic API key:

cp .env.example .env

Edit .env and add: ANTHROPIC_API_KEY=your_key_here

Always use environment variables for API keys in your notebooks:

import os
api_key = os.environ.get("ANTHROPIC_API_KEY")

Use the API key in your Claude client initialization

Understanding the Quality Standards

The Claude Cookbook maintains high quality through an automated validation stack. Understanding these tools will help you create contributions that pass review on the first try.

The Notebook Validation Stack

The repository uses three key tools to ensure quality:

  • nbconvert: Executes notebooks for testing to ensure 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, the Claude Cookbook intentionally keeps notebook outputs in the repository. These outputs demonstrate expected results to users, so don't clear them unless you're making substantive changes to the outputs themselves.

Claude Code Slash Commands

One of the most powerful features for contributors is the built-in Claude Code slash commands. These commands work both locally in Claude Code and in GitHub Actions CI, using the exact same validation logic.

Available Commands:
  • /link-review - Validates links in markdown and notebooks
  • /model-check - Verifies Claude model usage is current
  • /notebook-review - Comprehensive notebook quality check
Using Slash Commands in Claude Code:
# Run the same validations that CI will run
/notebook-review skills/my-notebook.ipynb
/model-check
/link-review README.md

The command definitions are stored in .claude/commands/, making them automatically available when you work in this repository with Claude Code. These commands help you catch issues before pushing, saving time during the review process.

Running Quality Checks Manually

Before committing 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

Test notebook execution (requires API key)

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

The pre-commit hooks will run these checks automatically, but running them manually first helps you fix issues proactively.

Creating Effective Notebook Contributions

Notebooks are the primary content type in the Claude Cookbook. Following these best practices will ensure your contributions are valuable and maintainable.

Notebook Structure and Content

  • Keep Notebooks Focused: Each notebook should demonstrate one clear concept or technique. Avoid combining multiple unrelated topics.
  • Use Current Claude Models: Always reference current Claude models. Use model aliases when available for better maintainability:
# Good - uses current model reference
client = anthropic.Anthropic(api_key=api_key)
response = client.messages.create(
    model="claude-haiku-4-5",  # Latest Haiku model
    max_tokens=1000,
    messages=[{"role": "user", "content": "Hello, Claude!"}]
)

Check the Claude models documentation for current model names. The repository's automated checks will flag outdated model references.

  • Include Clear Explanations: Use markdown cells to explain what each code cell does, why you're using specific approaches, and what users should expect to see.
  • Test Thoroughly: Ensure your notebook runs from top to bottom without errors. Use minimal tokens for example API calls to conserve resources and include basic error handling.

Example Notebook Structure

Here's a template for a well-structured cookbook notebook:

# Cell 1: Import and setup
import os
import anthropic
from dotenv import load_dotenv

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

Cell 2: Markdown explanation

"""

Text Classification with Claude

This notebook demonstrates how to use Claude for text classification tasks. We'll show a simple example of categorizing customer feedback. """

Cell 3: Example implementation

feedback = "The product works great but delivery was slow."

response = client.messages.create( model="claude-haiku-4-5", max_tokens=100, messages=[{ "role": "user", "content": f"Categorize this feedback: '{feedback}'\n\nCategories: Product Quality, Shipping, Customer Service, Pricing" }] )

print(response.content[0].text)

Git Workflow and Contribution Process

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

Branching and Committing

  • Create a Feature Branch: Always work in a dedicated branch:
git checkout -b <your-name>/<feature-description>

Example: git checkout -b alice/add-rag-example

  • Use Conventional Commits: Follow the conventional commits specification for clear commit messages:
# Format: <type>(<scope>): <subject>

Examples:

git commit -m "feat(skills): add text-to-sql notebook" git commit -m "fix(api): use environment variable for API key" git commit -m "docs(readme): update installation instructions"

Common types:

feat - New feature

fix - Bug fix

docs - Documentation

style - Formatting

refactor - Code restructuring

test - Tests

chore - Maintenance

ci - CI/CD changes

  • Keep Commits Atomic: Each commit should represent one logical change. This makes reviewing easier and helps with debugging if issues arise.

Creating a Pull Request

Once your changes are ready:

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

Create a pull request (if you have GitHub CLI)

gh pr create
Pull Request Requirements:
  • Title: Use conventional commit format
  • Description: Clearly explain:
- What changes you made - Why you made them (the problem they solve) - Any testing you performed
  • Linked Issues: Reference any related issues using GitHub's issue linking syntax (e.g., "Fixes #123")

Testing Your Contributions

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

Notebook Testing Checklist

Before submitting your contribution, verify:

  • [ ] Notebook executes from top to bottom without errors
  • [ ] API calls use minimal tokens for examples
  • [ ] Environment variables are used for sensitive data
  • [ ] Model references are current
  • [ ] Outputs are meaningful and demonstrate the concept
  • [ ] Markdown explanations are clear and helpful
  • [ ] Code follows Python best practices

Running the Full Test Suite

For complex contributions, run the complete validation suite:

# Run all quality checks
uv run pre-commit run --all-files

Validate all notebooks

uv run python scripts/validate_notebooks.py --all

Check links in documentation

uv run python scripts/check_links.py

Common Pitfalls and How to Avoid Them

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

  • Outdated Model References: Always check the latest model names in the Claude documentation.
  • Hardcoded API Keys: Never commit notebooks with hardcoded API keys. Always use environment variables.
  • Overly Complex Examples: Keep examples simple and focused. Users should be able to understand and adapt them quickly.
  • Missing Explanations: Don't assume users understand why you're using a particular approach. Explain your reasoning.
  • Not Testing Execution: Always test that your notebook runs completely. A notebook that fails halfway through is frustrating for users.

Getting Help and Community Resources

If you encounter issues or have questions:

  • Check Existing Issues: Search the repository's issues to see if your question has already been addressed.
  • Review Existing Notebooks: Look at similar notebooks in the repository for patterns and approaches.
  • Use the Validation Tools: The slash commands and pre-commit hooks often provide helpful error messages.
  • Be Specific in Issues: When reporting problems, include:
- What you're trying to do - What you expected to happen - What actually happened - Relevant code snippets - Your environment details

Key Takeaways

  • Use the recommended tooling: Set up your environment with uv and pre-commit hooks to ensure consistency with the repository's standards.
  • Leverage Claude Code slash commands: Use /notebook-review, /model-check, and /link-review to validate your contributions before submission, catching issues early.
  • Follow notebook best practices: Create focused notebooks with clear explanations, current model references, environment variables for API keys, and tested execution from start to finish.
  • Adopt the git workflow: Use feature branches, conventional commits, and atomic changes to make your contributions easy to review and integrate.
  • Test thoroughly: Always verify your notebooks execute completely and provide the expected outputs before submitting your pull request.
By following this guide, you'll be well-equipped to contribute valuable examples and tutorials to the Claude Cookbook, helping the entire Claude developer community build better AI applications.