Skip to content

app-server spawn strips all environment variables, breaking non-OpenAI model providers #160

Closed

Description

@Bhuvanesh09

Bug

When using a non-OpenAI model provider configured via env_key in ~/.codex/config.toml, invoking codex through the Claude Code plugin fails with:

Missing environment variable: DATABRICKS_TOKEN

Running codex directly from the terminal works fine.

Root Cause

In plugins/codex/scripts/lib/app-server.mjs, SpawnedCodexAppServerClient.initialize() spawns codex app-server with:

this.proc = spawn("codex", ["app-server"], {
  cwd: this.cwd,
  env: this.options.env,  // always undefined — no caller passes env in options
  ...
});

In Node.js, spawn() with env: undefined gives the child process no environment variables at all. The codex app-server subprocess can't see any env vars, so it fails when initializing model providers that require them.

Expected Behavior

The spawned codex app-server process should inherit the parent's environment variables when no explicit env is provided, matching the existing pattern in broker-lifecycle.mjs (line 146) and codex-companion.mjs (line 617).

Steps to Reproduce

  1. Configure a non-OpenAI model provider in ~/.codex/config.toml with env_key = "DATABRICKS_TOKEN" (or any custom env var)
  2. Export that env var in your shell
  3. Invoke the codex plugin from Claude Code
  4. Observe the Missing environment variable error

Suggested Fix

- env: this.options.env,
+ env: this.options.env ?? process.env,
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions