Skip to main content

@flow-state-dev/codex

Classes​

CodexAgentAbortedError​

The caller's signal fired. A cancelled run is a throw and never a handle, and this is what tells "you stopped it" from "it broke" for a manager deciding whether to retry.

A host tells it with core's isAbortLike, whatever stopped the run: the root of its cause chain is always an AbortError, whose message is the signal's reason. The reason itself (a deadline's TimeoutError, a plain Error, or none) is on reason.

Extends​

  • Error

Constructors​

Constructor​
new CodexAgentAbortedError(sessionId, reason?): CodexAgentAbortedError;
Parameters​
sessionId​

string | null

reason?​

unknown

The stopping signal's reason, as the caller gave it.

Returns​

CodexAgentAbortedError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

code​
readonly code: "CODEX_AGENT_ABORTED" = "CODEX_AGENT_ABORTED";
message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

reason?​
readonly reason?: unknown;

The stopping signal's reason, as the caller gave it.

sessionId​
readonly sessionId: string | null;
stack?​
stack?: string;
Inherited from​

Error.stack


CodexAgentConfigError​

A configuration mistake caught when the block is built: an option group carrying something the block owns rather than forwards (a working directory, a turn signal).

Extends​

  • Error

Constructors​

Constructor​
new CodexAgentConfigError(message): CodexAgentConfigError;
Parameters​
message​

string

Returns​

CodexAgentConfigError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

code​
readonly code: "CODEX_AGENT_CONFIG_INVALID" = "CODEX_AGENT_CONFIG_INVALID";
message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

stack?​
stack?: string;
Inherited from​

Error.stack


CodexAgentRunError​

The run ended abnormally: the CLI exited non-zero, the stream threw, or the prompt was empty. Wraps the underlying message on detail.cause so the caller sees a stable class without losing what the vendor said.

Extends​

  • Error

Implements​

  • ClassifiedHarnessError

Constructors​

Constructor​
new CodexAgentRunError(
message,
detail?,
cause?,
harnessFailure?
): CodexAgentRunError;
Parameters​
message​

string

detail?​

carries the underlying message as a string, the shape the Claude Code adapter's equivalent uses and the one a host can log.

cause?​

string

cause?​

unknown

the original throw, forwarded to Error's own cause so the class and stack of whatever failed stay reachable. detail.cause alone loses both, which is the difference between "the SDK threw" and knowing what it threw and where.

harnessFailure?​

"unknown-conversation" | null

see CodexAgentRunError.harnessFailure.

Returns​

CodexAgentRunError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Implementation of​

ClassifiedHarnessError.cause

Inherited from​

Error.cause

code​
readonly code: "CODEX_AGENT_RUN_FAILED" = "CODEX_AGENT_RUN_FAILED";
detail?​
readonly detail?: object;
cause?​
cause?: string;
harnessFailure​
readonly harnessFailure: "unknown-conversation" | null;

The failure in core's neutral vocabulary, read with core's harnessFailureKind. "unknown-conversation" when Codex refused to resume the thread the run asked for (see isUnknownThreadFailure); null for every other failure.

Implementation of​

ClassifiedHarnessError.harnessFailure

message​
message: string;
Implementation of​

ClassifiedHarnessError.message

Inherited from​

Error.message

name​
name: string;
Implementation of​

ClassifiedHarnessError.name

Inherited from​

Error.name

stack?​
stack?: string;
Implementation of​

ClassifiedHarnessError.stack

Inherited from​

Error.stack


CodexSdkNotInstalledError​

The optional @openai/codex-sdk peer dependency is not installed. Raised on the first RUN, not at import and not when the block is built — a block can be constructed on a host that never runs it.

Extends​

  • Error

Constructors​

Constructor​
new CodexSdkNotInstalledError(message?, detail?): CodexSdkNotInstalledError;
Parameters​
message?​

string

detail?​
cause?​

string

Returns​

CodexSdkNotInstalledError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

code​
readonly code: "CODEX_SDK_NOT_INSTALLED" = "CODEX_SDK_NOT_INSTALLED";
detail?​
readonly detail?: object;
cause?​
cause?: string;
message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

stack?​
stack?: string;
Inherited from​

Error.stack

Interfaces​

CodexAgentHandle​

Handle for a single Codex run.

The neutral harness handle plus Codex's own extras. status never reaches "dispatched"/"running": this door observes its run to completion or throws, so a returned handle is always terminal.

outcome is "finished" on a completed turn and "failed" on a failed one. Codex reports no turn or budget cap, so "stopped-at-limit" is never produced here — a run stopped by the CALLER's deadline is a throw, not a handle (the harness abort contract).

Extends​

  • HarnessRunHandle

Properties​

codexUsage​
codexUsage: CodexRunUsage | null;

Codex's own usage breakdown, or null when no turn.completed arrived.

cost​
cost: HarnessRunCost | null;

What the run cost and how that was arrived at, or null when neither is known.

Inherited from​

HarnessRunHandle.cost

dispatchedAt​
dispatchedAt: number;

Epoch millis when the handle was created.

Inherited from​

HarnessRunHandle.dispatchedAt

failureMessage​
failureMessage: string | null;

The message from a turn.failed event, or null when the turn did not fail.

finalMessage​
finalMessage: string | null;

The run's last assistant text, or null if it produced none.

Inherited from​

HarnessRunHandle.finalMessage

outcome​
outcome: HarnessRunOutcome | null;

How the run ended, or null while it is unknown.

Inherited from​

HarnessRunHandle.outcome

sessionId​
sessionId: string | null;

The harness's own session/run id, when one could be determined.

Inherited from​

HarnessRunHandle.sessionId

source​
source: "codex/sdk";

Which harness and door produced this — see HarnessSource.

Overrides​

HarnessRunHandle.source

status​
status: "completed" | "errored";
Overrides​

HarnessRunHandle.status

url​
url: string | null;

Human-openable URL for the run, when the harness exposes one.

Inherited from​

HarnessRunHandle.url

usage​
usage: HarnessRunUsage | null;

Token usage, or null when the harness reported none.

Inherited from​

HarnessRunHandle.usage


CodexAgentOptions​

Options for codexAgent.

Properties​

client?​
client?: CodexClientOptions;

The SDK's client options, forwarded verbatim (API key, environment, config overrides, a binary path override). Refused for the same two keys as thread.

cwd?​
cwd?: HarnessResolver<string>;

Where the run works. Called once per invocation, before anything is spawned, and its answer becomes the thread's workingDirectory.

A resolver, never a field on the block's input — a correctness constraint, not a style preference. The same block is a model-facing tool through the capability, so a directory reachable from the input is one the model could choose. Omit it and the run works in the host process's own directory, which is almost never what a host wants.

model?​
model?: string | HarnessResolver<string | null | undefined>;

Which model the run uses: a fixed id, or a resolver called once per invocation, like cwd and resume, so one block can run a different model for each run. It becomes the thread's model on a fresh thread and a resumed one alike, and it is what the cost estimate is priced against.

null, "" and undefined from the resolver all mean "no model named": Codex runs its own default. Setting this and thread.model together is refused when the block is built: one owner per value.

name?​
name?: string;

Block name. Default "codex-agent".

onActivity?​
onActivity?: HarnessActivityHook;

Called with each assistant message and each tool call the run starts, so a host can say how the run is doing. Not awaited, and a throw is logged and swallowed.

onEvent?​
onEvent?: HarnessEventHook;

Called on every event the run sends, of any kind, so a host can tell a working run from a silent one. Not awaited, and a throw is logged and swallowed.

onSession?​
onSession?: HarnessSessionHook;

The write side of resume: called once, with the thread id, the moment the stream names it — and before any turn work is consumed.

This is the only carrier that survives a cancelled run. A throw returns no handle and a status item is transient by contract, so a host whose deadline fired would otherwise have nothing to resume from. The hook fires on an actual thread.started event and on nothing else, which is why a REFUSED resume never reaches it: the CLI names no thread in that case, so no dead id is ever written back over a good one.

recordPlan?​
recordPlan?: boolean;

Record Codex's to-do list in the run's plan record, core's observed-plan collection, with its observed-plan-list marker. Default false.

On, the block declares both collections and, each time Codex confirms an update to its list, writes the whole list it confirmed through core's replacePlanList under the thread's conversation namespace (harnessConversationNamespace(threadId)). Off, the block writes no plan.

recordPullRequests?​
recordPullRequests?: boolean;

Record each pull request the run opens in core's pull-request record (observed-pull-requests). Default true: a gh pr create or a create-pull-request tool whose result names a pull request is a row; a gh pr view is not. false declares nothing and records nothing.

resolveCodexClient?​
resolveCodexClient?: ResolveCodexClient;

Host hook resolving the Codex client. Default: lazy SDK import.

resume?​
resume?: HarnessResolver<string | null | undefined>;

Which conversation to continue. Called once per invocation; null, "" and undefined all mean "start a fresh thread".

Same fence as cwd, and the same reason: a session id on the input is a model resuming any conversation it has seen into the current checkout.

thread?​
thread?: CodexThreadOptions;

The SDK's thread options, forwarded verbatim (model, sandbox mode, approval policy, reasoning effort, network and web-search settings, the git-repo check, additional directories).

The model the run used (this group's model, or the block's own CodexAgentOptions.model) is also what the cost estimate is priced against — Codex's wire never names the model that ran, so a run left on Codex's default reports no cost at all.

A workingDirectory or a signal in this bag is refused when the block is built: each has exactly one owner (cwd, and the block's own ctx.signal).

uses?​
uses?: UsesSlot;

Capabilities forwarded to the underlying handler.


CodexClientOptions​

The SDK's CodexOptions, forwarded verbatim to the client constructor.

Leave env unset and the CLI process inherits the server's entire process.env, every secret in it included. Setting it REPLACES that environment rather than adding to it — the SDK's own rule. To pass only named variables, use harnessEnv from @flow-state-dev/core/harness, exactly as for the Claude Code adapter's env.

Properties​

apiKey?​
apiKey?: string;
baseUrl?​
baseUrl?: string;
codexPathOverride?​
codexPathOverride?: string;
config?​
config?: Record<string, unknown>;
configOverrides?​
configOverrides?: string[];
env?​
env?: Record<string, string>;

CodexFileUpdateChange​

A file the run's patch touched, and how.

Properties​

kind​
kind: "add" | "delete" | "update";
path​
path: string;

CodexProgram​

The Codex program the SDK runs, and the directories it puts on that program's PATH.

Properties​

path​
readonly path: string;
pathDirs​
readonly pathDirs: readonly string[];

CodexReadinessOptions​

Options for checkCodexReadiness: the probe's, and how the installed SDK is read.

Extends​

Properties​

env​
env: Record<string, string>;

The environment Codex is started with. Pass the one the run gets (for example harnessEnv({ pass })), so a credential the run can't see isn't counted.

Inherited from​

ProbeCodexAccountOptions.env

program?​
program?: CodexProgram;

The program to run as <path> login status. A seam for tests and scripted checks; the default is findCodexProgram's answer.

Inherited from​

ProbeCodexAccountOptions.program

readInstalledSdkVersion?​
readInstalledSdkVersion?: InstalledSdkVersionReader;

Which @openai/codex-sdk is installed. Default: the one beside this package. A seam for a host's own check and for tests; the block itself always reads the installed one.

signal?​
signal?: AbortSignal;

Stops waiting and ends Codex when it aborts; the answer is then none, as on a timeout.

Inherited from​

ProbeCodexAccountOptions.signal

timeoutMs?​
timeoutMs?: number;

How long to wait for Codex's answer before reading it as none. Default 10 000 ms.

Inherited from​

ProbeCodexAccountOptions.timeoutMs


CodexRunUsage​

Codex's full token breakdown for a turn.

The neutral handle carries only inputTokens/outputTokens, which is what every harness can fill honestly. The rest rides here so a consumer that wants to price a run differently — or read what the cache actually saved — has the raw numbers rather than our derivation of them.

reasoningOutputTokens is a SUBSET of outputTokens, as OpenAI's usage reports it. Adding the two would double-count the reasoning.

Properties​

cachedInputTokens​
cachedInputTokens: number;
cacheWriteInputTokens​
cacheWriteInputTokens: number;
inputTokens​
inputTokens: number;
outputTokens​
outputTokens: number;
reasoningOutputTokens​
reasoningOutputTokens: number;

CodexThreadLike​

The subset of the SDK's Thread this package drives.

Properties​

id​
readonly id: string | null;

Populated once the first turn names the thread; null before that.

Methods​

runStreamed()​
runStreamed(input, turnOptions?): Promise<{
events: AsyncIterable<CodexThreadEvent>;
}>;
Parameters​
input​

CodexTurnInput

turnOptions?​
signal?​

AbortSignal

Returns​

Promise<{ events: AsyncIterable<CodexThreadEvent>; }>


CodexThreadOptions​

The SDK's ThreadOptions, forwarded verbatim and typed locally.

workingDirectory is deliberately ABSENT: the cwd resolver owns it, and passing one here is refused when the block is built rather than merged (one owner). The refusal is a runtime check, because a caller spreading an untyped bag would otherwise slip past the type.

Properties​

additionalDirectories?​
additionalDirectories?: string[];
approvalPolicy?​
approvalPolicy?: "never" | "on-request" | "on-failure" | "untrusted";
model?​
model?: string;
modelReasoningEffort?​
modelReasoningEffort?:
| "minimal"
| "low"
| "medium"
| "high"
| "xhigh"
| "max"
| "ultra"
| "persistent";
networkAccessEnabled?​
networkAccessEnabled?: boolean;
sandboxMode?​
sandboxMode?: "read-only" | "workspace-write" | "danger-full-access";
skipGitRepoCheck?​
skipGitRepoCheck?: boolean;
threadSource?​
threadSource?: string;
webSearchEnabled?​
webSearchEnabled?: boolean;
webSearchMode?​
webSearchMode?: "disabled" | "cached" | "live";

CodexWireUsage​

Codex's per-turn token report, in the wire's own snake_case spelling.

Properties​

cache_write_input_tokens​
cache_write_input_tokens: number;
cached_input_tokens​
cached_input_tokens: number;
input_tokens​
input_tokens: number;
output_tokens​
output_tokens: number;
reasoning_output_tokens​
reasoning_output_tokens: number;

ListCodexModelsOptions​

Options for listCodexModels.

Properties​

env​
env: Record<string, string>;

The environment Codex is started with. Pass the one the run gets.

program?​
program?: CodexProgram;

The program to start as <path> app-server. A seam for tests; the default is findCodexProgram's answer.

timeoutMs?​
timeoutMs?: number;

How long to wait for Codex's answers. Default 10 000 ms.


ProbeCodexAccountOptions​

Options for probeCodexAccount.

Extended by​

Properties​

env​
env: Record<string, string>;

The environment Codex is started with. Pass the one the run gets (for example harnessEnv({ pass })), so a credential the run can't see isn't counted.

program?​
program?: CodexProgram;

The program to run as <path> login status. A seam for tests and scripted checks; the default is findCodexProgram's answer.

signal?​
signal?: AbortSignal;

Stops waiting and ends Codex when it aborts; the answer is then none, as on a timeout.

timeoutMs?​
timeoutMs?: number;

How long to wait for Codex's answer before reading it as none. Default 10 000 ms.


ReadCodexUsageOptions​

Options for readCodexUsage.

Properties​

env​
env: Record<string, string>;

The environment Codex is started with. Pass the one a run gets (for example harnessEnv({ pass: ["PATH", "HOME", "CODEX_HOME"] })), so the read and the run see one sign-in.

program?​
program?: CodexProgram;

The program to start as <path> app-server. A seam for tests and scripted checks; the default is findCodexProgram's answer.

signal?​
signal?: AbortSignal;

Stops the read early; it then reads unavailable.

timeoutMs?​
timeoutMs?: number;

How long to wait for Codex's answers before reading unavailable. Default 10 000 ms.


ResolvedCodexClient​

The subset of the SDK's Codex client this package drives.

Methods​

resumeThread()​
resumeThread(id, options?): CodexThreadLike;
Parameters​
id​

string

options?​

CodexThreadOptions & object

Returns​

CodexThreadLike

startThread()​
startThread(options?): CodexThreadLike;
Parameters​
options?​

CodexThreadOptions & object

Returns​

CodexThreadLike

Type Aliases​

CodexAccountProbe​

type CodexAccountProbe =
| {
source: "api-key" | "login";
status: "account";
}
| {
reason: string;
status: "none";
unanswered?: true;
}
| {
reason: string;
status: "sdk-missing";
};

What probeCodexAccount found.

Union Members​

Type Literal​
{
source: "api-key" | "login";
status: "account";
}

A credential: CODEX_API_KEY in the environment, or a login codex login status accepts.


Type Literal​
{
reason: string;
status: "none";
unanswered?: true;
}

No credential, or no answer. reason says which, for a message to a person; unanswered is set when Codex timed out, was stopped, or could not be started, so nothing is known about the credential.


Type Literal​
{
reason: string;
status: "sdk-missing";
}

The Codex SDK could not be loaded, so there is no program to ask. reason carries why.


CodexHarnessOptions​

type CodexHarnessOptions = Omit<CodexAgentOptions, "cwd" | "resume" | "onSession" | "onActivity" | "onEvent">;

What codexHarness takes: the Codex block's options, less what each run feeds it.


CodexSdkImporter​

type CodexSdkImporter = () => Promise<{
Codex?: unknown;
}>;

How the resolver loads the SDK module. Overridable so the absent-SDK path is testable.

Returns​

Promise<{ Codex?: unknown; }>


CodexThreadEvent​

type CodexThreadEvent =
| {
thread_id: string;
type: "thread.started";
}
| {
type: "turn.started";
}
| {
type: "turn.completed";
usage: CodexWireUsage;
}
| {
error: {
message: string;
};
type: "turn.failed";
}
| {
item: CodexThreadItem;
type: "item.started";
}
| {
item: CodexThreadItem;
type: "item.updated";
}
| {
item: CodexThreadItem;
type: "item.completed";
}
| {
message: string;
type: "error";
}
| {
type: string;
};

A top-level JSONL event from codex exec --experimental-json.


CodexThreadItem​

type CodexThreadItem =
| {
id: string;
text: string;
type: "agent_message";
}
| {
id: string;
text: string;
type: "reasoning";
}
| {
aggregated_output: string;
command: string;
exit_code?: number;
id: string;
status: "in_progress" | "completed" | "failed";
type: "command_execution";
}
| {
changes: CodexFileUpdateChange[];
id: string;
status: "completed" | "failed";
type: "file_change";
}
| {
arguments: unknown;
error?: {
message: string;
};
id: string;
result?: unknown;
server: string;
status: "in_progress" | "completed" | "failed";
tool: string;
type: "mcp_tool_call";
}
| {
id: string;
query: string;
type: "web_search";
}
| {
id: string;
items: object[];
type: "todo_list";
}
| {
id: string;
message: string;
type: "error";
}
| {
id: string;
type: string;
};

One item in a Codex thread.

Eight kinds on the tested wire. Every field this package READS is optional or guarded at the point of use even inside a kind we recognise: the version gate holds the boundary, but a vendor moving a field WITHIN an event it still calls item.completed would otherwise crash translation on a wire the gate had already approved.


CodexTurnInput​

type CodexTurnInput =
| string
| (
| {
text: string;
type: "text";
}
| {
path: string;
type: "local_image";
})[];

A turn's input, as the SDK's Input takes it: the prompt alone, or the prompt and the paths of the turn's images.


ResolveCodexClient​

type ResolveCodexClient = (ctx) =>
| ResolvedCodexClient
| Promise<ResolvedCodexClient>;

Host hook resolving the Codex client for a block invocation.

Accepts the block context loosely so a fully parameterized execute context passes without a cast — the same reason ResolveClaudeCodeAgent does.

Parameters​

ctx​

BlockContext<any, any, any, any, any, any, any, any, any>

Returns​

| ResolvedCodexClient | Promise<ResolvedCodexClient>

Variables​

CODEX_PASS​

const CODEX_PASS: readonly ["PATH", "HOME", "USER", "SHELL", "TMPDIR", "HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy", "CODEX_HOME", "CODEX_API_KEY", "CODEX_CA_CERTIFICATE", "SSL_CERT_FILE"];

The only variables of the server's environment a Codex run needs, for client: { env: harnessEnv({ pass: CODEX_PASS }) } with harnessEnv from @flow-state-dev/core. Without a list, the Codex CLI inherits the server's whole process.env, every key, token and connection string in it.

Core's HARNESS_BASE_PASS and this harness's own names: PATH (its shell finds commands through it), HOME and CODEX_HOME (Codex keeps its sign-in and its threads there, so a thread is found again only under the same home), USER, SHELL and TMPDIR (its shell), CODEX_API_KEY, and the proxy and CA settings a proxied network needs, in upper and lower case.

It filters what a run starts with, not what it can read: a command the run starts as the server's OS user can still read the server's own environment. Pass the same environment to probeCodexAccount, listCodexModels and readCodexUsage, so they see the account the run sees. A host that needs more passes its own list.


CODEX_SIGN_IN_REMEDY​

const CODEX_SIGN_IN_REMEDY: "Run `codex login`, or set CODEX_API_KEY" = "Run `codex login`, or set CODEX_API_KEY";

What the user does when Codex has no credential.


CODEX_SOURCE​

const CODEX_SOURCE: "codex/sdk";

This harness's <package>/<door> name — the convention every writer of a harness handle's source owes. The suffix names the door we drive Codex through, and this package has exactly one: OpenAI's own SDK.


codexAgentHandleSchema​

const codexAgentHandleSchema: z.ZodObject<object & object, "strip", z.ZodTypeAny, {
codexUsage: | {
cachedInputTokens: number;
cacheWriteInputTokens: number;
inputTokens: number;
outputTokens: number;
reasoningOutputTokens: number;
}
| null;
cost: | {
basis: "estimated" | "reported";
usd: number;
}
| null;
dispatchedAt: number;
failureMessage: string | null;
finalMessage: string | null;
outcome: "failed" | "finished" | "stopped-at-limit" | null;
sessionId: string | null;
source: "codex/sdk";
status: "completed" | "errored";
url: string | null;
usage: | {
inputTokens: number;
outputTokens: number;
}
| null;
}, {
codexUsage?: | {
cachedInputTokens: number;
cacheWriteInputTokens: number;
inputTokens: number;
outputTokens: number;
reasoningOutputTokens: number;
}
| null;
cost?: | {
basis: "estimated" | "reported";
usd: number;
}
| null;
dispatchedAt: number;
failureMessage?: string | null;
finalMessage?: string | null;
outcome?: "failed" | "finished" | "stopped-at-limit" | null;
sessionId: string | null;
source: "codex/sdk";
status: "completed" | "errored";
url: string | null;
usage?: | {
inputTokens: number;
outputTokens: number;
}
| null;
}>;

Runtime validator for CodexAgentHandle.

The extension's own two fields default to null for the same reason the neutral schema's four do: a handle persisted before they existed still parses.

Functions​

checkCodexReadiness()​

function checkCodexReadiness(options): Promise<HarnessReadiness>;

Whether Codex can run on this machine, as core's neutral readiness: an installed SDK in the range this package tested, then the answer of probeCodexAccount, with what to do when there is no credential. A key counts only when the SDK also loads, since a run needs both. A host hands it to whatever keeps readiness (harness-manager's harnessReadiness). Never throws.

Parameters​

options​

CodexReadinessOptions

Returns​

Promise<HarnessReadiness>


codexAgent()​

function codexAgent(options?): BlockDefinition<ZodObject<{
attachments: ZodOptional<ZodArray<ZodObject<{
data: ZodEffects<ZodString, string, string>;
filename: ZodOptional<ZodString>;
mediaType: ZodString;
type: ZodLiteral<"file">;
}, "strip", ZodTypeAny, {
data: string;
filename?: string;
mediaType: string;
type: "file";
}, {
data: string;
filename?: string;
mediaType: string;
type: "file";
}>, "many">>;
prompt: ZodString;
}, "strip", ZodTypeAny, {
attachments?: object[];
prompt: string;
}, {
attachments?: object[];
prompt: string;
}>, ZodObject<object & object, "strip", ZodTypeAny, {
codexUsage: | {
cachedInputTokens: number;
cacheWriteInputTokens: number;
inputTokens: number;
outputTokens: number;
reasoningOutputTokens: number;
}
| null;
cost: | {
basis: "reported" | "estimated";
usd: number;
}
| null;
dispatchedAt: number;
failureMessage: string | null;
finalMessage: string | null;
outcome: "finished" | "stopped-at-limit" | "failed" | null;
sessionId: string | null;
source: "codex/sdk";
status: "completed" | "errored";
url: string | null;
usage: | {
inputTokens: number;
outputTokens: number;
}
| null;
}, {
codexUsage?: | {
cachedInputTokens: number;
cacheWriteInputTokens: number;
inputTokens: number;
outputTokens: number;
reasoningOutputTokens: number;
}
| null;
cost?: | {
basis: "reported" | "estimated";
usd: number;
}
| null;
dispatchedAt: number;
failureMessage?: string | null;
finalMessage?: string | null;
outcome?: "finished" | "stopped-at-limit" | "failed" | null;
sessionId: string | null;
source: "codex/sdk";
status: "completed" | "errored";
url: string | null;
usage?: | {
inputTokens: number;
outputTokens: number;
}
| null;
}>, {
attachments?: object[];
prompt: string;
}, CodexAgentHandle> & object;

Build the Codex harness block.

Refuses to build against an installed @openai/codex-sdk that is not the tested version, and against an option group carrying a working directory or a turn signal. Both are configuration errors a host sees at wiring time.

Parameters​

options?​

CodexAgentOptions

Returns​

BlockDefinition<ZodObject<{ attachments: ZodOptional<ZodArray<ZodObject<{ data: ZodEffects<ZodString, string, string>; filename: ZodOptional<ZodString>; mediaType: ZodString; type: ZodLiteral<"file">; }, "strip", ZodTypeAny, { data: string; filename?: string; mediaType: string; type: "file"; }, { data: string; filename?: string; mediaType: string; type: "file"; }>, "many">>; prompt: ZodString; }, "strip", ZodTypeAny, { attachments?: object[]; prompt: string; }, { attachments?: object[]; prompt: string; }>, ZodObject<object & object, "strip", ZodTypeAny, { codexUsage: | { cachedInputTokens: number; cacheWriteInputTokens: number; inputTokens: number; outputTokens: number; reasoningOutputTokens: number; } | null; cost: | { basis: "reported" | "estimated"; usd: number; } | null; dispatchedAt: number; failureMessage: string | null; finalMessage: string | null; outcome: "finished" | "stopped-at-limit" | "failed" | null; sessionId: string | null; source: "codex/sdk"; status: "completed" | "errored"; url: string | null; usage: | { inputTokens: number; outputTokens: number; } | null; }, { codexUsage?: | { cachedInputTokens: number; cacheWriteInputTokens: number; inputTokens: number; outputTokens: number; reasoningOutputTokens: number; } | null; cost?: | { basis: "reported" | "estimated"; usd: number; } | null; dispatchedAt: number; failureMessage?: string | null; finalMessage?: string | null; outcome?: "finished" | "stopped-at-limit" | "failed" | null; sessionId: string | null; source: "codex/sdk"; status: "completed" | "errored"; url: string | null; usage?: | { inputTokens: number; outputTokens: number; } | null; }>, { attachments?: object[]; prompt: string; }, CodexAgentHandle> & object


codexHarness()​

function codexHarness(options?): Harness;

Codex as a harness value.

Parameters​

options?​

CodexHarnessOptions

The Codex block's options. Its client's environment is always Codex's own.

Returns​

Harness


createCodexAgentCapability()​

function createCodexAgentCapability(options?): DefinedCapability<"codex-agent", Record<string, never>, "default" | "tools", Record<string, PresetDef<any>>, undefined, {
[x: string]: DeclaredResourceEntry;
}, undefined, undefined, undefined> & object;

Create the Codex agent capability. Forwards every agent option to the underlying handler — including the version gate, which therefore refuses here too rather than at the first run.

Parameters​

options?​

CodexAgentOptions

Returns​

DefinedCapability<"codex-agent", Record<string, never>, "default" | "tools", Record<string, PresetDef<any>>, undefined, { [x: string]: DeclaredResourceEntry; }, undefined, undefined, undefined> & object


createDefaultResolveCodexClient()​

function createDefaultResolveCodexClient(clientOptions?, importSdk?): ResolveCodexClient;

Build a resolver that loads the SDK via importSdk and constructs its client with clientOptions. Throws CodexSdkNotInstalledError when the module cannot be loaded or does not export Codex.

Exported mainly so a test can supply an importer that rejects; production uses the default the block installs for itself.

Parameters​

clientOptions?​

CodexClientOptions

importSdk?​

CodexSdkImporter

Returns​

ResolveCodexClient


findCodexProgram()​

function findCodexProgram(env, options?): Promise<CodexProgram>;

Find the Codex program the SDK would start, the way the SDK finds it.

The SDK resolves its platform binary (from @openai/codex, pinned beside it) when its client is constructed, which starts nothing. So a usage read and a run start the same program and read the same sign-in.

Parameters​

env​

Record<string, string>

options?​
importSdk?​

CodexSdkImporter

Returns​

Promise<CodexProgram>

Throws​

When the SDK can't be loaded, or doesn't say where its program is.


listCodexModels()​

function listCodexModels(options): Promise<HarnessModelList>;

Ask Codex for the models its picker offers, without a run.

Parameters​

options​

ListCodexModelsOptions

Returns​

Promise<HarnessModelList>

models, the default first, or failed with a reason. Never throws.


probeCodexAccount()​

function probeCodexAccount(options): Promise<CodexAccountProbe>;

Ask Codex whether it has a credential, without a model turn (see the file header). Never throws.

Parameters​

options​

ProbeCodexAccountOptions

Returns​

Promise<CodexAccountProbe>


readCodexUsage()​

function readCodexUsage(options): Promise<HarnessUsageReading>;

Read Codex's subscription usage, with no run.

Parameters​

options​

ReadCodexUsageOptions

Returns​

Promise<HarnessUsageReading>

windows with every window Codex reports; api-key or signed-out when there is no subscription number to read; unavailable with a plain reason when the read could not be made. Never throws.