skills/claude-agent-sdk/agent-sdk-quickstart/SKILL.md
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.
npx skillsauth add latestaiagents/agent-skills agent-sdk-quickstartInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
messages.create loops| 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.
TypeScript:
npm i @anthropic-ai/claude-agent-sdk
Python:
pip install claude-agent-sdk
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.
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())
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.
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.
Intercept tool calls before/after execution:
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.
options: {
mcpServers: {
github: { command: "npx", args: ["-y", "@modelcontextprotocol/server-github"] },
},
}
MCP tools appear alongside built-in tools. See the mcp-client-integration skill.
options: {
systemPrompt: "You are a code reviewer. Be concise and actionable.",
// or append to the default:
appendSystemPrompt: "Always use TypeScript in examples.",
}
Use resume to continue a previous session:
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.
bypassPermissions in production — first hallucinated rm is your lastmessages.create in the same agent — confuses session stateplan or default permission mode in prod; never bypassPermissionsresume for multi-turn rather than rebuilding history yourselfdevelopment
Test skills for correct activation, content quality, and regression — both automated checks (frontmatter validity, lint) and manual verification (query-suite activation testing). Covers CI integration and how to catch skill regressions before users do. Use this skill when adding skills to a repo, setting up CI for a skill library, or debugging "the skill exists but doesn't work". Activate when: test skills, validate skills, skill CI, skill linting, skill activation test, skill regression.
documentation
Write the YAML frontmatter for a SKILL.md file so it activates reliably — name, description, and activation keywords that the model matches against. Covers length, tone, and the most common frontmatter mistakes. Use this skill when authoring a new skill, fixing a skill that isn't auto-activating, or reviewing skills for publication. Activate when: SKILL.md frontmatter, skill description, skill activation, skill YAML, write a skill, author a skill.
development
Design skills that fire at the right moment — neither over-eager (noise) nor under-eager (silent). Covers activation specificity, trigger phrases, disambiguation between overlapping skills, and debugging activation. Use this skill when multiple skills could fire on the same query, a skill never fires, or a skill fires too often. Activate when: skill won't activate, skill over-activates, overlapping skills, skill triggers, skill selection, skill disambiguation.
development
Structure SKILL.md content so the model reads just enough — concise summary up front, progressively deeper detail, examples on demand. Covers section ordering, length budgets, when to split into multiple skills. Use this skill when writing or refactoring a skill body, one skill has grown too long, or a skill is wordy but not useful. Activate when: SKILL.md structure, skill content, skill too long, split skill, progressive disclosure, skill body.