Skip to content

feat(ocx): native token injection for Codex without the wrapper shim (systemd --user drop-in or equivalent) #2713

Description

@rrmlima

Area

CLI; Authentication and account pool; Service lifecycle; Platform (Linux).

What are you trying to accomplish?

I need Codex CLI processes launched on a Linux server to reach an OpenCodex provider configured with:

[model_providers.opencodex]
base_url = "http://127.0.0.1:10100/v1"
env_key = "OPENCODEX_API_AUTH_TOKEN"

without depending on a wrapper installed at the same filesystem path as the Codex binary. The token must remain outside config.toml, and Codex upgrades must not silently remove the credential injection mechanism.

What prevents this today?

env_key tells Codex which process environment variable to read; it does not create that variable. OpenCodex's current solution, ocx codex-shim install, replaces the Codex launcher with a POSIX wrapper that reads the service token and exports OPENCODEX_API_AUTH_TOKEN.

Codex upgrades can replace that path with a symlink or a fresh binary. After that, codex exec fails before reaching the proxy:

ERROR: Missing environment variable: `OPENCODEX_API_AUTH_TOKEN`.

Validated on OpenCodex 2.33.0 and Codex CLI 0.149.1:

Launch state Result
OpenCodex shim installed HTTP 200; turn.completed; request recorded in usage.jsonl
Direct symlink to the real Codex binary, env absent Immediate missing-variable error; no proxy request
Direct binary with token manually exported Works, confirming the missing environment is the only blocker

The current workaround is to reinstall the shim after every Codex update or maintain an external cron that detects and repairs it.

What should OpenCodex do?

Provide and document a shim-independent credential injection mode while preserving the current secure default:

  1. A first-class Linux environment integration, such as ocx codex-env install, that installs a user-scoped environment generator/drop-in and can be audited/uninstalled; or
  2. A provider credential-file directive supported by the Codex integration, allowing the launcher to read /root/.opencodex/service-api-token without storing the secret in config.toml or inheriting it through a shell wrapper.

At minimum, ocx doctor should detect the invalid combination "provider uses env_key + environment variable absent + shim absent" and print an actionable repair command.

The behavior should be idempotent, never print the token, create files with restrictive permissions, and survive Codex upgrades.

Example usage or interface

# Proposed first-class alternative
ocx codex-env install --mode systemd-user
ocx codex-env status
ocx codex-env uninstall

# Expected diagnostic
ocx doctor
# ERROR: model_providers.opencodex uses env_key=OPENCODEX_API_AUTH_TOKEN,
# but the variable is unavailable and no credential injector is active.
# Run: ocx codex-env install

Before/after behavior:

# Current, after a Codex upgrade overwrites the shim
codex exec "reply OK"
# ERROR: Missing environment variable: OPENCODEX_API_AUTH_TOKEN

# Expected after native environment integration
codex exec "reply OK"
# request reaches OpenCodex and completes

Alternatives or workarounds

  • ocx codex-shim install: works, but shares the executable path with Codex and is overwritten by upgrades.
  • Exporting the token manually in shell profiles: incomplete for GUI/systemd/non-interactive launches and spreads secret handling across user files.
  • systemctl --user set-environment: process-session scoped and not durable by itself.
  • External daily repair script: effective locally but duplicates lifecycle logic that belongs in OpenCodex.

Additional context

Environment tested:

  • OpenCodex 2.33.0
  • Codex CLI 0.149.1
  • Linux, root-owned server deployment
  • OpenCodex proxy at 127.0.0.1:10100

Related shim work: #1441.

Checks

  • I searched existing issues and documentation.
  • This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
  • I removed secrets and personal data.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliCLI, config inject, packaging flagsenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions