Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ed9b068
Renames skills to capabilities in preparation for skills cookbook
zealoushacker Oct 14, 2025
76f028d
Adds .env.example file
zealoushacker Oct 14, 2025
2feff76
Complete Skills Cookbook Notebook 1 with working examples
zealoushacker Oct 15, 2025
49665ed
Initial implementation of Notebook 2: Financial Applications
zealoushacker Oct 15, 2025
3907b7e
Update implementation tracker for Notebook 2 completion
zealoushacker Oct 15, 2025
6453205
Add Notebook 3: Custom Skills Development
zealoushacker Oct 15, 2025
9a5cf95
Fix quarterly_metrics.json structure for Notebook 2 compatibility
zealoushacker Oct 15, 2025
df54708
Clean up and improve flow in Notebook 2: Financial Applications
zealoushacker Oct 15, 2025
c95569a
Update cookbook plan: Mark Notebook 2 as complete with cleanup
zealoushacker Oct 15, 2025
b4aa547
Merge branch 'zh/skills-cookbook-notebook3' into zh/skills-cookbook
zealoushacker Oct 15, 2025
25c789c
Improve Notebook 3: Enhanced skill versioning workflow and complete e…
zealoushacker Oct 15, 2025
4f98f6d
Update Skills notebooks based on review feedback (P0 items)
zealoushacker Oct 15, 2025
b17c98b
Add Claude Creates Files links prominently across documentation
zealoushacker Oct 15, 2025
a638f38
refactor(skills): rename custom skills to follow gerund naming conven…
zealoushacker Oct 16, 2025
9b71759
docs: update all best practices references to link to official docume…
zealoushacker Oct 16, 2025
bbd5f89
docs(skills): add engineering blog post and support articles
zealoushacker Oct 16, 2025
b336891
Merge pull request #6 from anthropics/zh/skills-cookbook
zealoushacker Oct 16, 2025
7913e8f
Merge branch 'main' of github.com:anthropics/claude-cookbooks
zealoushacker Oct 16, 2025
3ddc4e0
Merge pull request #215 from anthropics/zh/sync-skills-cookbook
zealoushacker Oct 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions capabilities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Claude Capabilities

Welcome to the Capabilities section of the Claude Cookbooks! This directory contains a collection of guides that showcase specific capabilities where Claude excels. Each guide provides an in-depth exploration of a particular capability, discussing potential use cases, prompt engineering techniques to optimize results, and approaches for evaluating Claude's performance.

## Guides

- **[Classification with Claude](./classification/guide.ipynb)**: Discover how Claude can revolutionize classification tasks, especially in scenarios with complex business rules and limited training data. This guide walks you through data preparation, prompt engineering with retrieval-augmented generation (RAG), testing, and evaluation.

- **[Retrieval Augmented Generation with Claude](./retrieval_augmented_generation/guide.ipynb)**: Learn how to enhance Claude's capabilities with domain-specific knowledge using RAG. This guide demonstrates how to build a RAG system from scratch, optimize its performance, and create an evaluation suite. You'll learn how techniques like summary indexing and re-ranking can significantly improve precision, recall, and overall accuracy in question-answering tasks.

- **[Retrieval Augmented Generation with Contextual Embeddings](./contextual-embeddings/guide.ipynb)**: Learn how to use a new technique to improve the performance of your RAG system. In traditional RAG, documents are typically split into smaller chunks for efficient retrieval. While this approach works well for many applications, it can lead to problems when individual chunks lack sufficient context. Contextual Embeddings solve this problem by adding relevant context to each chunk before embedding. You'll learn how to use contextual embeddings with semantic search, BM25 search, and reranking to improve performance.

- **[Summarization with Claude](./summarization/guide.ipynb)**: Explore Claude's ability to summarize and synthesize information from multiple sources. This guide covers a variety of summarization techniques, including multi-shot, domain-based, and chunking methods, as well as strategies for handling long-form content and multiple documents. We also explore evaluating summaries, which can be a balance of art, subjectivity, and the right approach!

- **[Text-to-SQL with Claude](./text_to_sql/guide.ipynb)**: This guide covers how to generate complex SQL queries from natural language using prompting techniques, self-improvement, and RAG. We'll also explore how to evaluate and improve the accuracy of generated SQL queries, with evals that test for syntax, data correctness, row count, and more.

## Getting Started

To get started with these guides, simply navigate to the desired guide's directory and follow the instructions provided in the `guide.ipynb` file. Each guide is self-contained and includes all the necessary code, data, and evaluation scripts to reproduce the examples and experiments.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,7 @@
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Enhancing RAG with Contextual Retrieval\n",
"\n",
"> Note: For more background information on Contextual Retrieval, including additional performance evaluations on various datasets, we recommend reading our accompanying [blog post](https://www.anthropic.com/news/contextual-retrieval).\n",
"\n",
"Retrieval Augmented Generation (RAG) enables Claude to leverage your internal knowledge bases, codebases, or any other corpus of documents when providing a response. Enterprises are increasingly building RAG applications to improve workflows in customer support, Q&A over internal company documents, financial & legal analysis, code generation, and much more.\n",
"\n",
"In a [separate guide](https://github.com/anthropics/anthropic-cookbook/blob/main/skills/retrieval_augmented_generation/guide.ipynb), we walked through setting up a basic retrieval system, demonstrated how to evaluate its performance, and then outlined a few techniques to improve performance. In this guide, we present a technique for improving retrieval performance: Contextual Embeddings.\n",
"\n",
"In traditional RAG, documents are typically split into smaller chunks for efficient retrieval. While this approach works well for many applications, it can lead to problems when individual chunks lack sufficient context. Contextual Embeddings solve this problem by adding relevant context to each chunk before embedding. This method improves the quality of each embedded chunk, allowing for more accurate retrieval and thus better overall performance. Averaged across all data sources we tested, Contextual Embeddings reduced the top-20-chunk retrieval failure rate by 35%.\n",
"\n",
"The same chunk-specific context can also be used with BM25 search to further improve retrieval performance. We introduce this technique in the “Contextual BM25” section.\n",
"\n",
"In this guide, we'll demonstrate how to build and optimize a Contextual Retrieval system using a dataset of 9 codebases as our knowledge base. We'll walk through:\n",
"\n",
"1) Setting up a basic retrieval pipeline to establish a baseline for performance.\n",
"\n",
"2) Contextual Embeddings: what it is, why it works, and how prompt caching makes it practical for production use cases.\n",
"\n",
"3) Implementing Contextual Embeddings and demonstrating performance improvements.\n",
"\n",
"4) Contextual BM25: improving performance with *contextual* BM25 hybrid search.\n",
"\n",
"5) Improving performance with reranking,\n",
"\n",
"### Evaluation Metrics & Dataset:\n",
"\n",
"We use a pre-chunked dataset of 9 codebases - all of which have been chunked according to a basic character splitting mechanism. Our evaluation dataset contains 248 queries - each of which contains a 'golden chunk.' We'll use a metric called Pass@k to evaluate performance. Pass@k checks whether or not the 'golden document' was present in the first k documents retrieved for each query. Contextual Embeddings in this case helped us to improve Pass@10 performance from ~87% --> ~95%.\n",
"\n",
"You can find the code files and their chunks in `data/codebase_chunks.json` and the evaluation dataset in `data/evaluation_set.jsonl`\n",
"\n",
"#### Additional Notes:\n",
"\n",
"Prompt caching is helpful in managing costs when using this retrieval method. This feature is currently available on Anthropic's 1P API, and is coming soon to our 3P partner environments in AWS Bedrock and GCP Vertex. We know that many of our customers leverage AWS Knowledge Bases and GCP Vertex AI APIs when building RAG solutions, and this method can be used on either platform with a bit of customization. Consider reaching out to Anthropic or your AWS/GCP account team for guidance on this!\n",
"\n",
"To make it easier to use this method on Bedrock, the AWS team has provided us with code that you can use to implement a Lambda function that adds context to each document. If you deploy this Lambda function, you can select it as a custom chunking option when configuring a [Bedrock Knowledge Base](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-create.html). You can find this code in `contextual-rag-lambda-function`. The main lambda function code is in `lambda_function.py`.\n",
"\n",
"## Table of Contents\n",
"\n",
"1) Setup\n",
"\n",
"2) Basic RAG\n",
"\n",
"3) Contextual Embeddings\n",
"\n",
"4) Contextual BM25\n",
"\n",
"5) Reranking"
]
"source": "# Enhancing RAG with Contextual Retrieval\n\n> Note: For more background information on Contextual Retrieval, including additional performance evaluations on various datasets, we recommend reading our accompanying [blog post](https://www.anthropic.com/news/contextual-retrieval).\n\nRetrieval Augmented Generation (RAG) enables Claude to leverage your internal knowledge bases, codebases, or any other corpus of documents when providing a response. Enterprises are increasingly building RAG applications to improve workflows in customer support, Q&A over internal company documents, financial & legal analysis, code generation, and much more.\n\nIn a [separate guide](https://github.com/anthropics/anthropic-cookbook/blob/main/capabilities/retrieval_augmented_generation/guide.ipynb), we walked through setting up a basic retrieval system, demonstrated how to evaluate its performance, and then outlined a few techniques to improve performance. In this guide, we present a technique for improving retrieval performance: Contextual Embeddings.\n\nIn traditional RAG, documents are typically split into smaller chunks for efficient retrieval. While this approach works well for many applications, it can lead to problems when individual chunks lack sufficient context. Contextual Embeddings solve this problem by adding relevant context to each chunk before embedding. This method improves the quality of each embedded chunk, allowing for more accurate retrieval and thus better overall performance. Averaged across all data sources we tested, Contextual Embeddings reduced the top-20-chunk retrieval failure rate by 35%.\n\nThe same chunk-specific context can also be used with BM25 search to further improve retrieval performance. We introduce this technique in the \"Contextual BM25\" section.\n\nIn this guide, we'll demonstrate how to build and optimize a Contextual Retrieval system using a dataset of 9 codebases as our knowledge base. We'll walk through:\n\n1) Setting up a basic retrieval pipeline to establish a baseline for performance.\n\n2) Contextual Embeddings: what it is, why it works, and how prompt caching makes it practical for production use cases.\n\n3) Implementing Contextual Embeddings and demonstrating performance improvements.\n\n4) Contextual BM25: improving performance with *contextual* BM25 hybrid search.\n\n5) Improving performance with reranking,\n\n### Evaluation Metrics & Dataset:\n\nWe use a pre-chunked dataset of 9 codebases - all of which have been chunked according to a basic character splitting mechanism. Our evaluation dataset contains 248 queries - each of which contains a 'golden chunk.' We'll use a metric called Pass@k to evaluate performance. Pass@k checks whether or not the 'golden document' was present in the first k documents retrieved for each query. Contextual Embeddings in this case helped us to improve Pass@10 performance from ~87% --> ~95%.\n\nYou can find the code files and their chunks in `data/codebase_chunks.json` and the evaluation dataset in `data/evaluation_set.jsonl`\n\n#### Additional Notes:\n\nPrompt caching is helpful in managing costs when using this retrieval method. This feature is currently available on Anthropic's 1P API, and is coming soon to our 3P partner environments in AWS Bedrock and GCP Vertex. We know that many of our customers leverage AWS Knowledge Bases and GCP Vertex AI APIs when building RAG solutions, and this method can be used on either platform with a bit of customization. Consider reaching out to Anthropic or your AWS/GCP account team for guidance on this!\n\nTo make it easier to use this method on Bedrock, the AWS team has provided us with code that you can use to implement a Lambda function that adds context to each document. If you deploy this Lambda function, you can select it as a custom chunking option when configuring a [Bedrock Knowledge Base](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-create.html). You can find this code in `contextual-rag-lambda-function`. The main lambda function code is in `lambda_function.py`.\n\n## Table of Contents\n\n1) Setup\n\n2) Basic RAG\n\n3) Contextual Embeddings\n\n4) Contextual BM25\n\n5) Reranking"
},
{
"cell_type": "markdown",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions skills/.claude/hooks/pre-bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# PreToolUse Hook - Bash Safety Check
# Prevents dangerous commands and provides helpful reminders

set -e

TOOL_NAME="$1"
COMMAND="$2"

# Only run for Bash tool
if [[ "$TOOL_NAME" != "Bash" ]]; then
exit 0
fi

# Check for potentially dangerous commands
if [[ "$COMMAND" == *"rm -rf outputs"* ]] || [[ "$COMMAND" == *"rm -rf sample_data"* ]]; then
echo "⚠️ WARNING: Attempting to delete important directory!"
echo "Command: $COMMAND"
echo "These directories contain generated files and sample data."
# Allow but warn
fi

# Warn about pip install without using requirements.txt
if [[ "$COMMAND" == *"pip install"* ]] && [[ "$COMMAND" != *"requirements.txt"* ]]; then
echo "ℹ️ Installing package directly. Consider updating requirements.txt"
fi

# Remind about kernel restart after SDK reinstall
if [[ "$COMMAND" == *"pip install"* ]] && [[ "$COMMAND" == *"anthropic"* ]]; then
echo "ℹ️ Remember: Restart Jupyter kernel after SDK installation!"
fi

# Warn if trying to start jupyter/servers
if [[ "$COMMAND" == *"jupyter notebook"* ]] || [[ "$COMMAND" == *"jupyter lab"* ]]; then
echo "ℹ️ Starting Jupyter. Make sure to select the venv kernel in notebooks."
fi

exit 0
39 changes: 39 additions & 0 deletions skills/.claude/hooks/pre-write.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# PreToolUse Hook - Write Safety Check
# Prevents accidental overwrites of key files

set -e

TOOL_NAME="$1"
FILE_PATH="$2"

# Only run for Write tool
if [[ "$TOOL_NAME" != "Write" ]]; then
exit 0
fi

# Protected files - should never be overwritten without explicit user request
PROTECTED_FILES=(
".env"
"requirements.txt"
)

for protected in "${PROTECTED_FILES[@]}"; do
if [[ "$FILE_PATH" == *"$protected"* ]]; then
echo "⚠️ WARNING: Attempting to write to protected file: $FILE_PATH"
echo "This file should rarely be modified. Proceeding with caution..."
# Allow but warn - don't block
fi
done

# Warn if writing to notebooks/ without .ipynb extension
if [[ "$FILE_PATH" == *"notebooks/"* ]] && [[ "$FILE_PATH" != *".ipynb" ]]; then
echo "⚠️ Writing non-notebook file to notebooks/ directory: $FILE_PATH"
fi

# Warn if writing to sample_data/
if [[ "$FILE_PATH" == *"sample_data/"* ]]; then
echo "ℹ️ Modifying sample data: $FILE_PATH"
fi

exit 0
73 changes: 73 additions & 0 deletions skills/.claude/hooks/session-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
# SessionStart Hook - Skills Cookbook Environment Check
# This hook runs at the start of each Claude Code session to verify environment setup

set -e

echo "🔍 Skills Cookbook - Environment Check"
echo "======================================"

# Check if we're in a virtual environment
if [[ -z "$VIRTUAL_ENV" ]]; then
echo "⚠️ WARNING: No virtual environment detected!"
echo " Run: source venv/bin/activate"
echo ""
fi

# Check if Anthropic SDK is installed and get version
if python -c "import anthropic" 2>/dev/null; then
SDK_VERSION=$(python -c "import anthropic; print(anthropic.__version__)" 2>/dev/null || echo "unknown")
echo "✅ Anthropic SDK: $SDK_VERSION"
# Check for minimum version for Skills support
if [[ "$SDK_VERSION" < "0.71.0" ]]; then
echo "⚠️ SDK version $SDK_VERSION may be too old (minimum 0.71.0 for Skills support)"
echo " Run: pip install anthropic>=0.71.0"
echo ""
fi
else
echo "❌ Anthropic SDK not installed"
echo " Run: pip install -r requirements.txt"
echo ""
fi

# Check for API key
if [[ -f ".env" ]]; then
if grep -q "^ANTHROPIC_API_KEY=sk-" .env 2>/dev/null; then
echo "✅ API key configured in .env"
else
echo "⚠️ .env exists but API key may not be set"
echo " Check ANTHROPIC_API_KEY in .env"
echo ""
fi
else
echo "⚠️ .env file not found"
echo " Run: cp .env.example .env"
echo " Then add your ANTHROPIC_API_KEY"
echo ""
fi

# Check outputs directory
if [[ -d "outputs" ]]; then
FILE_COUNT=$(find outputs -type f 2>/dev/null | wc -l | tr -d ' ')
echo "✅ outputs/ directory exists ($FILE_COUNT files)"
else
echo "ℹ️ Creating outputs/ directory..."
mkdir -p outputs
fi

# Show current status from plan
if [[ -f "docs/skills_cookbook_plan.md" ]]; then
echo ""
echo "📊 Current Status:"
PHASE_STATUS=$(grep -A1 "^**Phase:**" docs/skills_cookbook_plan.md 2>/dev/null | tail -1 || echo "Unknown")
echo " $PHASE_STATUS"
fi

echo ""
echo "======================================"
echo "Ready to work on Skills Cookbook! 🚀"
echo ""
echo "Quick commands:"
echo " - jupyter notebook # Launch notebooks"
echo " - ls outputs/ # View generated files"
echo " - cat CLAUDE.md # View project guide"
30 changes: 30 additions & 0 deletions skills/.claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"hooks": {
"SessionStart": {
"command": ".claude/hooks/session-start.sh",
"description": "Verify Skills cookbook environment setup (SDK version, API key, directories)"
},
"PreToolUse": [
{
"command": ".claude/hooks/pre-write.sh",
"description": "Warn before overwriting protected files (whl, plan, sample data)",
"toolFilter": ["Write"]
},
{
"command": ".claude/hooks/pre-bash.sh",
"description": "Safety checks for bash commands (rm, pip install, jupyter)",
"toolFilter": ["Bash"]
}
]
},
"contextFiles": [
"CLAUDE.md",
"docs/skills_cookbook_plan.md"
],
"projectInfo": {
"name": "Skills Cookbook",
"type": "jupyter-notebooks",
"language": "python",
"description": "Educational cookbook for Claude Skills API with progressive notebooks"
}
}
14 changes: 14 additions & 0 deletions skills/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Claude Skills Cookbook Configuration
# Copy this file to .env and add your actual API key

# Required: Your Anthropic API key from https://console.anthropic.com/
ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Model selection (Skills require Claude 4.5 Sonnet or newer)
ANTHROPIC_MODEL=claude-sonnet-4-5-20250929

# Optional: Custom skills storage directory (default: ./custom_skills)
SKILLS_STORAGE_PATH=./custom_skills

# Optional: Output directory for generated files (default: ./outputs)
OUTPUT_PATH=./outputs
38 changes: 38 additions & 0 deletions skills/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Environment and secrets
.env
*.env

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/

# Jupyter
.ipynb_checkpoints/
*.ipynb_checkpoints

# Generated outputs
outputs/
*.xlsx
*.pptx
*.pdf
*.docx

# Documentation sources - internal only
docs/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db
Loading
Loading