agentsclimarketplace

Claude code agent sdk

Skill ucsandman/claude-code-capability-primer/skills/claude-code-agent-sdk

Claude Code plugin: injects a capability self-awareness card at session start so Claude actually knows and uses its built-in capabilities — skills, subagents, dynamic workflows, hooks, MCP, plugins, GitHub Actions, the Agent SDK, and more.

Install
npx -y skills add ucsandman/claude-code-capability-primer --skill claude-code-agent-sdk

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when building custom AI agents headlessly, embedding Claude Code tools in an app, or running scripted/cron agents—need SDK package names, setup, core API entry points, supported languages, and relation to Claude Code CLI and Messages...

SKILL.md

7.2 KB, ~1.8k tokens by cl100k_base, as published. Nobody here has run it

Claude Code Agent SDK

What it is: Library for building production AI agents in TypeScript or Python with the same tools, agentic loop, and context management that power Claude Code. Same capabilities as the CLI, but programmable for headless automation, CI/CD, custom applications, and production deployments.

Packages:

  • TypeScript: @anthropic-ai/claude-agent-sdk (includes native Claude Code binary)
  • Python: claude-agent-sdk (requires Python 3.10+)

Installation:

npm install @anthropic-ai/claude-agent-sdk
pip install claude-agent-sdk

When to Use

Use Agent SDK when: productizing/automating agents headlessly, embedding tools into apps, running agents on schedule, building custom agents with full control, or agents need autonomous operation without interactive CLI.

Don't use when: interactive development (use CLI), one-off tasks (use CLI), or needing managed REST API without running infrastructure (use Managed Agents).

Core Entry Point: query()

import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Fix the bug in auth.ts",
  options: { allowedTools: ["Read", "Edit", "Bash"] }
})) {
  console.log(message);
}
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

async def main():
    async for message in query(
        prompt="Fix the bug in auth.py",
        options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"]),
    ):
        print(message)

asyncio.run(main())

Python also supports context manager: async with ClaudeSDKClient(options=...) as client: await client.query(...)

Key Options (Python snake_case / TypeScript camelCase)

OptionTypeDefaultPurpose
allowed_tools / allowedToolsstring[]Pre-approve tools
disallowed_tools / disallowedToolsstring[]Block tools or patterns
permission_mode / permissionModestring"default"Control approval: default, dontAsk, acceptEdits, bypassPermissions, plan, auto (TS only)
cwdstringcwdWorking directory
modelstringlatest ClaudeModel ID
resumestringSession ID to resume
max_turns / maxTurnsnumberMax iterations
hooksobjectLifecycle callbacks
agentsobjectSubagent definitions
mcp_servers / mcpServersobjectMCP server config
setting_sources / settingSourcesstring[]["project"]Config sources to load

Built-in Tools

Read, Write, Edit, Bash, PowerShell, Monitor, Glob, Grep, WebSearch, WebFetch, AskUserQuestion.

Hooks: Lifecycle Callbacks

Available events (17+ total; 6 TypeScript-only):

EventPythonTypeScriptPurpose
PreToolUseBlock/modify before execution
PostToolUseAudit/log after completion
PostToolUseFailureHandle errors
PostToolBatchReact to batch completion
UserPromptSubmitInject context
MessageDisplayTransform display text
StopSave state on exit
SubagentStartTrack spawn
SubagentStopAggregate results
PreCompactArchive before compaction
PermissionRequestCustom permissions
SessionStartInitialize (TS only)
SessionEndCleanup (TS only)
NotificationForward status
SetupInit tasks (TS only)
TeammateIdleReassign (TS only)
TaskCompletedReact to task (TS only)
ConfigChangeReload settings (TS only)
WorktreeCreateTrack worktree (TS only)
WorktreeRemoveCleanup worktree (TS only)

Hooks use matcher patterns (e.g. "Write|Edit") and return hookSpecificOutput with permissionDecision, updatedInput, additionalContext, or updatedToolOutput. Note: SessionStart/SessionEnd are TypeScript-only for SDK callbacks; Python supports them only as shell command hooks in .claude/settings.json.

Subagents

Spawn specialized agents via the Agent tool. Warning: when parent uses bypassPermissions, acceptEdits, or auto mode, subagents inherit it without override—grants full system access in controlled environments only.

Sessions: Context Persistence

Capture session_id from init message, resume with resume=session_id. Sessions persist as .jsonl files locally. Use resumeSessionAt to resume at specific transcript point.

MCP Integration

Register via mcp_servers / mcpServers option or load from .claude/mcp.json / ~/.claude/mcp.json.

Permission Modes

ModeBehavior
defaultNo auto-approvals; unmatched tools trigger callback
dontAskDeny instead of prompting
acceptEditsAuto-approve file edits + filesystem ops
bypassPermissionsAll tools run without prompts (use cautiously)
planRead-only tools; Claude analyzes without editing
autoModel-classified approvals (TS only)

Evaluation order: Hooks → Deny rules → Permission mode → Allow rules → Callback.

Configuration Sources

Loaded from .claude/ and ~/.claude/ when settingSources includes those paths:

  • Skills: .claude/skills/*/SKILL.md
  • Commands: .claude/commands/*.md (legacy)
  • Memory: CLAUDE.md or .claude/CLAUDE.md
  • Settings/Hooks: .claude/settings.json
  • Plugins: Programmatic via plugins option only

Authentication

Priority: api_key in options → ANTHROPIC_API_KEY env var → Third-party providers (Bedrock, AWS, Vertex AI, Azure).

Billing

Starting June 15, 2026: Agent SDK usage draws from separate monthly credit pool (distinct from interactive Claude). Credits do not roll over.

TypeScript vs Python

ConceptTypeScriptPython
OptionsPassed as objectClaudeAgentOptions
camelCaseallowedTools, mcpServersallowed_tools, mcp_servers
Iterationfor await (const msg of query(...))async for message in query(...)
SessionStart/EndCallback hooksShell command hooks only

Key Resources

Gives 0 of the 12 instructions most context ai engineering skills give in ~1.8k tokens

Counted across 1,193 of the 1,976 authors here whose files we hold, read 2026-08-06

  • dispatch a fresh implementer subagent per taskin 48 of 1193, across 19 files
  • dispatch final reviewer after all tasksin 37 of 1193, across 11 files
  • provide full task text to the subagentin 31 of 1193, across 10 files
  • review spec compliance before code qualityin 27 of 1193, across 10 files
  • make the hook script executablein 26 of 1193, across 8 files
  • re-snapshot after navigation or DOM changesin 25 of 1193, across 17 files
  • answer subagent questions before proceedingin 22 of 1193, across 7 files
  • mark task complete in TodoWrite after approvalin 22 of 1193, across 6 files
  • merge hook into existing settingsin 21 of 1193, across 3 files
  • read files before editing themin 21 of 1193, across 9 files
  • ask if installation is global or projectin 20 of 1193, across 2 files
  • copy the hook script to target locationin 20 of 1193, across 2 files

Said here and by no other author read

  • pre-approve tools via allowed tools option
  • control approval using permission mode
  • handle lifecycle events via hooks
  • register servers via mcp servers option
  • load configuration sources from the specified paths

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.