codex icon indicating copy to clipboard operation
codex copied to clipboard

Allow /copy to target a specific assistant response by id

Open michaelbrylevskii opened this issue 6 months ago • 6 comments

What problem are you trying to solve?

In the Codex CLI TUI, /copy currently copies the latest assistant response as markdown. That is useful, but it is hard to copy an earlier assistant response cleanly.

The current workaround is either:

  • ask Codex to repeat the earlier answer and then run /copy, which burns tokens and adds friction;
  • manually select text in the terminal, which often captures extra indentation, soft-wrap artifacts, or surrounding TUI formatting.

This is especially painful when copying markdown/code blocks from previous answers into chats, tickets, docs, or issue comments.

Related broader request: #2880. This issue is a narrower request for addressable copy of a specific message.

Proposed solution

Add a way for /copy to target a specific assistant response.

Possible command shapes:

/copy          # current behavior: copy latest assistant response
/copy 12       # copy assistant response with id 12
/copy a12      # copy assistant response with explicit assistant-message id
/copy last-2   # copy the previous assistant response

The TUI could expose compact ids for assistant messages, for example:

assistant #42
...

Alternatively, ids could stay out of the main transcript and be discoverable through /history or message metadata.

Why this would help

This would make /copy useful for more than the latest response while preserving clean markdown output and avoiding terminal-selection artifacts.

michaelbrylevskii avatar May 22 '26 12:05 michaelbrylevskii

One implementation note from current main: the TUI already keeps a bounded copy history, not only a single last-response string.

  • codex-rs/tui/src/chatwidget.rs sets MAX_AGENT_COPY_HISTORY to 32.
  • codex-rs/tui/src/chatwidget/transcript.rs stores agent_turn_markdowns keyed by visible user-turn count.
  • /copy is still described as "copy last response as markdown" in codex-rs/tui/src/slash_command.rs, and dispatches to copy_last_agent_markdown() in codex-rs/tui/src/chatwidget/slash_dispatch.rs.

So this may not require inventing persistence for older responses from scratch. The missing piece appears to be an addressable selector/argument path plus user-visible labels or metadata for the retained responses.

yui-stingray avatar May 22 '26 14:05 yui-stingray

We need the ability to copy individual commands/blocks.

Like if Codex is giving me a bunch of commands to run in a terminal, it should be easy to copy them.

nullbio avatar May 23 '26 23:05 nullbio

Any updates?

michaelbrylevskii avatar Jun 30 '26 03:06 michaelbrylevskii

This would be a great addition to bring Codex in line with most other coding agents.

bendavis78 avatar Aug 13 '26 22:08 bendavis78

I found a workaround for copying an earlier assistant response using Codex CLI's existing conversation rewind functionality.

Steps:

  1. Press Esc Esc to enter conversation history.
  2. Navigate back to the exchange containing the assistant response you want.
  3. Press Enter to restore that point in the conversation.
  4. Run /copy to copy the restored assistant response as Markdown.

I tested this successfully while extracting an earlier Codex response to create a UAT runbook for a project.

Caveat: Rewinding changes the conversation state and can discard subsequent conversation context from the active path. In my case, I was finishing the session anyway, so that was acceptable.

This is a useful workaround for anyone who needs to retrieve an earlier response and doesn't mind rewinding. However, the proposed enhancement remains valuable: being able to select and copy an arbitrary previous assistant response without modifying the current conversation state would be substantially better.

RobertKielty avatar Oct 21 '26 10:10 RobertKielty

@michaelbrylevskii, there is a native route for reusing an earlier answer without the rewind step: Codex CLI 0.171.0 has /export → Save to file (or Copy to clipboard) for the complete conversation as Markdown. Open that .md in your editor, find the earlier response, and copy from the Markdown source. The released export menu shows both options.

I maintain the free Codex Desk and am researching this earlier-answer reuse workflow. For your next ticket or doc, which earlier response would you want to copy, and does native export plus your editor now settle it—or is locating the right response still awkward?

blucca avatar Nov 29 '26 10:11 blucca