# Repository: anthropics/claude-cookbooks # Stars: 40890 ## CLAUDE.md # Claude Cookbooks A collection of Jupyter notebooks and Python examples for building with the Claude API. ## Quick Start ```bash # Install dependencies uv sync --all-extras # Install pre-commit hooks uv run pre-commit install # Set up API key cp .env.example .env # Edit .env and add your ANTHROPIC_API_KEY ``` ## Development Commands ```bash make format # Format code with ruff make lint # Run linting make check # Run format-check + lint make fix # Auto-fix issues + format make test # Run pytest ``` Or directly with uv: ```bash uv run ruff format . # Format uv run ruff check . # Lint uv run ruff check --fix . # Auto-fix uv run pre-commit run --all-files ``` ## Code Style - **Line length:** 100 characters - **Quotes:** Double quotes - **Formatter:** Ruff Notebooks have relaxed rules for mid-file imports (E402), redefinitions (F811), and variable naming (N803, N806). ## Git Workflow **Branch naming:** `/` **Commit format (conventional commits):** ``` feat(scope): add new feature fix(scope): fix bug docs(scope): update documentation style: lint/format ``` ## Key Rules 1. **API Keys:** Never commit `.env` files. Use `dotenv.load_dotenv()` then access keys via `os.environ` or `os.getenv()` 2. **Dependencies:** Use `uv add ` or `uv add --dev `. Never edit pyproject.toml directly. 3. **Models:** Use current Claude models. Check docs.anthropic.com for latest versions. - Sonnet: `claude-sonnet-4-6` - Haiku: `claude-haiku-4-5` - Opus: `claude-opus-4-6` - **Never use dated model IDs** (e.g., `claude-sonnet-4-6-20250514`). Always use the non-dated alias. - **Bedrock model IDs** follow a different format. Use the base Bedrock model ID from the docs: - 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` - Prepend `global.` for global endpoints (recommended): `global.anthropic.claude-opus-4-6-v1` - Note: Bedrock models before Opus 4.6 require dated IDs in their Bedrock model ID. 4. **Notebooks:** - Keep outputs in notebooks (intentional for demonstration) - One concept per notebook - Test that notebooks run top-to-bottom without errors 5. **Quality checks:** Run `make check` before committing. Pre-commit hooks validate formatting and notebook structure. ## Slash Commands These commands are available in Claude Code and CI: - `/notebook-review` - Review notebook quality - `/model-check` - Validate Claude model references - `/link-review` - Check links in changed files ## Project Structure ``` 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 ``` ## Adding a New Cookbook 1. Create notebook in the appropriate directory 2. Add entry to `registry.yaml` with title, description, path, authors, categories 3. Add author info to `authors.yaml` if new contributor 4. Run quality checks and submit PR ## README.md # Claude Cookbooks The Claude Cookbooks provide code and guides designed to help developers build with Claude, offering copy-able code snippets that you can easily integrate into your own projects. ## Prerequisites To make the most of the examples in this cookbook, you'll need a Claude API key (sign up for free [here](https://www.anthropic.com)). While the code examples are primarily written in Python, the concepts can be adapted to any programming language that supports interaction with the Claude API. If you're new to working with the Claude API, we recommend starting with our [Claude API Fundamentals course](https://github.com/anthropics/courses/tree/master/anthropic_api_fundamentals) to get a solid foundation. ## Explore Further Looking for more resources to enhance your experience with Claude and AI assistants? Check out these helpful links: - [Anthropic developer documentation](https://docs.claude.com/claude/docs/guide-to-anthropics-prompt-engineering-resources) - [Anthropic support docs](https://support.anthropic.com) - [Anthropic Discord community](https://www.anthropic.com/discord) ## Contributing The Claude Cookbooks thrives on the contributions of the developer community. We value your input, whether it's submitting an idea, fixing a typo, adding a new guide, or improving an existing one. By contributing, you help make this resource even more valuable for everyone. To avoid duplication of efforts, please review the existing issues and pull requests before contributing. If you have ideas for new examples or guides, share them on the [issues page](https://github.com/anthropics/anthropic-cookbook/issues). ## Table of recipes ### Capabilities - [Classification](https://github.com/anthropics/anthropic-cookbook/tree/main/capabilities/classification): Explore techniques for text and data classification using Claude. - [Retrieval Augmented Generation](https://github.com/anthropics/anthropic-cookbook/tree/main/capabilities/retrieval_augmented_generation): Learn how to enhance Claude's responses with external knowledge. - [Summarization](https://github.com/anthropics/anthropic-cookbook/tree/main/capabilities/summarization): Discover techniques for effective text summarization with Claude. ### Tool Use and Integration - [Tool use](https://github.com/anthropics/anthropic-cookbook/tree/main/tool_use): Learn how to integrate Claude with external tools and functions to extend its capabilities. - [Customer service agent](https://github.com/anthropics/anthropic-cookbook/blob/main/tool_use/customer_service_agent.ipynb) - [Calculator integration](https://github.com/anthropics/anthropic-cookbook/blob/main/tool_use/calculator_tool.ipynb) - [SQL queries](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/how_to_make_sql_queries.ipynb) ### Third-Party Integrations - [Retrieval augmented generation](https://github.com/anthropics/anthropic-cookbook/tree/main/third_party): Supplement Claude's knowledge with external data sources. - [Vector databases (Pinecone)](https://github.com/anthropics/anthropic-cookbook/blob/main/third_party/Pinecone/rag_using_pinecone.ipynb) - [Wikipedia](https://github.com/anthropics/anthropic-cookbook/blob/main/third_party/Wikipedia/wikipedia-search-cookbook.ipynb/) - [Web pages](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/read_web_pages_with_haiku.ipynb) - [Embeddings with Voyage AI](https://github.com/anthropics/anthropic-cookbook/blob/main/third_party/VoyageAI/how_to_create_embeddings.md) ### Multimodal Capabilities - [Vision with Claude](https://github.com/anthropics/anthropic-cookbook/tree/main/multimodal): - [Getting started with images](https://github.com/anthropics/anthropic-cookbook/blob/main/multimodal/getting_started_with_vision.ipynb) - [Best practices for vision](https://github.com/anthropics/anthropic-cookbook/blob/main/multimodal/best_practices_for_vision.ipynb) - [Interpreting charts and graphs](https://github.com/anthropics/anthropic-cookbook/blob/main/multimodal/reading_charts_graphs_powerpoints.ipynb) - [Extracting content from forms](https://github.com/anthropics/anthropic-cookbook/blob/main/multimodal/how_to_transcribe_text.ipynb) - [Generate images with Claude](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/illustrated_responses.ipynb): Use Claude with Stable Diffusion for image generation. ### Advanced Techniques - [Sub-agents](https://github.com/anthropics/anthropic-cookbook/blob/main/multimodal/using_sub_agents.ipynb): Learn how to use Haiku as a sub-agent in combination with Opus. - [Upload PDFs to Claude](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/pdf_upload_summarization.ipynb): Parse and pass PDFs as text to Claude. - [Automated evaluations](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/building_evals.ipynb): Use Claude to automate the prompt evaluation process. - [Enable JSON mode](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/how_to_enable_json_mode.ipynb): Ensure consistent JSON output from Claude. - [Create a moderation filter](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/building_moderation_filter.ipynb): Use Claude to create a content moderation filter for your application. - [Prompt caching](https://github.com/anthropics/anthropic-cookbook/blob/main/misc/prompt_caching.ipynb): Learn techniques for efficient prompt caching with Claude. ## Additional Resources - [Anthropic on AWS](https://github.com/aws-samples/anthropic-on-aws): Explore examples and solutions for using Claude on AWS infrastructure. - [AWS Samples](https://github.com/aws-samples/): A collection of code samples from AWS which can be adapted for use with Claude. Note that some samples may require modification to work optimally with Claude.