This template includes a sdk/ directory with TypeScript and
Python starters. The SDK lets you embed Claude Code's agent loop inside
your own applications — build custom bots, automations, or review tools.
Full reference: Agent SDK overview.
| Need | Use |
|---|---|
| Interactive coding | CLI (claude) |
| One-off CI job | CLI headless (claude -p "...") |
| Recurring scheduled job | Routines |
| Long-running service, custom tools, custom orchestration | SDK |
| GitHub PR automation | Claude Code Action |
query()— the main entrypoint. Streams messages from the agent loop as an async iterable.- Options —
cwd,permissionMode,model,maxTurns,tools,mcpServers,allowedTools,disallowedTools. - Custom tools — JSON Schema + handler. See
sdk/custom-tool-example.ts. - Hooks — same lifecycle events as the CLI, intercepted in your process. See SDK hooks.
- Sessions — persist and resume conversations. See sessions.
- Subagents — spawn specialized agents programmatically. See SDK subagents.
- Structured output — constrain the final response to a JSON schema. See structured outputs.
Read Securely deploying AI agents before shipping an SDK-based service. The key points:
- Never run in
bypassPermissionsmode against a user's data without sandboxing. - Validate every tool handler input — treat Claude-generated arguments as untrusted input.
- Set
maxTurnsand cost budgets. - Log tool calls for audit.
See OpenTelemetry observability. The SDK emits OTel spans for each turn and tool call — point them at your collector of choice.