npx skills add ...
npx skills add pydantic/skills --skill migrating-claude-agent-sdk-to-pydantic-ai
Migrate Python applications from the Claude Agent SDK to Pydantic AI and, only when needed, Pydantic AI Harness. Use when source code imports `claude_agent_sdk` or relies on Claude Code's agent loop, sessions, built-in tools, hooks, permissions, skills, or subagents. Do not use for the Anthropic Messages SDK or Claude Managed Agents.
npx skills add pydantic/skills --skill migrating-claude-agent-sdk-to-pydantic-ai
Preserve observable behavior, not the Claude Code process or API shape. Migrate the smallest complete caller path and keep application infrastructure in place.
query() or ClaudeSDKClient through prompts, tools, events, results, state, persistence, approvals, and side effects that callers use. Establish a focused baseline or characterization test.query() calls, live ClaudeSDKClient continuation, disk/external-store resume, transcript forks, and file rewind;Read Research and concept mapping for the detected source features. Read Verification and cutover before implementation.
pydantic_ai.Agent for model calls, the agent loop, typed dependencies, tools, outputs, normalized messages, generic hooks, streaming, MCP, approvals, usage limits, instrumentation, and durable-runtime integrations.pydantic-ai-harness only for observed reusable policy such as coding filesystem/shell tools, repository context, planning, memory, model-directed subagents, model-agnostic context management, or Agent Skills. Harness capabilities compose through the core agent loop; Harness is not a second runtime.ClaudeSDKClient or emulate Claude transcript files merely to hide a difference.The normal migration is one reusable Agent, application services supplied through typed dependencies, ordinary Pydantic AI tools, a typed output when the caller expects structure, and application-owned storage of result.all_messages() when later turns need context. Preserve the existing public request/response/event boundary with a small adapter while callers migrate.
allowed_tools in the Claude Agent SDK means auto-approval, not exclusive availability and not isolation. Map availability, approval, policy, and sandboxing independently.message_history explicitly replays normalized messages. conversation_id correlates runs; it is not a Claude session-resume token. Prove restart and fork behavior rather than renaming IDs.before_* hooks in capability order, after_* hooks in reverse order, and nests wrap_* hooks with the first capability outermost. Require a golden trace for any hook-visible contract.SubAgents only for model-directed delegation. Keep deterministic orchestration and verification loops in application code.Skills supplies on-demand SKILL.md instructions; verify resources and scripts separately instead of assuming Claude Code skill or plugin loading parity.ModalSandbox where it fits or retain application-owned container, VM, or sandbox isolation.claude-agent-sdk only after no retained path imports it, spawns Claude Code, reads its transcripts, or consumes its event/result types.Explain any consequential semantic change before implementing it: state the source behavior, target behavior, caller impact, recommended choice, and remaining risk.
Apply the completion criterion in Verification and cutover. Label evidence from fakes, recordings, and live providers accurately.