Codex Runtime
codex-runtime is a Rust wrapper around the local codex app-server, the stdio JSON-RPC backend started by the codex CLI.
Repository identity:
- repository and crate:
codex-runtime - Rust import path:
codex_runtime - current crate version:
0.6.2
The project is intentionally layered so callers can start with one prompt and move down only when they need more control.
| Layer | Entry point | Use when |
|---|---|---|
| 1 | quick_run, quick_run_with_profile |
You want one prompt with safe defaults |
| 2 | Workflow, WorkflowConfig |
You want repeated runs in one working directory |
| 3 | runtime::{Client, Session} |
You want explicit session lifecycle and typed config |
| 4 | automation::{spawn, AutomationSpec} |
You want repeated turns on one prepared Session |
| 5 | AppServer |
You want validated low-level JSON-RPC helpers |
| 6 | runtime::Runtime or raw JSON-RPC |
You want full runtime control and live events |
Install
Requires codex CLI >= 0.104.0 on $PATH.
Published crate:
[]
= "0.6.2"
= { = "1", = ["macros", "rt-multi-thread"] }
Workspace path:
[]
= { = "crates/codex-runtime" }
Safe Defaults
All high-level entry points share the same baseline unless you opt out:
| Setting | Default |
|---|---|
| approval | never |
| sandbox | read-only |
| effort | medium |
| timeout | 120s |
| privileged escalation | false |
Privileged execution must be enabled explicitly. Tool-use hooks do not bypass sandbox or approval policy.
Quick Start
One-shot prompt
use quick_run;
async
Reusable workflow
use ;
async
Explicit client and session
use ;
async
Scoped streaming
use ;
async
Session::ask_wait(prompt) is the convenience path for ask_stream(...).finish().await when you do not need manual event handling.
Automation
use ;
use ;
use ;
async
Automation contract:
- one prepared
Sessionper runner - fixed
Durationcadence only - one turn in flight at a time
- missed ticks collapse into one next eligible run
- any
PromptRunErroris terminal - no cron parsing, persistence, or restart recovery in v1
Public Modules
| Module | Role |
|---|---|
codex_runtime |
root convenience surface |
codex_runtime::runtime |
typed runtime, sessions, approvals, transport, hooks, metrics |
codex_runtime::automation |
session-scoped recurring prompt runner |
codex_runtime::plugin |
hook traits and hook-side contracts |
codex_runtime::web |
higher-order web bridge over runtime sessions and approvals |
codex_runtime::artifact |
higher-order artifact domain over runtime threads and stores |
Root crate exports include:
quick_run,quick_run_with_profile,QuickRunErrorWorkflow,WorkflowConfigAppServer,rpc_methodsHookMatcher,FilteredPreHook,FilteredPostHook,ShellCommandHookautomation,plugin,runtime,web,artifact
Runtime Contracts
- High-level builders stay intentionally smaller than raw upstream payloads.
- Stable upstream fields graduate into typed APIs first.
- Experimental or custom methods remain available through raw JSON-RPC.
- Validation is strict in typed paths and only relaxed when callers explicitly choose raw mode.
- Detached cleanup and validation paths are kept data-first where practical so side effects stay at the outer boundary.
Hooks
Hooks let you intercept lifecycle phases without forking the runtime call path.
Phases:
PreRun,PostRunPreSessionStart,PostSessionStartPreTurn,PostTurnPreToolUse,PostToolUse
Key rules:
- pre-hooks can mutate or block
- post-hooks observe outcomes and issue reports
- tool-use hooks run inside approval-gated command/file-change handling
- hook logic sits on top of sandbox and approval policy, not instead of it
Documentation
docs/API_REFERENCE.md: public API and contract referencedocs/TEST_TREE.md: test layers and release-gate boundariesdocs/README.md: documentation indexCHANGELOG.md: release history
Quality Gates
Opt-in real-server tests:
CODEX_RUNTIME_REAL_SERVER_APPROVED=1 \
License
MIT