How to copy terminal output on Mac without the formatting mess
Every Mac terminal copies output a little differently — trailing spaces, extra newlines, prompt prefixes that paste as > at the start of every line. The fixes are per-terminal: iTerm2 has explicit preferences, Warp has known multi-line issues, Ghostty's config is minimal, Terminal.app has no trim option. A clipboard manager with source-app tagging like Maus doesn't fix the formatting, but it stops you from losing the original when you re-copy with edits.
Why terminals copy weird
A terminal is a grid of cells. When a line of output ends before the right edge, the terminal fills the rest with spaces — because there's no "blank" cell, there are only space-cells and other-character-cells. When you drag-select multiple lines, those padding spaces get copied as real 0x20 bytes. vim is the worst offender: it writes spaces to clear the screen between buffer redraws, so even one-line files come out trailed with spaces all the way to column 80.
Then layered on top:
- Line-wrap breaks. One logical line wrapped across two visual rows. Copy it and you get a newline in the middle of what was one line of output.
- Prompt prefixes. Copy a selection that starts before your prompt and every line includes
$,%,>or whatever your$PS1renders. - ANSI escape codes. Most terminals strip these on copy. Some don't always, and you end up pasting
\x1b[0;32msequences into Claude. - Trailing newline. Some terminals add a final
\non copy; some don't. Pasting at a shell prompt with a trailing newline auto-executes the command — sometimes good, sometimes a footgun.
iTerm2 — the most configurable
iTerm2 exposes the relevant controls in Preferences → General → Selection:
- "Copied text includes trailing newline." If enabled, selections that include a terminal newline carry it to the pasteboard; if disabled, no selection ever includes one. Disable this if you keep accidentally executing pasted commands.
- Smart selection (rules under Preferences → Selection → Edit smart selection rules). Lets you double-click on a path, URL, or other recognizable pattern and select just that, not the surrounding cell padding.
- Rectangular selection. Hold
Optionwhile dragging to select a rectangle — useful when you want to grab just the right-hand column of a table and skip the prompt prefix on the left.
For the trailing-spaces-from-vim problem, there's a long-standing iTerm2 issue (#1677) — vim paints spaces to the right margin and they end up in your copy. The workaround the maintainer suggests in issue #1793: bind a key to a Coprocess that runs pbpaste | tr -d "\n" or similar post-processing on the clipboard.
Warp — multi-line is the rough edge
Warp's block-based UX is great for reading output, but the copy/paste pipeline has documented quirks:
- Issue #4796 — multi-line commands pasted into Warp end up with output touching the prompt with no spacing, because Warp's prompt handling assumes each block is one command.
- Issue #4247, #4314, #4811 — clipboard sync between Warp and the system pasteboard isn't always two-way; users report copies inside Warp not showing up in other apps and vice versa.
- Issue #465 — formatting lost when pasting from outside Warp into editors like nano running inside Warp.
The practical move with Warp:
- Copy block-by-block. Warp's "copy block output" is the cleanest path — it gives you just the output of one command without the prompt or input.
- For multi-line paste into a remote shell: paste into a scratch buffer first, verify line breaks, then re-copy and paste into Warp.
- For sharing with Claude: use block copy, then check the paste is clean before sending.
Ghostty — minimal config, minimal surprises
Ghostty's config reference exposes a basic copy_to_clipboard action and a copy_on_select behavior, but it doesn't document the same trim-trailing-whitespace controls iTerm2 has. The terminal is fast and clean, but the copy story is "what you select is what you get" — including any padding spaces or prompt prefixes you grabbed.
The pragmatic Ghostty flow:
- Select carefully — start the selection at the first character of the actual output, not before the prompt.
- For multi-line output, use
scriptor pipe topbcopydirectly:your-command | pbcopyskips the terminal copy path entirely. - For partial selections from a busy buffer, the pipe trick isn't available — that's where a clipboard manager helps you not lose the original copy when you re-do it.
Terminal.app — least configurable
The built-in Terminal includes trailing whitespace to the right edge of the window and has no documented option to trim it. There's no equivalent to iTerm2's "trim trailing whitespace" setting. The realistic options:
- Resize the window narrower before copying so there's less padding.
- Pipe to
pbcopywhen you can. - Post-process: paste into a scratch buffer, clean up, copy again.
- Switch to iTerm2 or Ghostty if this matters daily.
Claude Code's own copy issue
Worth knowing if you're a Claude Code user: there's an open issue (#18170) in the Claude Code repo about copying from the TUI. Copied text retains leading indentation that matches the visual padding for prompt symbols (> and ·) plus trailing whitespace. Code blocks in particular paste back unindented and need manual cleanup. The issue notes this was briefly fixed and then regressed.
Until it's fixed upstream, the workaround inside Claude Code is to copy with care (start selection after the prompt indent) or post-process the paste.
Pipe to pbcopy when you can
The terminal-quirk-free path is to skip the terminal selection entirely:
git diff | pbcopy
cat error.log | tail -50 | pbcopy
echo $PATH | pbcopy
No padding spaces, no prompt prefix, no line wrap weirdness — the bytes go straight from stdout to the pasteboard. This is the move when you know in advance you'll need to paste the output somewhere. It doesn't help when you've already run the command and are looking at the output deciding "ok, that's the part I want to paste."
Where a clipboard manager fits in
Trim settings and pbcopy handle the prevention side. The cleanup side — when you've already copied something messy and need to redo it — is where having every copy in history saves time.
With Maus:
- Every copy attempt is kept. Copied a selection with prompt prefixes, then re-copied without them? Both are in your history. If you mess up the cleanup, the original is still there.
- Source-app tagging. Each clip is tagged with the app it came from. Search by
warp,ghostty,iterm,terminalto filter just terminal copies when you've also been copying from Slack, browser, IDE. - Multipaste. Copied three separate command outputs you want to send to Claude in sequence? Open Maus,
⌘+Clickeach in order,⏎pastes them all. - Pin recurring outputs. The same
kubectl get podsoutput you reference repeatedly during a debug session — pin it so you can compare against later runs without scrolling back.
What Maus does not do: it doesn't auto-strip trailing whitespace from your copies. The terminal-side fixes above are the right tools for that. Maus's job is to make sure you don't lose copies when you redo them, and to make the history searchable when the copy you want is two hours back.
A workflow that holds up under load
- iTerm2 or Ghostty as your daily terminal (better copy story than Terminal.app).
- Enable "Copied text includes trailing newline" → off in iTerm2 to avoid accidentally executing pasted commands.
- Pipe to
pbcopywhenever you know the output is going to the clipboard. Cleanest path. - For ad-hoc selections, a clipboard manager so you can re-copy without losing the original.
- For pasting into Claude or Cursor, source-app filter (
iterm,warp,ghostty) makes "which terminal copy did I want" a one-keystroke filter instead of a scroll.
FAQ
Why does copying from the terminal include extra spaces?
The terminal grid fills the rest of each line with spaces. Selecting multi-line output copies those padding spaces as real characters. iTerm2 has a trim preference; Terminal.app does not. vim is especially bad because it actively writes spaces to clear the screen.
Does Ghostty handle copy formatting differently from iTerm2?
Ghostty's documented config is minimal — basic copy_to_clipboard action, copy_on_select behavior. It doesn't expose the same trim controls iTerm2 has. Selection care plus pbcopy piping is the workflow.
Why does Warp paste produce weird multi-line behavior?
Documented issues: multi-line commands touch the prompt with no spacing (#4796), clipboard sync between Warp and macOS isn't always two-way (#4247, #4314, #4811). Block-by-block copy is the cleanest path inside Warp.
How do I copy from a terminal so Claude or Cursor reads it as code?
Select carefully (skip the prompt), pipe to pbcopy when you can, and use a clipboard manager that tags clips by source app so you can find the clean one when you've made multiple copy attempts.
Is there a way to strip the prompt symbol from copied lines?
Not built into most terminals. Even Claude Code itself has an open issue (#18170) about this. The fix is post-processing or careful selection. A clipboard manager keeps every attempt available.
Stop losing copies when you redo them
Maus keeps every ⌘C from your terminal, tagged by source app. When you re-copy the same output with the prompt stripped, the messy original is still there if you need it. Free with 24h history. Pro $12.99 once for unlimited.