agent-sdk-quickstart
Build your first Claude Agent SDK agent — TypeScript or Python. Covers installation, minimal agent loop, tool definitions, and the difference between "roll-your-own" and Managed Agents. Use this skill when starting a new AI agent project, migrating from raw messages.create loops to the Agent SDK, or evaluating SDK vs direct API. Activate when: Claude Agent SDK, @anthropic-ai/claude-agent-sdk, build agent, agent SDK quickstart, agent tutorial.
What this skill does
# Claude Agent SDK — Quickstart
**The Claude Agent SDK is Anthropic's framework for building agents. It handles the tool-use loop, context compaction, sub-agent spawning, and MCP integration so you don't reinvent them.**
## When to Use
- Starting a new agent project
- Migrating from hand-rolled `messages.create` loops
- Need sub-agent orchestration, compaction, or skills out-of-box
- Building CLI tools, automation, or backend agents
## SDK vs Direct API vs Managed Agents
| Approach | Best for | Tradeoff |
|---|---|---|
| **Direct `messages.create`** | Simple one-shot calls | You manage everything |
| **Agent SDK** (client-side) | Custom agents with full control | You run the loop, manage state |
| **Managed Agents API** (`/v1/agents`) | Production agents at scale | Anthropic runs the loop server-side |
Use the SDK when you need more control than Managed Agents but don't want to rewrite the tool loop.
## Install
TypeScript:
```bash
npm i @anthropic-ai/claude-agent-sdk
```
Python:
```bash
pip install claude-agent-sdk
```
## Minimal Agent — TypeScript
```ts
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "What files are in the current directory?",
options: {
model: "claude-sonnet-4-6",
permissionMode: "default",
},
})) {
if (message.type === "assistant") {
for (const block of message.message.content) {
if (block.type === "text") process.stdout.write(block.text);
}
}
}
```
Under the hood: the SDK connects to Claude, provides default tools (file read, bash, web fetch), runs the tool-use loop, and streams results back.
## Minimal Agent — Python
```python
import asyncio
from claude_agent_sdk import query
async def main():
async for msg in query(
prompt="What files are here?",
options={"model": "claude-sonnet-4-6"},
):
if msg.type == "assistant":
for block in msg.message.content:
if block.type == "text":
print(block.text, end="")
asyncio.run(main())
```
## Adding Custom Tools
```ts
import { query, tool } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";
const getWeather = tool({
name: "get_weather",
description: "Get current weather for a city.",
inputSchema: z.object({ city: z.string() }),
handler: async ({ city }) => ({
content: [{ type: "text", text: `Weather in ${city}: sunny, 72°F` }],
}),
});
for await (const message of query({
prompt: "What's the weather in SF?",
options: {
model: "claude-sonnet-4-6",
tools: [getWeather],
},
})) { /* ... */ }
```
Tools are plain objects with a name, description, schema, and async handler. No magic.
## Permission Modes
```ts
options: {
permissionMode: "default", // prompt user for risky actions
// or "acceptEdits" // auto-approve edits, prompt for bash
// or "bypassPermissions" // YOLO (dev only)
// or "plan" // read-only, no writes
}
```
Use `plan` for dry-runs, `default` for interactive tools, `acceptEdits` only when you trust the agent.
## Hooks
Intercept tool calls before/after execution:
```ts
options: {
hooks: {
PreToolUse: async ({ toolName, input }) => {
console.log(`About to run ${toolName}`);
if (toolName === "bash" && input.command.includes("rm -rf")) {
return { decision: "block", reason: "Blocked destructive command" };
}
},
PostToolUse: async ({ toolName, output }) => {
await audit.log({ toolName, output });
},
},
}
```
Hooks run on your machine and can block, modify, or observe every tool call.
## Connecting to MCP Servers
```ts
options: {
mcpServers: {
github: { command: "npx", args: ["-y", "@modelcontextprotocol/server-github"] },
},
}
```
MCP tools appear alongside built-in tools. See the `mcp-client-integration` skill.
## System Prompts
```ts
options: {
systemPrompt: "You are a code reviewer. Be concise and actionable.",
// or append to the default:
appendSystemPrompt: "Always use TypeScript in examples.",
}
```
## Multi-Turn
Use `resume` to continue a previous session:
```ts
const sessionId = "session-123";
for await (const msg of query({
prompt: "Follow up: what about tests?",
options: { model: "claude-sonnet-4-6", resume: sessionId },
})) { /* ... */ }
```
See the `session-lifecycle` skill for more.
## Anti-Patterns
1. **Rebuilding the tool loop manually** when the SDK handles it
2. **`bypassPermissions` in production** — first hallucinated rm is your last
3. **Not using hooks** for audit/safety — missed opportunity
4. **Mixing SDK calls with direct `messages.create`** in the same agent — confuses session state
## Best Practices
1. Start with the SDK; drop to direct API only if SDK blocks something specific
2. Use `plan` or `default` permission mode in prod; never `bypassPermissions`
3. Add PreToolUse hooks for audit and safety checks
4. Use `resume` for multi-turn rather than rebuilding history yourself
5. Connect MCP servers for ecosystem tools; don't reimplement GitHub/Slack tools by hand
6. Keep system prompts short — big prompts cost per call (cache them)
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.