Agent SDK — TypeScript
Agentby davila7 · Added 5mo ago
Claude
Install
npx claude-code-templates@latest --agent=cli-tool/components/skills/development/claude-api/typescript/agent-sdk --yesAdd to Claude
claude mcp add agent-sdk-typescriptAbout
Agent SDK — TypeScript
The Claude Agent SDK provides a higher-level interface for building AI agents with built-in tools, safety features, and agentic capabilities.
Installation
npm install @anthropic-ai/claude-agent-sdk
Quick Start
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Explain this codebase",
options: { allowedTools: ["Read", "Glob", "Grep"] },
})) {
if ("result" in message) {
console.log(message.result);
}
}
Built-in Tools
| Tool | Description |
|---|---|
| Read | Read files in the workspace |
| Write | Create new files |
| Edit | Make precise edits to existing files |
| Bash | Execute shell commands |
| Glob | Find files by pattern |
| Grep | Search files by content |
| WebSearch | Search the web for information |
| WebFetch | Fetch and analyze web pages |
| AskUserQuestion | Ask user clarifying questions |
| Agent | Spawn subagents |
Permission System
for await (const message of query({
prompt: "Refactor the authentication module",
options: {
allowedTools: ["Read", "Edit", "Write"],
permissionMode: "acceptEdits",
},
})) {
if ("result" in message) console.log(message.result);
}
Permission modes:
"default": Prompt for dangerous operations"plan": Planning only, no execution"acceptEdits": Auto-accept file edits"dontAsk": Don't prompt (useful for CI/CD)"bypassPermissions": Skip all prompts (requiresallowDangerouslySkipPermissions: truein options)
MCP (Model Context Protocol) Support
for await (const message of query({
prompt: "Open example.com and describe what you see",
options: {
mcpServers: {
Tags
FullStackaitmplclaude-code-templates