Codex
Codex adapter contract
Overview
@stax/codex is the canonical stax adapter for Codex.
Codex differs from Claude Code and OpenClaw in two important ways:
- instructions are discovered through
AGENTS.md/AGENTS.override.mdfiles along the directory path - MCP, sandboxing, approvals, and some skill controls live in TOML configuration (
config.toml)
This adapter targets the documented Codex file contract described in 17 — Runtime File Contracts.
Scope model
| Scope | Typical files |
|---|---|
| User | ~/.codex/config.toml, ~/.codex/AGENTS.md, $HOME/.agents/skills/** |
| Project | .codex/config.toml, AGENTS.md, .agents/skills/** |
| System / admin | /etc/codex/config.toml, /etc/codex/skills/** |
| State | ~/.codex/auth.json, ~/.codex/history.jsonl, logs, caches |
In stax 1.0.0, @stax/codex SHOULD default to project scope.
Adapter interface
interface CodexAdapterOptions {
model?: string;
modelParams?: Record<string, unknown>;
scope?: "project" | "user";
exact?: boolean;
approval?: "untrusted" | "on-request" | "never";
sandbox?: "read-only" | "workspace-write" | "danger-full-access";
allowLoginShell?: boolean;
writeConfig?: boolean; // default: true
writeInstructions?: boolean; // default: true
writeSkills?: boolean; // default: true
writeMcp?: boolean; // default: true
config?: Record<string, unknown>; // extra Codex TOML keys
}The compiled adapter config SHOULD use:
{
"type": "codex",
"runtime": "codex",
"adapterVersion": "1.0.0"
}Exact target mapping
Project scope
| stax source | Target |
|---|---|
surfaces/instructions.md or composed prompt | AGENTS.md |
instructionTree | <scoped-path>/AGENTS.md |
| skills | .agents/skills/** |
| MCP layer | .codex/config.toml under [mcp_servers.*] |
| adapter config | .codex/config.toml |
User scope
| stax source | Target |
|---|---|
surfaces/instructions.md or composed prompt | ~/.codex/AGENTS.md |
| skills | $HOME/.agents/skills/** |
| MCP layer | ~/.codex/config.toml under [mcp_servers.*] |
| adapter config | ~/.codex/config.toml |
AGENTS.md behavior
Codex instruction discovery is hierarchical.
Documented behavior
- In
CODEX_HOME(default~/.codex), Codex readsAGENTS.override.mdif present, otherwiseAGENTS.md - In a project, Codex walks from repo root down to the current directory
- In each directory, it checks
AGENTS.override.mdfirst, thenAGENTS.md - It includes at most one instruction file per directory
- Files closer to the current directory appear later and therefore override earlier guidance
stax mapping policy
stax supports both one canonical instruction surface and an optional instruction tree:
- without
instructionTree,@stax/codextargets one exact file location at a time - with 38 — Instruction Trees, the adapter MAY materialize a discovered multi-directory AGENTS hierarchy
Root mapping remains:
- project root
AGENTS.md, or - user
~/.codex/AGENTS.md
config.toml generation
Codex stores runtime configuration, MCP config, approval policy, and sandbox policy in TOML.
Example output
model = "gpt-5-codex"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
allow_login_shell = false
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
[mcp_servers.context7.env]
MY_ENV_VAR = "MY_ENV_VALUE"Mapping rules
modelmaps from adaptermodel- approval and sandbox options map to top-level TOML keys
- canonical MCP servers map to
[mcp_servers.<name>]tables - stdio server env maps to
[mcp_servers.<name>.env] - remote servers map to
urland related supported fields - unsupported canonical fields MUST trigger warnings
Skills mapping
Codex scans skills from several locations. stax SHOULD materialize project skills into:
.agents/skills/<skill>/SKILL.mdand user skills into:
$HOME/.agents/skills/<skill>/SKILL.mdRules:
- preserve the skill directory exactly
- preserve
SKILL.mdbytes exactly - preserve support files exactly
- do not rewrite runtime-specific skill metadata unless required by policy
Approval and sandbox defaults
Codex exposes approval and sandboxing as first-class config.
The adapter SHOULD map:
- stax capability hints into suggested defaults where reasonable
- but MUST preserve explicit adapter options over generic hints
Example policy:
hints.capabilities.shell = truedoes not automatically implydanger-full-access- explicit
sandbox: 'workspace-write'wins over inferred settings
What the adapter MUST NOT own
@stax/codex MUST NOT package or write by default:
~/.codex/auth.json~/.codex/history.jsonl- logs and caches
- ephemeral trust or approval state
- admin-wide
/etc/codex/**files unless explicitly requested by an administrator
Exactness requirements
An implementation claiming exact Codex support SHOULD:
- write valid TOML to
.codex/config.tomlor~/.codex/config.toml - preserve project skill directories under
.agents/skills/ - write exact
AGENTS.mdwhen source instructions exist - materialize instruction-tree entries to scoped
AGENTS.mdfiles when present - avoid writing state or credential files
- warn or fail when composition or unsupported TOML fields make output lossy