Skip to content

feat: forward CODEX_PLUGIN_CC_ARGS to codex launches#419

Open
klmklmnb wants to merge 2 commits into
openai:mainfrom
klmklmnb:feat/codex-plugin-cc-args
Open

feat: forward CODEX_PLUGIN_CC_ARGS to codex launches#419
klmklmnb wants to merge 2 commits into
openai:mainfrom
klmklmnb:feat/codex-plugin-cc-args

Conversation

@klmklmnb

@klmklmnb klmklmnb commented Jul 2, 2026

Copy link
Copy Markdown

What

Adds a CODEX_PLUGIN_CC_ARGS environment variable. When set, its value is tokenized (shell-style, reusing the existing splitRawArgumentString) and prepended to every codex invocation the plugin makes:

  • the codex app-server runtime spawn (app-server.mjs), which covers both direct and broker modes
  • the availability checks codex --version and codex app-server --help (codex.mjs)

Example:

export CODEX_PLUGIN_CC_ARGS='-c model_provider=litellm'
# plugin now runs: codex -c model_provider=litellm app-server

Why

Closes #418. Previously only --model/--effort were forwarded and the app-server was always spawned bare, so there was no way to pass Codex global overrides (custom model_provider, --profile, arbitrary -c key=value) without editing config.toml. This makes it opt-in via a single env var, reusing Codex's own config-override surface.

Changes

  • scripts/lib/args.mjs: new getCodexPassthroughArgs(env) + CODEX_PLUGIN_ARGS_ENV constant
  • scripts/lib/app-server.mjs: prepend args to the codex app-server spawn (reads the same env passed to the child)
  • scripts/lib/codex.mjs: prepend args to the availability checks
  • tests/fake-codex-fixture.mjs: tolerate leading global flags before the subcommand; record boot argv
  • tests/args.test.mjs (new): unit tests for the parser
  • tests/runtime.test.mjs: e2e test asserting the args reach the codex process
  • README.md: documents the variable, quoting, and the shared-runtime caveat

Testing

npm test — 95/95 passing locally.

Notes

  • Args are prepended (before the subcommand), the canonical position for Codex global flags like -c / --profile.
  • Read when a Codex runtime starts; if a shared runtime is already active for the session, a fresh session is needed for new values to take effect (documented in the README).

Add a CODEX_PLUGIN_CC_ARGS environment variable. When set, its value is
tokenized (shell-style) and prepended to every codex invocation the plugin
makes: the app-server runtime spawn and the availability checks.

This lets users force codex global overrides (e.g. a custom provider via
`-c model_provider=...` or `--profile`) without editing config.toml, and
without a per-command flag. Previously only --model/--effort were forwarded
and the app-server was always spawned as `codex app-server`.

- args.mjs: getCodexPassthroughArgs(env) + CODEX_PLUGIN_ARGS_ENV
- app-server.mjs: prepend args to the `codex app-server` spawn
- codex.mjs: prepend args to `--version` / `app-server --help` checks
- fake codex fixture: tolerate leading global flags, record boot argv
- tests: unit tests for the parser + e2e passthrough assertion
- README: document the variable

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@klmklmnb klmklmnb requested a review from a team July 2, 2026 11:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da5b881948

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (typeof raw !== "string" || !raw.trim()) {
return [];
}
return splitRawArgumentString(raw);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve quoted backslashes in passthrough args

When users put a global argument whose value contains literal backslashes in CODEX_PLUGIN_CC_ARGS—for example the documented --add-dir path flag with a Windows path like --add-dir 'C:\work\repo'—this new env path calls splitRawArgumentString(), which treats \ as an escape even inside single quotes; the argv becomes ["--add-dir","C:workrepo"] before spawning Codex. That launches Codex with the wrong directory/config value, so the passthrough should use a parser that preserves quoted backslashes or otherwise handle Windows paths explicitly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in f6f1ab7. splitRawArgumentString now handles single-quote context before the escape check, so single-quoted content is literal (POSIX semantics) and --add-dir 'C:\work\repo' survives intact. Double-quote escaping is unchanged. Added unit tests covering single-quote backslashes, double-quote escaping, and unquoted escapes.

