EnerBrain Agency· Documentation
Adapters › Agent Adapters

Codex

OpenAI Codex local adapter setup and configuration

The codex_local adapter runs OpenAI's Codex CLI locally. It supports session persistence via previous_response_id chaining and skills injection through the global Codex skills directory.

Prerequisites

Configuration Fields

Field Type Required Description
cwd string Yes Working directory for the agent process (absolute path; created automatically if missing when permissions allow)
model string No Model to use
promptTemplate string No Prompt used for all runs
env object No Environment variables (supports secret refs)
timeoutSec number No Process timeout (0 = no timeout)
graceSec number No Grace period before force-kill
fastMode boolean No Enables Codex Fast mode. Currently supported on gpt-5.4 only and burns credits faster
dangerouslyBypassApprovalsAndSandbox boolean No Skip safety checks (dev only)

Session Persistence

Codex uses previous_response_id for session continuity. The adapter serializes and restores this across heartbeats, allowing the agent to maintain conversation context.

Skills Injection

The adapter symlinks EnerBrain Agency skills into the global Codex skills directory (~/.codex/skills). Existing user skills are not overwritten.

Fast Mode

When fastMode is enabled, EnerBrain Agency adds Codex config overrides equivalent to:

-c 'service_tier="fast"' -c 'features.fast_mode=true'

EnerBrain Agency currently applies that only when the selected model is gpt-5.4. On other models, the toggle is preserved in config but ignored at execution time to avoid unsupported runs.

Managed CODEX_HOME

When EnerBrain Agency is running inside a managed worktree instance (PAPERCLIP_IN_WORKTREE=true), the adapter instead uses a worktree-isolated CODEX_HOME under the EnerBrain Agency instance so Codex skills, sessions, logs, and other runtime state do not leak across checkouts. It seeds that isolated home from the user's main Codex home for shared auth/config continuity.

Per-agent isolation and auth seeding

For codex_local agents the server isolation guard pins each agent to a per-agent home (<instance>/companies/<companyId>/agents/<agentId>/codex-home) and sets OPENAI_API_KEY="" so an agent can never spend against the host API key or share another agent's Codex state.

A managed home is created empty, so the adapter must provision auth into it before launching Codex — otherwise the agent runs with zero credentials and the provider returns 401 Missing bearer. The seeding contract:

Auth ownership and precedence

codex_local is host-owns-auth when EnerBrain Agency owns the effective CODEX_HOME. The winning credential file is:

  1. Per-agent API key: when adapter env contains a non-empty OPENAI_API_KEY, EnerBrain Agency writes $CODEX_HOME/auth.json with only { "OPENAI_API_KEY": "..." }. This overwrites any existing file or symlink at that path. Codex CLI versions that EnerBrain Agency supports read the key from auth.json, not directly from the process environment.
  2. Host ChatGPT-subscription login: when no per-agent key is configured, EnerBrain Agency symlinks auth.json from the shared host Codex home into the managed home. The symlink keeps rotating/single-use refresh tokens live instead of copying a stale token into the managed home.
  3. External CODEX_HOME: if adapter env points CODEX_HOME outside the EnerBrain Agency-managed company tree, that home is self-managed. EnerBrain Agency does not seed or overwrite it, so its own auth.json wins.

For sandbox or SSH execution, EnerBrain Agency uploads the effective managed CODEX_HOME and launches Codex with CODEX_HOME pointing at that uploaded directory. Any auth.json already baked into the sandbox image is shadowed in managed-home mode. If the host has no usable auth.json and no per-agent OPENAI_API_KEY, the managed run fails fast instead of falling back to an in-sandbox login.

Worked example: a worker runs in a sandbox image that already has $HOME/.codex/auth.json, and the EnerBrain Agency host is logged in with a ChatGPT subscription. For a managed codex_local agent, EnerBrain Agency symlinks the host auth.json into the agent's managed home, uploads that home to the sandbox, and sets CODEX_HOME to the uploaded path. Codex reads the host-owned uploaded file, so the sandbox image login does not win.

For high-concurrency sandbox fleets, prefer a per-agent OPENAI_API_KEY over a shared ChatGPT-subscription login. API-key mode produces a standalone auth.json for each managed home and avoids many concurrent sandboxes sharing one rotating subscription credential. The tradeoff is billing: API-key mode is metered per token through the OpenAI API, while ChatGPT-subscription auth uses the subscription's flat-plan economics and quota behavior. Pick the mode deliberately for the fleet's cost and concurrency profile.

Deferred config-validation warning spec

This section specifies a warning that is not implemented yet. The warning should help operators notice the host-owns-auth topology before they run a sandbox fleet with ChatGPT-subscription credentials.

Because the warning touches authentication behavior, its implementation needs a maintainer security review before merge. Treat this docs section as the follow-up implementation spec, not as authorization to add the warning in a docs-only change.

Manual Local CLI

For manual local CLI usage outside heartbeat runs (for example running as codexcoder directly), use:

npx paperclipai agent local-cli codexcoder --company-id <company-id>

This installs any missing skills, creates an agent API key, and prints shell exports to run as that agent.

Instructions Resolution

If instructionsFilePath is configured, EnerBrain Agency reads that file and prepends it to the stdin prompt sent to codex exec on every run.

This is separate from any workspace-level instruction discovery that Codex itself performs in the run cwd. EnerBrain Agency does not disable Codex-native repo instruction files, so a repo-local AGENTS.md may still be loaded by Codex in addition to the EnerBrain Agency-managed agent instructions.

Environment Test

The environment test checks: