Claude Agent SDK Developer Guide
The Claude Code SDK was officially renamed to Claude Agent SDK, offering a more complete AI Agent building experience. This guide covers Python/TypeScript quickstarts, core concepts, and enterprise best practices.
What is Claude Agent SDK
seo_agent_sdk.rename_title
seo_agent_sdk.rename_desc
seo_agent_sdk.why_rename_title
seo_agent_sdk.why_rename_desc
Unified Tool Interface
Shares the same tool system and Agent loop as Claude Code, enabling seamless switching between local and cloud deployments.
Production Ready
Built-in error retry, session management, streaming output and other enterprise features work out of the box.
Multi-language Support
Official Python and TypeScript SDKs with symmetric API design and comprehensive documentation.
Core Concepts
Tools
Functions callable by the Agent, declared with decorators that auto-generate JSON Schema for Claude to understand and invoke.
Agent Loop
Claude thinks → selects tool → executes → observes result → continues thinking, until the task is complete.
Memory / Context
Unified management of in-session short-term memory (conversation history) and cross-session long-term memory (file/database persistence).
Permissions
Fine-grained permission control: filesystem, network, code execution, and external API access scopes can all be configured independently.
Python Quickstart
Build your first Claude Agent in three steps, fully compatible with QCode.cc proxy.
Step 1: Install SDK
pip install anthropic-agent-sdk
Step 2: Create Agent
from anthropic_agent_sdk import Agent, tool
@tool
def get_weather(city: str) -> str:
"""Get current weather for a city"""
return f"Weather in {city}: 22°C, sunny"
agent = Agent(
model="claude-opus-4-7",
tools=[get_weather],
base_url="https://api.qcode.cc", # QCode.cc proxy
api_key="your-api-key",
)
result = agent.run("What's the weather in Beijing and Shanghai?")
print(result.output)
Step 3: Define Custom Tools
from anthropic_agent_sdk import Agent, tool
import requests
@tool
def search_web(query: str, max_results: int = 5) -> list[dict]:
"""Search the web and return results"""
# Your search implementation here
response = requests.get(f"https://api.search.example.com?q={query}&n={max_results}")
return response.json()["results"]
@tool
def read_file(path: str) -> str:
"""Read contents of a local file"""
with open(path, "r") as f:
return f.read()
agent = Agent(
model="claude-opus-4-7",
tools=[search_web, read_file],
base_url="https://api.qcode.cc",
api_key="your-api-key",
system="You are a helpful research assistant.",
)
result = agent.run("Search for recent news about Claude Agent SDK and summarize")
print(result.output)
TypeScript Quickstart
Claude Agent development in Node.js / Bun with full type support.
Step 1: Install SDK
npm install @anthropic-ai/agent-sdk
Step 2: Create Agent
import { Agent, tool } from '@anthropic-ai/agent-sdk';
const getWeather = tool({
name: 'get_weather',
description: 'Get current weather for a city',
parameters: { city: { type: 'string' } },
execute: async ({ city }) => `Weather in ${city}: 22°C, sunny`,
});
const agent = new Agent({
model: 'claude-opus-4-7',
tools: [getWeather],
baseURL: 'https://api.qcode.cc',
apiKey: process.env.ANTHROPIC_API_KEY,
});
const result = await agent.run("What's the weather in Beijing?");
console.log(result.output);
Step 3: Full Example
import { Agent, tool } from '@anthropic-ai/agent-sdk';
const searchWeb = tool({
name: 'search_web',
description: 'Search the web for information',
parameters: {
query: { type: 'string', description: 'Search query' },
maxResults: { type: 'number', description: 'Max results', default: 5 },
},
execute: async ({ query, maxResults = 5 }) => {
const res = await fetch(`https://api.search.example.com?q=${query}&n=${maxResults}`);
const data = await res.json();
return data.results;
},
});
const agent = new Agent({
model: 'claude-opus-4-7',
tools: [searchWeb],
baseURL: 'https://api.qcode.cc',
apiKey: process.env.ANTHROPIC_API_KEY,
systemPrompt: 'You are a helpful research assistant.',
maxTurns: 10,
});
// Streaming support
for await (const event of agent.stream("Research the latest AI agent frameworks")) {
if (event.type === 'text') process.stdout.write(event.text);
}
Agent SDK vs Managed Agents
| seo_agent_sdk.vs_col_feature |
seo_agent_sdk.vs_col_sdk
|
seo_agent_sdk.vs_col_managed
|
|---|---|---|
| seo_agent_sdk.vs_row1_feature | Self-hosted (local / own server) | Anthropic cloud-hosted |
| seo_agent_sdk.vs_row2_feature | Manual instance management | Auto elastic scaling |
| seo_agent_sdk.vs_row3_feature | Prototyping, highly custom scenarios | Enterprise production Agent deployment |
Using via QCode.cc
Set ANTHROPIC_BASE_URL to the QCode.cc endpoint and all Agent SDK features work reliably within China, no VPN required.
# Python SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc
ANTHROPIC_API_KEY=your-qcode-api-key
# TypeScript SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc
ANTHROPIC_API_KEY=your-qcode-api-key
# Or set inline
agent = Agent(
base_url="https://api.qcode.cc",
api_key="your-qcode-api-key",
)
All Claude models (Opus 4.7 / Sonnet 4.6 / Haiku 4.5) available
Full tool calling (Function Calling) support
Streaming output support
Fully compatible with Managed Agents API
Start Building AI Agents Today
Register at QCode.cc for stable Claude API access within China, supporting all Agent SDK features.