fix(exec): prevent -i/--image from consuming PROMPT (clap greedy variadic)

Open 💬 1 comment Opened Aug 25, 2026 by shoemoney
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

Bug

codex exec -i image.png "describe this" --skip-git-repo-check silently consumes the prompt:

  • SharedCliOptions at codex-rs/utils/cli/src/shared_options.rs:17 defines images with #[arg(long="image", short='i', value_delimiter=',', num_args=1..)]
  • With num_args=1.. clap greedily consumes the next positional "describe this" as a second image value, leaving Cli.prompt=None
  • Execution falls through to read_prompt_from_stdin() in exec/src/lib.rs:2038 and fails No prompt provided via stdin

Reordering to codex exec "describe this" -i image.png works. Same root at codex-rs/cli/src/main.rs:289 for the TUI entrypoint.

Repro

  • Before: codex exec -i /tmp/a.png "hello" parses as images=["/tmp/a.png", "hello"] prompt=None
  • After: same command parses as images=["/tmp/a.png"] prompt=Some("hello")comma a.png,b.png and repeated -i a.png -i b.png still work

Fix (branch ready to cherry-pick)

Branch pushed to shoemoney/codex:fix/exec-image-clap-greedy @ 1cf455e:

  • codex-rs/utils/cli/src/shared_options.rs:17 num_args=1..num_args=1
  • codex-rs/cli/src/main.rs:289 same change
  • With num_args=1 + value_delimiter=',' each -i consumes exactly one arg that may contain comma-separated paths, so the following positional PROMPT is not eaten. ForkArgs/ResumeArgs in codex-rs/exec/src/cli.rs:171,204 already use num_args=1 as the correct pattern.

Diff: https://github.com/openai/codex/compare/main...shoemoney:fix/exec-image-clap-greedy

Evidence: local clap repro (before → images=[a.png, hello] prompt=None, after → images=[a.png] prompt=Some(hello)), cargo check -p codex-utils-cli 24s pass, cargo fmt --check pass.

Note

PR creation is blocked by collaborators_only (GraphQL FORBIDDEN + REST 404 on CreatePullRequest), so filing as an issue the maintainer can cherry-pick from (per CONTRIBUTING.md).

Written in conjunction with my pair programmer Claude.

View original on GitHub ↗

1 Comment

github-actions[bot] contributor · 2 days ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #40545

Powered by Codex Action