klmklmnb pushed a commit to klmklmnb/codex-plugin-cc that referenced this pull request Jul 3, 2026
splitRawArgumentString treated `\` as an escape even inside single quotes,
so CODEX_PLUGIN_CC_ARGS values like `--add-dir 'C:\work\repo'` were mangled
into `C:workrepo`. Handle single-quote context before the escape check so
single-quoted content is literal (POSIX semantics); double-quote escaping
is unchanged.

Addresses the Codex review comment on openai#419.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6f1ab7714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/codex/mcp/lib/tools.mjs Outdated
pushValue(args, "--scope", input.scope);
pushValue(args, "--model", input.model);
pushValue(args, "--cwd", input.cwd);
args.push("--background", "--json");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make MCP review calls actually non-blocking

Here codex_review maps MCP tool calls to review --background --json, but that flag does not enqueue a review job in the companion: handleReviewCommand parses --background and then unconditionally awaits runForegroundCommand (checked in plugins/codex/scripts/codex-companion.mjs). The existing slash-command flow detaches reviews through Claude's Bash run_in_background; an MCP tool call has no such wrapper, so longer reviews block the MCP request and return the final review payload instead of the advertised job id/status. Please either implement a real background review path for this invocation or make the MCP review tool foreground/timeout-aware.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — but this file was included in the PR by mistake. plugins/codex/mcp/** and tests/mcp-server.test.mjs are unrelated to this change (which only adds the CODEX_PLUGIN_CC_ARGS passthrough); they got swept into a git add -A for a follow-up commit. I've rewritten that commit and force-pushed, so these files are no longer part of the PR. This MCP background-review concern is therefore out of scope here — happy to open a separate issue for it if it's a real problem on main.

Comment thread plugins/codex/scripts/lib/args.mjs Outdated
Comment on lines +120 to +124
escaping = true;
continue;
}

if (quote) {
if (quote === "\"") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve double-quoted backslashes in passthrough args

Fresh evidence after the single-quote fix: in the current code, double-quoted values still hit the generic backslash escape before quote === "\"" is handled. With CODEX_PLUGIN_CC_ARGS='--add-dir "C:\\work\\repo"', splitRawArgumentString() returns ['--add-dir','C:workrepo'], even though the README promises shell-like parsing and POSIX double quotes keep backslashes before ordinary characters. This launches Codex with the wrong path/config whenever users choose double quotes around a Windows path; handle double-quote escaping selectively or preserve \ before non-special chars.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 2f75ad1. splitRawArgumentString now applies POSIX double-quote semantics: a backslash only escapes " \ $ and stays literal before any other character, so--add-dir "C:\work\repo" is preserved ("a"b"still yieldsa"b`). Both single- and double-quote backslash cases now have unit tests. Note the fix commit was rewritten (force-push) to drop some files that were included by mistake — see the reply on the other thread.

splitRawArgumentString treated `\` as an escape regardless of quote context,
so CODEX_PLUGIN_CC_ARGS values with backslashes were mangled — e.g.
`--add-dir 'C:\work\repo'` and `--add-dir "C:\work\repo"` both became
`C:workrepo`.

Apply POSIX quoting semantics:
- single quotes: everything literal, including backslashes
- double quotes: backslash only escapes " \ $ ` ; before any other char it
  stays literal (so `"a\"b"` still yields `a"b`)

Adds unit tests for single/double-quote backslash handling.
Addresses the Codex review comments on openai#419.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@klmklmnb klmklmnb force-pushed the feat/codex-plugin-cc-args branch from f6f1ab7 to 2f75ad1 Compare July 3, 2026 02:39
@klmklmnb

klmklmnb commented Jul 3, 2026

Copy link
Copy Markdown
Author

@codex review

The parsing feedback (single- and double-quote backslash handling) is addressed in 2f75ad1, and the unrelated plugins/codex/mcp/** + tests/mcp-server.test.mjs files that were accidentally swept into an earlier commit have been removed via force-push. Please re-review the current head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2f75ad1621

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: forward extra args (custom model_provider / profile) to every codex launch

2 participants