Quick Verdict
Bottom Line
The Codex SDK is the right choice if you're building on OpenAI models and want a thin, thread-based wrapper with OS-level sandboxing. The Claude Agent SDK is the right choice if you need hooks for runtime control, sub-agent orchestration, or Python support. Both are open-source. Both stream structured events. The model underneath matters more than the SDK around it.
What the Codex SDK Does
The Codex SDK is a TypeScript library that wraps the Codex CLI (@openai/codex). It spawns the CLI as a child process and communicates over stdin/stdout using JSONL. This is the same agent that powers Codex in ChatGPT and Codex Cloud, now embeddable in your own applications.
Core API Surface
You create a Codex instance, start a thread, and call run() for blocking execution or runStreamed() for an async generator of structured events. Threads persist conversation history. Call run() repeatedly on the same thread to continue a conversation. Use resumeThread() to reconstruct a thread from a saved ID.
Thread-Based Conversations
Each thread maintains its own context. Call run() or runStreamed() multiple times to iterate. Threads can be persisted and resumed across process restarts using resumeThread().
Structured Streaming
runStreamed() returns an async generator yielding typed events: item.started, item.updated, item.completed, turn.completed. Each event carries the item payload or usage stats. You control the UI.
Image Input
Pass screenshots and design specs alongside text prompts. Images are forwarded to the CLI via --image. Useful for UI-driven coding tasks where the agent needs visual context.
OS-Level Sandboxing
Inherits the CLI's sandbox modes: workspace-write (default, scoped to project directory), danger-full-access (no restrictions), and cloud containers (OpenAI-managed isolation). macOS uses Apple Seatbelt.
Models
The SDK defaults to GPT-5-Codex, a version of GPT-5 further optimized for agentic coding. Also available: codex-mini-latest (lower cost, lower latency) and GPT-5.4-mini for lightweight tasks. Model selection happens at initialization.
What the Claude Agent SDK Does
The Claude Agent SDK (@anthropic-ai/claude-agent-sdk) gives you the same tools, agent loop, and context management that power Claude Code, programmable in TypeScript and Python. It's not a CLI wrapper. It's the agent runtime itself.
Core API Surface
The primary entry point is query(), which returns an async generator streaming messages as Claude works. Sessions provide multi-turn conversations with automatic or manual lifecycle management. The SDK supports await using syntax for automatic cleanup.
12+ Hook Event Types
Intercept agent behavior with hooks: PreToolUse, PostToolUse, PostToolUseFailure, Notification, SessionStart, SessionEnd, Stop, SubagentStart, SubagentStop, PreCompact, PermissionRequest, and more. Block dangerous operations before they execute.
Sub-Agent Spawning
Claude Agent SDK supports spawning sub-agents that share task lists with dependency tracking. Each sub-agent gets its own context window. This is the same Agent Teams architecture that powers Claude Code's multi-agent workflows.
Fine-Grained Permissions
Control what tools the agent can use (allowedTools, disallowedTools), set permission modes, and use canUseTool callbacks for dynamic authorization. More granular than Codex's three sandbox tiers.
Python + TypeScript
Full SDK available in both languages. The Python SDK uses the same API shape. Codex SDK is TypeScript-only, with more languages planned. If your infrastructure is Python-heavy, Claude Agent SDK is the only option today.
Models
The SDK works with any Claude model: Opus 4.6 (highest SWE-bench score at 80.9%), Sonnet 4.5, and Haiku 3.5 for lightweight tasks. Model selection is per-query, so you can route different task types to different models within the same session.
Feature Comparison: Codex SDK vs Claude Agent SDK
| Feature | Codex SDK | Claude Agent SDK |
|---|---|---|
| npm package | @openai/codex-sdk | @anthropic-ai/claude-agent-sdk |
| Language support | TypeScript | TypeScript + Python |
| Architecture | CLI wrapper (spawns process, JSONL over stdio) | Native agent runtime |
| Conversation model | Threads (run / runStreamed) | Sessions (query generator) |
| Streaming | Async generator (typed events) | Async generator (typed messages) |
| Hook system | Approval policy (4 modes) | 12+ event hooks with callbacks |
| Sub-agents | Cloud tasks (isolated, no coordination) | Agent Teams (shared task list, coordination) |
| Sandbox | OS-level (Seatbelt on macOS, cloud containers) | Permission-based (tool allow/deny lists) |
| Image input | Yes (via --image flag) | Yes (multimodal messages) |
| Session persistence | resumeThread() | Resume by session ID |
| MCP support | Yes (expose agents as MCP servers) | Yes (connect to MCP servers) |
| AGENTS.md / CLAUDE.md | AGENTS.md (project instructions) | CLAUDE.md (project instructions) |
| Open source | Yes (MIT) | Yes |
| Default model | GPT-5-Codex | Claude Sonnet 4.5 |
| Token efficiency | ~3x fewer tokens per task | Higher token usage, deeper reasoning |
Sandbox and Security
Both SDKs run agents that read files, write code, and execute shell commands. Security models determine how much damage a misbehaving agent can do.
Codex SDK: OS-Level Isolation
Three sandbox tiers. workspace-write (default): read anything, write only in the project directory. danger-full-access: no restrictions. Cloud: OpenAI-managed containers with full isolation. On macOS, workspace-write uses Apple Seatbelt (sandbox-exec) to enforce filesystem boundaries at the OS level. Network access is blocked by default in sandboxed modes.
Claude Agent SDK: Permission Callbacks
Security is callback-driven. PreToolUse hooks fire before every tool call. You inspect the tool name, arguments, and return allow/deny/modify. disallowedTools blocks entire tool categories. canUseTool provides dynamic per-call authorization. More flexible than sandbox tiers, but the security boundary is your code, not the OS.
Practical Difference
Codex's OS-level sandbox means even a bug in your approval logic can't escape the filesystem boundary. Claude's hook system means you can implement arbitrarily complex authorization rules, but if your hook has a bug, the agent inherits whatever permissions the host process has. For high-stakes automation, Codex's sandbox-exec approach is more conservative. For nuanced authorization logic, Claude's hooks are more expressive.
Streaming and Events
Both SDKs stream structured events so you can build real-time UIs on top of the agent. The event models differ in granularity.
Codex SDK Events
runStreamed() yields events with a type field: thread.started, turn.started, item.started, item.updated, item.completed, and turn.completed. Items represent individual actions (tool calls, text generation). Turns represent a complete agent cycle. Usage stats arrive with turn.completed.
Claude Agent SDK Events
query() yields messages as an async generator. Each message carries the tool use, result, or text block. Hooks fire as side effects during the stream: PreToolUse lets you intercept before execution, PostToolUse lets you inspect results, SubagentStart and SubagentStop track agent orchestration. The hook system gives you more intervention points than Codex's event stream.
For UI Builders
If you're rendering a live coding assistant UI, both SDKs give you enough event granularity to show progress indicators, tool call logs, and streaming text. Codex's event model is simpler (6 event types). Claude's is richer (messages + 12+ hooks). Pick based on how much runtime control you need.
Pricing
Both SDKs are free. You pay for the model tokens your agent consumes. The cost difference is entirely about which models you use and how many tokens each SDK's agent loop generates.
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| GPT-5-Codex | $2.50 | $10.00 |
| codex-mini-latest | $1.50 | $6.00 |
| Claude Opus 4.6 | $15.00 | $75.00 |
| Claude Sonnet 4.5 | $3.00 | $15.00 |
| Claude Haiku 3.5 | $0.80 | $4.00 |
Codex agents use roughly 3x fewer tokens per equivalent task, according to community benchmarks. That means a codex-mini task at ~$1.50/M input is significantly cheaper than a Sonnet task at $3.00/M input, even before the 3x multiplier. But Claude Opus achieves higher scores on complex refactoring tasks (80.9% SWE-bench), so the cost-per-correct-solution calculation depends on task difficulty.
Most developers report $100-200/month for active Codex SDK usage. Claude Agent SDK costs vary more widely because Opus is 5-6x more expensive per token than Sonnet, and teams using Agent Teams with sub-agents multiply token consumption.
Where Morph Fits In
Regardless of which SDK you choose, the agent loop follows the same pattern: a planning model reads context, decides what to change, generates an edit, and applies it. The planning step uses expensive frontier tokens. The editing step is mechanical, merging a diff into an existing file.
Morph's Fast Apply replaces the editing step. Instead of burning GPT-5-Codex or Claude Opus tokens on the merge, your agent outputs a lazy edit snippet with // ... existing code ... markers for unchanged sections. Fast Apply merges it at 10,500 tok/s with 98% first-pass accuracy. The planning model stays the same. The editing model becomes specialized and cheap.
The Morph Sandbox SDK provides isolated execution environments for testing agent-generated code. Spin up a container, run the code, check the output, tear it down. This works as a validation layer on top of either Codex or Claude agents, catching runtime errors before they reach your codebase.
Integration Pattern
The pattern is: planning model (GPT-5-Codex or Claude Opus) decides what to change. Morph Fast Apply executes how to merge it. Morph Sandbox validates the result. This three-step pipeline works identically with both SDKs and cuts editing costs by 60-80% while adding a test-before-commit safety net.
Frequently Asked Questions
What is the Codex SDK?
The Codex SDK (@openai/codex-sdk) is a TypeScript library that wraps the Codex CLI. It spawns the CLI as a child process and communicates via JSONL over stdin/stdout. You get thread-based conversations, streaming events, image input, and session persistence. It requires Node.js 18+ and is published under the MIT license.
How does the Codex SDK compare to the Claude Agent SDK?
Both let you embed a coding agent in your app. Codex SDK is TypeScript-only, wraps the CLI, uses OpenAI models, and provides OS-level sandboxing. Claude Agent SDK supports TypeScript and Python, exposes 12+ hook events for runtime control, supports sub-agent orchestration, and works with Claude models. Codex uses fewer tokens per task. Claude offers deeper reasoning on complex refactoring. See our Codex vs Claude Code comparison for the full CLI comparison.
What models does the Codex SDK support?
GPT-5-Codex (default, optimized for agentic coding), codex-mini-latest ($1.50/$6.00 per million tokens), and GPT-5.4-mini for lightweight tasks. The model is configured at initialization.
Can I use Morph Fast Apply with the Codex SDK?
Yes. Fast Apply is model-agnostic. Your Codex agent outputs a lazy edit snippet, Fast Apply merges it at 10,500 tok/s, and the result goes back to the agent. Same pattern works with Claude Agent SDK. The Fast Apply API accepts a source file and edit snippet, returns the merged result.
Is the Codex SDK free?
The SDK is free and open-source (MIT license). You pay OpenAI for API token usage. GPT-5-Codex runs approximately $2.50 input / $10.00 output per million tokens. codex-mini-latest is $1.50/$6.00. Most active developers report $100-200/month in API costs.
Does the Codex SDK support MCP?
Yes. Codex agents can be exposed as MCP servers, allowing other tools and agents to interact with them via the Model Context Protocol. The Claude Agent SDK also supports MCP, connecting to MCP servers for additional tools and context.
Related
Add Fast Apply to Your Codex Agent
Morph Fast Apply processes code edits at 10,500 tok/s with 98% accuracy. Drop it into your Codex SDK or Claude Agent SDK pipeline as the editing backend. Same planning model, 60-80% lower edit costs.