Back to list
amco3008

claude-sdk

by amco3008

0🍴 0📅 Jan 24, 2026

SKILL.md


name: claude-sdk description: Use the Anthropic Claude SDK for programmatic API access. Enables spawning sub-agents, parallel processing, batch operations, and custom Claude interactions via Python. Use when tasks need multiple Claude instances, background processing, or direct API control. allowed-tools:

  • Bash
  • Read
  • Write

Claude SDK Skill

Enables programmatic access to Claude's API for sub-agents, parallel processing, and advanced workflows.

Prerequisites

The Anthropic Python SDK is pre-installed. Ensure ANTHROPIC_API_KEY is set:

export ANTHROPIC_API_KEY="sk-ant-..."

Basic Usage

from anthropic import Anthropic

client = Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=4096,
    messages=[
        {"role": "user", "content": "Your prompt here"}
    ]
)

print(response.content[0].text)

Use Cases

1. Spawn a Sub-Agent

Delegate a focused task to a separate Claude instance:

from anthropic import Anthropic

def spawn_sub_agent(task: str, context: str = "") -> str:
    """Spawn a sub-agent for a focused task."""
    client = Anthropic()
    
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=4096,
        system="You are a focused sub-agent. Complete the task directly and concisely.",
        messages=[
            {"role": "user", "content": f"Context:\n{context}\n\nTask:\n{task}"}
        ]
    )
    return response.content[0].text

# Example: Delegate code review
result = spawn_sub_agent(
    task="Review this function for bugs and suggest improvements",
    context=open("myfile.py").read()
)
print(result)

2. Parallel Processing

Process multiple items concurrently:

from anthropic import Anthropic
from concurrent.futures import ThreadPoolExecutor

def process_item(item: str) -> str:
    client = Anthropic()
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        messages=[{"role": "user", "content": f"Analyze: {item}"}]
    )
    return response.content[0].text

items = ["item1", "item2", "item3"]
with ThreadPoolExecutor(max_workers=3) as executor:
    results = list(executor.map(process_item, items))

3. Streaming Responses

Stream long responses for real-time output:

from anthropic import Anthropic

client = Anthropic()

with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=4096,
    messages=[{"role": "user", "content": "Write a long story"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

4. Multi-Turn Conversations

Maintain conversation context:

from anthropic import Anthropic

client = Anthropic()
messages = []

def chat(user_message: str) -> str:
    messages.append({"role": "user", "content": user_message})
    
    response = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=4096,
        messages=messages
    )
    
    assistant_message = response.content[0].text
    messages.append({"role": "assistant", "content": assistant_message})
    return assistant_message

# Multi-turn conversation
chat("What is Python?")
chat("Show me an example")
chat("How do I run it?")

5. Tool Use (Function Calling)

Let Claude call your functions:

from anthropic import Anthropic

client = Anthropic()

tools = [{
    "name": "get_weather",
    "description": "Get weather for a location",
    "input_schema": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "City name"}
        },
        "required": ["location"]
    }
}]

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in Paris?"}]
)

# Check if Claude wants to use a tool
for block in response.content:
    if block.type == "tool_use":
        print(f"Tool: {block.name}, Input: {block.input}")

Models

ModelBest For
claude-sonnet-4-20250514Balanced performance/cost
claude-opus-4-20250514Complex reasoning
claude-3-5-haiku-20241022Fast, cheap tasks

Rate Limits

Be mindful of API rate limits when spawning multiple sub-agents. Use exponential backoff:

import time
from anthropic import RateLimitError

def call_with_retry(func, max_retries=5):
    for i in range(max_retries):
        try:
            return func()
        except RateLimitError:
            wait = 2 ** i
            print(f"Rate limited, waiting {wait}s...")
            time.sleep(wait)
    raise Exception("Max retries exceeded")

Cost Awareness

API calls cost money. Estimate before large operations:

  • Sonnet: ~$3/M input, ~$15/M output tokens
  • Opus: ~$15/M input, ~$75/M output tokens
  • Haiku: ~$0.25/M input, ~$1.25/M output tokens

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon