codex icon indicating copy to clipboard operation
codex copied to clipboard

Remove 2 leading spaces from cmd suggestion

Open Spacetime99 opened this issue 10 months ago • 19 comments

What version of Codex is running?

codex-cli 0.80.0

What subscription do you have?

ChatGPT+

Which model were you using?

5.2

What platform is your computer?

Linux 6.14.0-34-generic x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

MacOS Terminal

What issue are you seeing?

When codex suggests a cmd to run, e.g. inline PY or a cmd line with a line wrap, the simple copy / paste fails because there are 2 leading spaces indenting each output line. So these will split up things like URL's that should be a single string. Here's an example:
Run it the same way: /home/spacetime/codex/scripts/run_single_story_extract.sh /home/spacetime/codex/datasets/news_ingest/news_reports_20260110T030329Z.jsonl https://www.pennlive.com/news/2026/01/anti-ice- protesters-assemble-in-harrisburg-as-fallout-from-minnesota-shooting-grows.html

anti-ice-protestors, gets 2 spaces inserted after ice-

What steps can reproduce the bug?

Just ask it to suggest a cmd line that line wraps on a couple or more lines, where the spaces will interrupt it.

What is the expected behavior?

No spaces to indent multi line cmd's, place them all on the left, slighly less pretty, but much more functional

Additional information

No response

Spacetime99 avatar Jan 15 '26 02:01 Spacetime99

This is also on Windows Terminal (WSL Ubuntu) too.

My current workaround is to copy, paste into VSCode, and use the shift+alt drag for multi-cursor select all lines with two spaces or none, press Space then Backspace (since not all cursors have selected the two spaces prefixes per line). Now I have a clean command to copy-paste.

https://github.com/user-attachments/assets/c6705281-f3a3-4b19-8c3b-aaef2a8efab9

ignatremizov avatar Jan 15 '26 08:01 ignatremizov

It also bites me everytime when I copy things from terminal

SunRunAway avatar Jan 15 '26 11:01 SunRunAway

Here's a workaround I just came up with. I run it in another terminal after the agent has finished responding, and I get its last message without the extra indentation. Then I can copy properly from there. Helps both with indentation issues and when codex outputs what should be long one-liners. Not a solution, but a good enough workaround for me.

