Support STDIN as PROMPT for large input

Open 💬 7 comments Opened May 26, 2025 by doggy8088

This is a feature suggestion.

When I need to input a lot of prompt content, I hope to have the following methods to replace directly passing in the last argument:

  1. STDIN

``sh
cat PROMPT.md | codex
``

  1. Specify a file

``sh
codex --file PROMPT.md
``

View original on GitHub ↗

7 Comments

surajssd · 1 year ago

For me codex freezes when I pass in the stdin.

Lekyaira · 11 months ago

You can use

``codex "$(cat <prompt-file>)"``
but having it use stdio would open up some pretty powerful tool chaining. Should probably run in headless mode for this.

surajssd · 10 months ago

I wasn't using the exec subcommand hence codex used to freeze. But now this workes for me:

➜  git diff --cached | codex exec "Write a commit message for these staged changes"
doggy8088 · 10 months ago
I wasn't using the exec subcommand hence codex used to freeze. But now this workes for me: `` ➜ git diff --cached | codex exec "Write a commit message for these staged changes" ``

@surajssd I tested. The codex will not read STDIN from the git diff --cached command output when there is a PROMPT in the argument.

@easong-openai I wish codex can read both STDIN and the PROMPT.

surajssd · 10 months ago

@doggy8088 you are right, I tried to recreate the same issue and I can now see that codex is running git diff --staged again. I had a wrong assumption that it was reading STDIN.

cd `mktemp -d`
git init
echo "foo" | tee README.md
git status
git add .
git diff --cached

Finally when running the command:

➜  git diff --cached | codex exec "Write a commit message for these staged changes"
[2025-09-04T16:20:04] OpenAI Codex v0.29.0 (research preview)
--------
workdir: /private/var/folders/ls/csbb474j2r9__hhcvmxq0rfh0000gn/T/tmp.g9rYxumPfE
model: grok-3
sandbox: read-only
--------
[2025-09-04T16:20:04] User instructions:
Write a commit message for these staged changes
[2025-09-04T16:20:07] exec git diff --staged in /private/var/folders/ls/csbb474j2r9__hhcvmxq0rfh0000gn/T/tmp.g9rYxumPfE
[2025-09-04T16:20:07] git diff --staged succeeded in 30ms:
diff --git README.md README.md
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ README.md
@@ -0,0 +1 @@
+foo
[2025-09-04T16:20:07] codex
I'll help you write a commit message for the staged changes. Let me check what's been modified.


[2025-09-04T16:20:09] codex
Based on the diff, I see you've added a README.md file with the content "foo". Here's a commit message for these changes:

**Commit Message**

- **README**: Add initial project documentation file

If you'd like me to adjust the tone or content of this message, just let me know!
nhickster · 7 months ago

To address why running codex "$(cat <prompt-file>)" is not a valid solution, if you run it on large prompt files, you get this error:

> codex "$(Get-Content C:\dev\Misc\BuildOutput.txt)"

Program 'node.exe' failed to run: The filename or extension is too longAt C:\Program
Files\nodejs\codex.ps1:16 char:5
+     & "$basedir/node$exe"  "$basedir/node_modules/@openai/codex/bin/c ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At C:\Program Files\nodejs\codex.ps1:16 char:5
+     & "$basedir/node$exe"  "$basedir/node_modules/@openai/codex/bin/c ...

Note: This is on windows, so I'm using Get-Content instead of cat, but I see a similar error on linux and macOS when using cat.

The title of this issue even says "for large input". One of the main reasons I use STDIN for claude and copilot CLI is to automate passing large prompts with a lot of context, or even just pass the output of a long log file. Not accepting STDIN is a serious limitation with codex.

Eriz1818 · 6 months ago

I implemented stdin/file prompt input support in my fork, xCodex (xcodex). If you need this today, you can try it as a workaround (it’s still WIP and may have bugs): https://github.com/Eriz1818/xCodex.

If maintainers are interested in bringing this upstream, I’m happy to open a proposal/PR and adapt it to match Codex’s contribution guidelines and desired behaviour (I understand new feature PRs may not be accepted right now). I’ve tested with PROMPT.md files up to ~1MB. Both xcodex exec (non-interactive) and xcodex (interactive) can be used.

1) Prompt as a file (large prompts)
xcodex exec --file PROMPT.md

2) Prompt via stdin (pipe)
cat PROMPT.md | xcodex exec -

3) Prompt via stdin (heredoc)
xcodex exec - <<'EOF'
Write a one-paragraph summary of this repository.
EOF