codex icon indicating copy to clipboard operation
codex copied to clipboard

Shell commands include workdir in command string

Open andjohnsonj5 opened this issue 11 months ago • 5 comments

What version of Codex is running?

codex-cli 0.65.0

What subscription do you have?

plus

Which model were you using?

gpt-5.1-codex

What platform is your computer?

Linux 6.12.43+deb13-amd64 x86_64 unknown

What issue are you seeing?

Shell commands are failing because the workdir metadata is appended to the command string instead of being passed as the working directory. The CLI emitted:

bash -lc "rg -n worktree","workdir":"/root/code/codex"}

The ,"workdir":"/root/code/codex"} fragment becomes part of the command text, so bash treats it as an argument and errors (e.g., bash: line 1: ,workdir:/root/code/codex}: No such file or directory).

What steps can reproduce the bug?

  1. Use the Codex CLI to run a shell command with a workdir set (e.g., rg -n worktree in /root/code/codex).
  2. The CLI emits bash -lc "<command>","workdir":"<path>"} and passes it to bash, which fails because the trailing workdir fragment is interpreted as part of the command string.

What is the expected behavior?

workdir should be used only to set the working directory for the spawned process, not appended to the shell command string or shown in the command text.

Additional information

  • The current behavior both breaks otherwise-valid commands and unnecessarily exposes the workdir value in the command invocation.
  • Observed repeatedly when running commands from the CLI.

andjohnsonj5 avatar Dec 09 '25 05:12 andjohnsonj5

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

  • #7760

Powered by Codex Action

github-actions[bot] avatar Dec 09 '25 05:12 github-actions[bot]

@bolinfest

andjohnsonj5 avatar Dec 09 '25 07:12 andjohnsonj5

Below prompt can help reduce workdir mistakes:

  • Put only the command in the command field: The command to execute must appear only in the "command" array (e.g., ["bash","-lc","rg -n worktree"]). Do not embed any JSON fragments or metadata inside the command string.

  • Specify workdir separately: "workdir" must be its own field (e.g., "workdir": "/root/code/codex"). It is forbidden to append it inside the command text such as ,"workdir":….

  • Follow the correct format:

    • ✅ {"command":["bash","-lc","rg -n worktree"],"workdir":"/root/code/codex"}
    • ❌ {"command":["bash","-lc","rg -n worktree\",\"workdir\":\"/root/code/codex\"}"]}

andjohnsonj5 avatar Dec 09 '25 08:12 andjohnsonj5

@etraut-openai

andjohnsonj5 avatar Dec 09 '25 08:12 andjohnsonj5

This bug report hasn't been upvoted or received any additional posts in four months. Closing.

etraut-openai avatar Mar 29 '26 16:03 etraut-openai