tail -n1 $(ls -t ~/.codex/sessions/*/*/*/*.jsonl | head -n1) | jq -r '.payload.last_agent_message'

emilan avatar Feb 18 '26 20:02 emilan

@emilan I wonder if you could pipe that into clipboard with an extra regex... On windows git bash you can echo text | clip.exe, not sure about equivalent macos/Linux... but I imagine it's possible to create a "copy commands to clipboard" Skill and just let codex get the command copied directly

ignatremizov avatar Feb 18 '26 21:02 ignatremizov

@emilan I wonder if you could pipe that into clipboard with an extra regex... On windows git bash you can echo text | clip.exe, not sure about equivalent macos/Linux... but I imagine it's possible to create a "copy commands to clipboard" Skill and just let codex get the command copied directly

Any terminal emulator that supports OSC52 can be told to put data in the system clipboard. For desktop terminal emulators like Windows Terminal, this means it will be put in the Windows clipboard. This also works fine in SSH sessions, containers, etc, also when started from WSL.

Put this little helper on your target (e.g. in .bashrc):

clip ()
{
    local b64;
    b64=$(base64 | tr -d '\n');
    printf '\e]52;c;%s\a' "$b64"
}

Then invoke it like

my-cmd | clip

emilan avatar Feb 19 '26 07:02 emilan

@etraut-openai might you be interested in a PR to make the indent configurable? Copy/pasting shell commands from codex was bugging me so I addressed it locally by adding a config for the indent in https://github.com/ahornby/codex/commit/28dc14792b5657188919371eff362dd3c34671b2

Before, spaces break here document terminator:

$ codex "show me a simple bash shell command using a here document"
╭─────────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.111.0)                  │
│                                             │
│ model:     gpt-5.3-codex   /model to change │
│ directory: ~/local/codex/codex-rs           │
╰─────────────────────────────────────────────╯

  Tip: New Use /fast to enable our fastest inference at 2X plan usage.


› show me a simple bash shell command using a here document


• cat <<'EOF'
  Hello from a here document.
  EOF
Token usage: total=5,783 input=5,762 (+ 6,528 cached) output=21

After, no spaces:

$ ./target/debug/codex -c tui.continuation_indent=0 "show me a simple bash shell command using a here document"
╭─────────────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0)                    │
│                                             │
│ model:     gpt-5.3-codex   /model to change │
│ directory: ~/local/codex/codex-rs           │
╰─────────────────────────────────────────────╯

  Tip: This is a test announcement


› show me a simple bash shell command using a here document


• cat <<'EOF'
Hello from a here document.
This is line 2.
EOF
Token usage: total=5,550 input=5,523 (+ 6,656 cached) output=27

ahornby avatar Mar 08 '26 15:03 ahornby

+1

WAY29 avatar Mar 19 '26 05:03 WAY29

+1

bradmccormick avatar Apr 02 '26 16:04 bradmccormick

Please guys downvote to hell @etraut-openai because he says this is by "design" and closed as no planned...

https://github.com/openai/codex/issues/16431#issuecomment-4174267698

What a joke CLI without basic features when others have this fixed from beggining, Opencode is years light better than Codex in UI design.

dhaern avatar Apr 11 '26 03:04 dhaern

Very excited to see movement on this issue - thank you to those commiting!

haydonryan avatar May 23 '26 02:05 haydonryan

Very excited to see movement on this issue - thank you to those commiting!

Did you try raw mode? Default keymap is alt-r but you can remap it with /keymap

fcoury-oai avatar May 23 '26 03:05 fcoury-oai

Wasn't aware that raw mode was a feature. That does help. I still question if there's a better way.

haydonryan avatar May 26 '26 12:05 haydonryan

the /raw support unblocks but as put in a conversation with gemini: ok. Now option-r works to switch to raw mode. So I can get ugly but can copy and paste and pretty but deadly time-wasting trap.

Exactly! You have summed it up perfectly: "Ugly but functional" vs. "Pretty but a deadly time-wasting trap."It is a frustrating trade-off, but at least you can now use Option + R like a quick toggle switch. Press it to drop into "ugly mode" right before you drag-select your text, copy it, and then instantly press it again to return to the cleaner layout view.

:-)

youngjoel avatar Jun 04 '26 23:06 youngjoel

Thank you very much @fcoury-oai for the raw mode, this is very useful ! Would you consider a follow-up to make fenced shell-like command blocks copy cleanly while leaving the rest of the response in rich mode ?

Suggested shape:

  • Detect fenced code blocks whose info string is shell-like, e.g. sh, bash, zsh, shell, console, terminal, powershell, pwsh, ps1, cmd, bat.
  • Keep using the existing syntax-highlighted code-block renderer for those blocks.
  • Mark the rendered lines as copy-sensitive command lines.
  • Skip the assistant gutter (• / two-space continuation padding) for those lines only.
  • Preserve each source command line as one logical line and let the terminal soft-wrap long lines where possible, rather than hard-wrapping them before insertion into scrollback.
  • Apply this to both streamed output and finalized history cells.

This should fix common heredoc and multiline-command cases without forcing the entire transcript into /raw.

samronsin avatar Jun 14 '26 21:06 samronsin

On iTerm2 (and any decent terminal) you can press cmd-option while selecting text in order to select a rectangle instead of entire lines. Solves the problem completely and I don’t see why Claude should downgrade its TUI to accommodate your lack of understanding of the basic controls of your terminal.

devnoname120 avatar Sep 18 '26 22:09 devnoname120

On iTerm2 (and any decent terminal) you can press cmd-option while selecting text in order to select a rectangle instead of entire lines. Solves the problem completely and I don’t see why Claude should downgrade its TUI to accommodate your lack of understanding of the basic controls of your terminal.

Funny you should mention Claude, because Claude handles this perfectly. Its code blocks are indented, yet ordinary cursor selection does not start at the beginning or include two-space indents. Not only that, selection copies text automatically so no keyboard shortcuts are needed at all.

reedlaw avatar Sep 18 '26 23:09 reedlaw

Yes please to this fix.

adrianegraphene avatar Sep 18 '26 23:09 adrianegraphene

With the new default fullscreen mode, copy operations no longer include incidental display formatting like spaces, so this is no longer an issue.

etraut-openai avatar Oct 12 '26 00:10 etraut-openai

Hello, thank you @etraut-openai for the update. Sorry to be that guy, but for us --no-alt-screen (also tui.alternate_screen = "never") people, this issue is still relevant.

Glad to read that the fullscreen mode solves the issue though, will give it a second chance.

samronsin avatar Oct 12 '26 13:10 samronsin