Build apps with the Claude API or Anthropic SDK. TRIGGER when: code imports `anthropic`/`@anthropic-ai/sdk`/`claude_agent_sdk`, or user asks to use Claude API, Anthropic SDKs, or Agent SDK. DO NOT TRIGGER when: code imports `openai`/other AI SDK, general programming, or ML/data-science tasks.
Build apps with the Claude API or Anthropic SDK. TRIGGER when: code imports `anthropic`/`@anthropic-ai/sdk`/`claude_agent_sdk`, or user asks to use Claude API, Anthropic SDKs, or Agent SDK. DO NOT TRIGGER when: code imports `openai`/other AI SDK, general programming, or ML/data-science tasks.
["Use claude-opus-4-6 as default model unless user specifies otherwise","Use thinking with type adaptive not budget_tokens (deprecated)","Use streaming for requests with long input, output, or high max_tokens","Use get_final_message or finalMessage helper for complete streamed responses","Use parse tool inputs with proper JSON methods not string operations","Never truncate user inputs — discuss options instead"]
error_handling
strict
streaming
supported
source
builtin
trust_score
100
provenance_sha
13eb18938323db2e
Claude API & Agent SDK
Defaults
Model: claude-opus-4-6 (unless user specifies otherwise)
Streaming: Default for large inputs, large outputs, or high max_tokens
Streaming completion: Use .get_final_message() (Python) / .finalMessage() (TypeScript)
Language Detection
Infer language from project files. Support: Python, TypeScript/JavaScript, Java/Kotlin/Scala, Go, Ruby, C#, PHP, cURL. If multiple languages detected, clarify which is relevant.
Which Surface to Use
Use Case
Surface
Single LLM call (classify, summarize, extract, Q&A)
Claude API direct
Multi-step pipelines with tool use
Claude API + tool use
Open-ended autonomous agents
Claude API agentic loop or Agent SDK
Built-in tools (files, web, terminal)
Agent SDK
Current Models
Model
ID
Context
Input $/1M
Output $/1M
Claude Opus 4.6
claude-opus-4-6
200K (1M beta)
$5.00
$25.00
Claude Sonnet 4.6
claude-sonnet-4-6
200K (1M beta)
$3.00
$15.00
Claude Haiku 4.5
claude-haiku-4-5
200K
$1.00
$5.00
Default to claude-opus-4-6 unless the user explicitly requests another model.
Use streaming when max_tokens is large or inputs are long:
Python
with client.messages.stream(
model="claude-opus-4-6",
max_tokens=4096,
messages=[{"role": "user", "content": prompt}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
# For complete response with metadata:
final = stream.get_final_message()
Determines which feature to work on next (marks completed ones)
Prepares context and constraints for the coding agent
Spawns the coding agent with focused instructions
Coding Agent
Receives a single focused task from the initializer
Implements using TDD (write tests, implement, verify)
Commits progress to git after each logical unit
Reports completion back to the initializer
Git-Persisted Progress
The key innovation: progress is persisted via git commits, not in-memory state.
from claude_agent_sdk import Agent, tool
@tooldefcommit_progress(message: str, files: list[str]):
"""Commit completed work to git."""
subprocess.run(["git", "add"] + files, check=True)
subprocess.run(["git", "commit", "-m", message], check=True)
Between sessions:
Git log shows what was completed
Feature list file shows what remains
No session state needed — fresh agent reads git history
Feature List Tracking
Maintain a features.md file that both agents read/write:
# Features- [x] User authentication (JWT)
- [x] Database schema setup
- [ ] API endpoints for CRUD <-- next
- [ ] Frontend dashboard
- [ ] Email notifications
The initializer marks features complete after the coding agent finishes each one.
When to Use This Pattern
Building complete applications over multiple sessions
Long-running projects that exceed single context windows
Projects requiring incremental, testable progress
Autonomous coding with minimal human intervention
Support Agent Quickstart Pattern
Build a customer support agent that handles tickets, escalates unresolved issues, and maintains conversation history (from anthropics/claude-quickstarts):
import anthropic
from typing importOptional
client = anthropic.Anthropic()
SUPPORT_SYSTEM_PROMPT = """You are a helpful customer support agent for Acme Corp.
You have access to the following tools to help customers:
- look_up_order: Find order status by order ID
- process_refund: Initiate a refund for an order
- escalate_ticket: Escalate to human support with a reason
Always be polite and empathetic. If you cannot resolve an issue, escalate it."""
support_tools = [
{
"name": "look_up_order",
"description": "Look up the status of a customer order",
"input_schema": {
"type": "object",
"properties": {
"order_id": {"type": "string", "description": "The order ID (e.g. ORD-12345)"}
},
"required": ["order_id"]
}
},
{
"name": "process_refund",
"description": "Process a refund for a completed order",
"input_schema": {
"type": "object",
"properties": {
"order_id": {"type": "string"},
"reason": {"type": "string", "description": "Reason for refund"}
},
"required": ["order_id", "reason"]
}
},
{
"name": "escalate_ticket",
"description": "Escalate an unresolved issue to human support",
"input_schema": {
"type": "object",
"properties": {
"issue_summary": {"type": "string"},
"priority": {"type": "string", "enum": ["low", "medium", "high"]}
},
"required": ["issue_summary", "priority"]
}
}
]
defrun_support_agent(user_message: str, conversation_history: list) -> tuple[str, list]:
"""Run one turn of the support agent, returning (response, updated_history)."""
conversation_history.append({"role": "user", "content": user_message})
whileTrue:
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=2048,
system=SUPPORT_SYSTEM_PROMPT,
tools=support_tools,
messages=conversation_history
)
if response.stop_reason == "end_turn":
text_content = next((b.text for b in response.content ifhasattr(b, 'text')), "")
conversation_history.append({"role": "assistant", "content": response.content})
return text_content, conversation_history
# Handle tool use
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": str(result)
})
conversation_history.append({"role": "assistant", "content": response.content})
conversation_history.append({"role": "user", "content": tool_results})
Financial Analyst Agent Pattern
Build a financial analysis agent that processes market data and generates reports (from anthropics/claude-quickstarts):
import anthropic
import json
client = anthropic.Anthropic()
financial_tools = [
{
"name": "get_stock_price",
"description": "Get current and historical stock price data",
"input_schema": {
"type": "object",
"properties": {
"symbol": {"type": "string", "description": "Stock ticker symbol (e.g. AAPL)"},
"period": {"type": "string", "enum": ["1d", "1w", "1m", "3m", "1y"],
"description": "Time period for historical data"}
},
"required": ["symbol"]
}
},
{
"name": "calculate_metrics",
"description": "Calculate financial metrics like PE ratio, moving averages, volatility",
"input_schema": {
"type": "object",
"properties": {
"symbol": {"type": "string"},
"metrics": {
"type": "array",
"items": {"type": "string", "enum": ["pe_ratio", "ma_50", "ma_200", "volatility", "beta"]},
"description": "Financial metrics to calculate"
}
},
"required": ["symbol", "metrics"]
}
},
{
"name": "generate_report",
"description": "Generate a structured financial analysis report",
"input_schema": {
"type": "object",
"properties": {
"symbol": {"type": "string"},
"report_type": {"type": "string", "enum": ["summary", "detailed", "comparison"]},
"output_format": {"type": "string", "enum": ["markdown", "json", "html"]}
},
"required": ["symbol", "report_type"]
}
}
]
FINANCIAL_SYSTEM_PROMPT = """You are an expert financial analyst. Analyze stocks and market data
to provide actionable insights. Always:
1. Gather relevant data before making recommendations
2. Consider multiple metrics and timeframes
3. Clearly state assumptions and limitations
4. Structure analysis with: Summary → Data Analysis → Key Findings → Recommendation"""defanalyze_stock(symbol: str, question: Optional[str] = None) -> str:
"""Run a financial analysis agent for a given stock symbol."""
prompt = question orf"Provide a comprehensive analysis of {symbol} stock."
messages = [{"role": "user", "content": prompt}]
whileTrue:
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=4096,
system=FINANCIAL_SYSTEM_PROMPT,
tools=financial_tools,
messages=messages
)
if response.stop_reason == "end_turn":
returnnext((b.text for b in response.content ifhasattr(b, 'text')), "")
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_financial_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": json.dumps(result)
})
messages.append({"role": "assistant", "content": response.content})
messages.append({"role": "user", "content": tool_results})
Common Pitfalls
Pitfall
Fix
Using budget_tokens in thinking
Use thinking: {type: "adaptive"} instead
Truncating long inputs
Discuss chunking or summarization options with user
Using output_format
Use output_config: {format: {...}} instead
Not streaming large responses
Add streaming for max_tokens > 4096
String manipulation on tool inputs
Use json.loads(block.input) / JSON.parse(block.input)