Skip to content

afoxnyc3/claude-agent-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Claude Code SDK Agent Boilerplate

Production-ready template for building sophisticated AI agents with the Claude Code SDK. From research assistants to complex multi-agent systems, this boilerplate provides everything you need to go from prototype to production.

πŸš€ Quick Start

# 1. Copy this boilerplate
cp -r agent_boilerplate my_agent && cd my_agent

# 2. Install dependencies
uv sync

# 3. Set up your API key
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY

# 4. Run your agent
python agent.py

✨ Features

Core Capabilities

  • βœ… Multi-turn conversations with context management
  • βœ… Tool integration (WebSearch, Read, Write, Bash, custom tools)
  • βœ… Custom Python scripts via Bash tool
  • βœ… MCP server support for external integrations (GitHub, databases, etc.)
  • βœ… Async/sync support for different deployment contexts

Advanced Features

  • βœ… Subagents - Delegate to specialized expert agents
  • βœ… Output styles - Different communication templates for different audiences
  • βœ… Slash commands - Reusable prompt templates
  • βœ… Hooks - Automated compliance and audit trails
  • βœ… Memory - Persistent context via CLAUDE.md

Production Ready

  • βœ… Multiple deployment options (CLI, Web UI, REST API, Docker)
  • βœ… Comprehensive tests (unit + integration)
  • βœ… Security best practices
  • βœ… Monitoring and logging

πŸ“ Project Structure

agent_boilerplate/
β”œβ”€β”€ agent.py                 # Main agent module
β”œβ”€β”€ CLAUDE.md                # Agent memory/context
β”œβ”€β”€ GUIDE.md                 # Complete step-by-step guide
β”‚
β”œβ”€β”€ .claude/                 # Advanced configuration
β”‚   β”œβ”€β”€ agents/              # Subagent definitions
β”‚   β”œβ”€β”€ commands/            # Slash commands
β”‚   β”œβ”€β”€ output-styles/       # Communication templates
β”‚   β”œβ”€β”€ hooks/               # Automation scripts
β”‚   └── settings.local.json  # Hook configuration
β”‚
β”œβ”€β”€ scripts/                 # Custom Python tools
β”œβ”€β”€ data/                    # Agent data files
β”œβ”€β”€ tests/                   # Test suite
β”‚
└── deployment/              # Deployment options
    β”œβ”€β”€ cli/                 # Command-line interface
    β”œβ”€β”€ streamlit/           # Web UI (MVP)
    β”œβ”€β”€ fastapi/             # REST API (Production)
    └── docker/              # Containerization

🎯 Usage Examples

Basic Agent

from agent import send_query_simple

# Simple query
result = await send_query_simple("What is AI?")
print(result)

# Multi-turn conversation
result1 = await send_query_simple("What is the capital of France?")
result2 = await send_query_simple(
    "What's the population?",
    continue_conversation=True
)

Advanced Agent

from agent import send_query

# With custom configuration
result, messages = await send_query(
    prompt="Analyze the data in data/example.json",
    output_style="concise",
    allowed_tools=["Read", "Bash"],
    permission_mode="default"
)

With MCP Servers

# GitHub integration
github_mcp = {
    "github": {
        "command": "docker",
        "args": ["run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
                "ghcr.io/github/github-mcp-server"],
        "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": os.environ.get("GITHUB_TOKEN")}
    }
}

result, _ = await send_query(
    "Check issues in anthropics/claude-code-sdk-python",
    mcp_servers=github_mcp,
    allowed_tools=["mcp__github"]
)

🚒 Deployment Options

1. CLI (Quick MVP)

# Interactive mode
python deployment/cli/cli.py -i

# Single query
python deployment/cli/cli.py "Hello, agent!"

2. Streamlit Web UI (Demo/MVP)

# Install and run
uv add streamlit
streamlit run deployment/streamlit/app.py

# Deploy to cloud
# β†’ Push to GitHub
# β†’ Deploy on share.streamlit.io

3. FastAPI REST API (Production)

# Install and run
uv add fastapi uvicorn
uvicorn deployment.fastapi.api:app

# Test API
curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello!"}'

# Deploy to cloud
railway up  # or: fly deploy

4. Docker (Any Platform)

# Run with Docker Compose
docker-compose up agent-api

# Deploy to cloud
# AWS ECS, Google Cloud Run, Azure Container Instances
# See deployment/docker/README.md for details

πŸ§ͺ Testing

# Install test dependencies
uv add pytest pytest-asyncio

# Run all tests
pytest tests/ -v

# Run specific test
pytest tests/test_agent.py::test_basic -v

🎨 Customization Guide

1. Define Your Agent's Purpose

Edit CLAUDE.md with your domain knowledge and guidelines.

2. Add Custom Tools

Create scripts in scripts/ directory:

# scripts/my_tool.py
import sys
import json

def process(data):
    # Your logic here
    return {"result": data}

if __name__ == "__main__":
    result = process(sys.argv[1])
    print(json.dumps(result))

3. Create Subagents

Add markdown files to .claude/agents/:

---
name: expert-analyst
description: Expert in data analysis
tools: Bash, Read
---

You are a data analysis expert...

4. Add Output Styles

Create templates in .claude/output-styles/:

---
name: executive
description: Brief, KPI-focused communication
---

## Principles
- Lead with key insight
- Use bullet points
- Include metrics

5. Configure Hooks

Add automation in .claude/hooks/ and configure in settings.local.json.

πŸ“š Documentation

πŸ”§ Configuration

Environment Variables

# Required
ANTHROPIC_API_KEY=your_key_here

# Optional (for specific features)
GITHUB_TOKEN=your_github_token

Agent Options

ClaudeCodeOptions(
    model="claude-sonnet-4-20250514",  # Model selection
    max_turns=50,                       # Conversation limit
    allowed_tools=["Read", "Bash"],     # Tool permissions
    permission_mode="default",          # default, plan, acceptEdits
    system_prompt="...",                # Custom system prompt
    mcp_servers={...},                  # MCP integrations
)

πŸ—οΈ Architecture Patterns

This boilerplate implements patterns from the Claude Code SDK tutorial series:

  1. Research Agent - Web search + multimodal analysis
  2. Chief of Staff - Multi-agent orchestration + governance
  3. Observability Agent - External system integration via MCP

πŸ“ˆ Production Best Practices

  • βœ… Security: Environment variables, API auth, input validation
  • βœ… Monitoring: Logging, metrics, error tracking
  • βœ… Cost management: Token limits, model selection, caching
  • βœ… Scaling: Async processing, concurrent queries, load balancing
  • βœ… Testing: Unit tests, integration tests, E2E tests

See GUIDE.md section 8 for detailed best practices.

🌟 Example Use Cases

  • Customer Support - Handle inquiries, troubleshoot issues, access knowledge base
  • Data Analysis - Process datasets, generate insights, create visualizations
  • DevOps - Monitor systems, analyze logs, automate workflows
  • Research - Gather information, synthesize findings, generate reports
  • Content Creation - Write, edit, format content for different audiences

🀝 Contributing

This is a boilerplate template - customize it for your needs! Some ideas:

  • Add more deployment options (AWS Lambda, Google Cloud Functions)
  • Create industry-specific templates (healthcare, finance, legal)
  • Add more example scripts and tools
  • Improve test coverage
  • Add monitoring dashboards

πŸ“„ License

This boilerplate is part of the Anthropic Cookbook and follows the same license.

πŸ”— Resources

πŸ†˜ Support

  • Issues: Report bugs or request features
  • Discussions: Ask questions, share ideas
  • Documentation: Check GUIDE.md for detailed help

Built with ❀️ using the Claude Code SDK

Ready to build your agent? Start with GUIDE.md β†’

About

Production-ready boilerplate for building AI agents with Claude Code SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors