codex-agent is a Bun + TypeScript CLI/library for managing Codex session data and automation workflows.
It provides:
- Session discovery, inspection, streaming, resume, and fork operations
- Group orchestration for running prompts across multiple sessions
- Queue management for ordered prompt execution
- Bookmarking and search across sessions/messages
- Token-based auth helpers
- File-change indexing and lookup
- HTTP server and daemon modes for integration
- Bun (runtime/package manager)
- TypeScript (installed via dependencies)
- Optional: Nix + direnv for reproducible dev shell
bun install
bun run test
bun run typecheckRun CLI help:
bun run src/bin.ts --helpUsing Bun scripts:
bun run dev
bun run build
bun run start
bun run test
bun run test:watch
bun run typecheck
bun run check:dist-sync
bun run format
bun run format:checkUsing task (see Taskfile.yml):
task install
task test
task typecheck
task lint
task ciBinary entrypoint: src/bin.ts
Top-level command groups:
session: list/show/watch/run/resume/forkgroup: create/list/show/add/remove/pause/resume/delete/runqueue: create/add/show/list/pause/resume/delete/update/remove/move/mode/runbookmark: add/list/get/delete/searchtoken: create/list/revoke/rotatefiles: list/find/rebuildserver: startdaemon: start/stop/statusversion: inspect installed tool versions as human-readable text or JSON
Examples:
# List sessions
bun run src/bin.ts session list --limit 20
# Show one session and extract markdown tasks
bun run src/bin.ts session show <session-id> --tasks
# Start a new session, send one prompt, and stream output
bun run src/bin.ts session run --prompt "say hello" --stream-granularity char
# Create and run a queue
bun run src/bin.ts queue create nightly --project /path/to/repo
bun run src/bin.ts queue add nightly --prompt "Run checks and summarize failures"
bun run src/bin.ts queue run nightly --model gpt-5
# Start API server
bun run src/bin.ts server start --host 127.0.0.1 --port 3100
# Tool versions for system status UI
bun run src/bin.ts version --jsonsrc/
activity/ Session activity derivation
auth/ API token and permission handling
bookmark/ Bookmark storage and search
cli/ CLI parsing and text formatting
daemon/ Background daemon lifecycle
file-changes/ Changed-file extraction and indexing
group/ Session group orchestration
markdown/ Markdown parsing and task extraction
process/ Codex process execution management
queue/ Prompt queue lifecycle and execution
rollout/ Rollout log parsing and file watching
server/ HTTP/WebSocket server components
session/ Session discovery and SQLite-backed lookup
sdk/ Lightweight SDK/event abstractions
types/ Shared strict TypeScript types
Use the stable SDK facade when integrating from TypeScript applications. Callers pass a typed request object and do not compose Codex CLI command forms.
import { runAgent, type AgentEvent } from "codex-agent";
const events: AgentEvent[] = [];
for await (const event of runAgent({
prompt: "Summarize the latest test failures",
attachments: [
{ type: "path", path: "./screenshots/failure.png" },
{ type: "base64", data: "iVBORw0KGgoAAA...", mediaType: "image/png" },
],
})) {
events.push(event);
}Request routing (exec vs resume) and attachment normalization are handled
inside codex-agent internals.
codex-agent supports two stream granularities:
event: emit rollout events (session_meta,event_msg,response_item, ...)char: emit assistant text as character chunks
# Event-level stream (default)
bun run src/bin.ts session run --prompt "say hello"
# Character stream
bun run src/bin.ts session run --prompt "say hello" --stream-granularity char
# Slower "typing" effect in terminal
bun run src/bin.ts session run --prompt "say hello" --stream-granularity char --char-delay-ms 30Relevant flags:
--prompt <P>: required forsession run--stream-granularity <event|char>: output mode--char-delay-ms <n>: delay per rendered character insession runchar mode (default:8)
import { runAgent } from "codex-agent";
for await (const event of runAgent({
prompt: "say hello",
streamGranularity: "char",
})) {
if (event.type === "session.message") {
const chunk = event.chunk;
if (typeof chunk === "object" && chunk !== null && "kind" in chunk && chunk.kind === "char") {
process.stdout.write(chunk.char);
}
}
}
process.stdout.write("\n");If you want a visible typing effect in your app, apply delay in your render loop (the SDK returns chunks, but display pacing is caller-controlled).
Depending on the upstream codex exec --json event shape, assistant text may arrive as completed message items (not token deltas).
In that case, char mode still emits per-character chunks from the completed text, and CLI session run can pace rendering with --char-delay-ms.
Tool-version introspection is available for health/system status screens:
import { getToolVersions } from "codex-agent";
const versions = await getToolVersions({ includeGit: true });
// {
// codex: { version: "codex 0.x.y", error: null },
// git: { version: "git version 2.x.y", error: null }
// }Run full tests:
bun run testRun type checks:
bun run typecheckVerify distribution artifacts are synced with source:
bun run check:dist-sync- TypeScript strict mode is enabled (
tsconfig.json). - Nix users can enter the environment with
nix develop. - Design docs are stored in
design-docs/and implementation plans inimpl-plans/.