Skip to main content

Strip the gutter and padding from terminal output you've copied, so you can paste it cleanly.

Project description

pastecleaner

Strip the gutter and padding from terminal output you've copied, so you can paste it cleanly elsewhere.

The problem

Modern terminal agents and TUIs render output inside a bordered panel with a vertical gutter glyph on the left. This shows up in Claude Code, Codex CLI, Aider, Cursor's agent chat, Goose, Plandex, lazygit, k9s, and most git log --graph views. When you select + copy that text, you get:

  • the gutter character (, , , etc.) on every line
  • leading whitespace to indent past the gutter
  • trailing padding spaces to the terminal width
  • hard line breaks at the terminal width, not at paragraph boundaries

So a single flowing paragraph pastes as a jagged block that has to be hand-edited before it's usable in an email, doc, or issue.

Before:

▎ Heads up on the cache-invalidation pass: the current TTL sweep runs per-key      
  ▎ and holds the write lock for the whole batch, which stalls writers under load.  
  ▎                                                                                  
  ▎ Switching to a chunked sweep with a 256-key batch should fix it.                 

After pastecleaner:

Heads up on the cache-invalidation pass: the current TTL sweep runs per-key and holds the write lock for the whole batch, which stalls writers under load.

Switching to a chunked sweep with a 256-key batch should fix it.

Install

pipx install pastecleaner

Or from source:

git clone https://github.com/bray-solo-tsaina/pastecleaner
pipx install ./pastecleaner

Usage

pastecleaner file.txt              # clean to stdout
pastecleaner -i file.txt           # rewrite file in place
pastecleaner -c                    # read clipboard, write back to clipboard (macOS)
pbpaste | pastecleaner | pbcopy    # same idea, explicit
cat output.log | pastecleaner      # stdin

Flags

  • -c, --clipboard: read from the clipboard, write back to the clipboard (macOS; uses pbpaste/pbcopy)
  • -i, --in-place: rewrite the input file
  • --unwrap / --no-unwrap: force paragraph unwrapping on or off. Default is auto: on when a gutter is detected, off otherwise.

Supported gutter glyphs

Any of these are recognized as a left gutter and stripped: ▎ │ ┃ ▏ ▌ ▍ ▐. If none of them appear in the input, pastecleaner just trims trailing whitespace and leaves structure alone.

Running automatically

Four ways to avoid remembering to run pastecleaner -c yourself. Pick whichever matches your workflow. They're all optional; the manual CLI works fine on its own.

1. Clipboard-watcher daemon (macOS, recommended)

A tiny background process that polls the pasteboard and auto-cleans any content containing a gutter glyph. Runs at login, works across every app and terminal, zero keypresses.

Install:

pipx install pastecleaner        # provides both `pastecleaner` and `pastecleaner-watch`
mkdir -p ~/Library/LaunchAgents
pastecleaner-watch --print-plist > ~/Library/LaunchAgents/com.pastecleaner.watch.plist
launchctl load ~/Library/LaunchAgents/com.pastecleaner.watch.plist

Check it's running:

launchctl list | grep pastecleaner
tail -f /tmp/pastecleaner-watch.log /tmp/pastecleaner-watch.err

Uninstall:

launchctl unload ~/Library/LaunchAgents/com.pastecleaner.watch.plist
rm ~/Library/LaunchAgents/com.pastecleaner.watch.plist

The daemon only rewrites the clipboard when it sees one of the supported gutter glyphs; normal copy/paste is untouched.

2. Hotkey (one keypress)

Bind pbpaste | pastecleaner | pbcopy to a shortcut in:

  • Raycast: Create Script Command → Shell Script, paste the pipeline, assign a hotkey.
  • Alfred: Workflow → Hotkey → Run Script, same pipeline.
  • macOS Shortcuts app (built-in): New Shortcut → Run Shell Script, pick a keyboard shortcut in the shortcut's settings.

Then: copy as usual, tap your hotkey, paste.

3. Slash command (Claude Code example)

Drop this in ~/.claude/commands/clean.md to invoke from Claude Code via /clean:

---
description: Clean the clipboard of terminal gutter/padding
---

Run `pastecleaner -c` in the shell.

Adaptable to any agent that can register a shell-invoking command. Aider's /commands, Codex CLI's tool hooks, and Cursor's custom agent commands all work similarly: have the command shell out to pastecleaner -c.

4. Post-response hook (Claude Code example, caveat)

You can wire a hook into ~/.claude/settings.json to run pastecleaner -c after every response:

{
  "hooks": {
    "Stop": [
      { "hooks": [{ "type": "command", "command": "pastecleaner -c" }] }
    ]
  }
}

Caveat: the hook fires when Claude finishes its response, before you've had a chance to select and copy text. It only helps if you habitually copy during Claude's output (e.g. from a long reply) and paste afterwards. For anything else, the watcher daemon (option 1) is a better fit.

The same idea works with any agent that exposes a post-response or idle hook; the watcher daemon (option 1) is a catch-all that needs no agent support at all.

Development

git clone https://github.com/bray-solo-tsaina/pastecleaner
cd pastecleaner
python -m venv .venv && . .venv/bin/activate
pip install -e '.[dev]'
pytest

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pastecleaner-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pastecleaner-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pastecleaner-0.2.0.tar.gz.

File metadata

  • Download URL: pastecleaner-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pastecleaner-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9e17375f7400aa07344589109ae2d6daa9d3771d1b27851eb979783c5a7b2e09
MD5 5d63d3f9f446be238105e1812d068305
BLAKE2b-256 a2f9fc8f6fa8b2bad82142e19464a21468681be2125dfbe57576f98e636aff18

See more details on using hashes here.

File details

Details for the file pastecleaner-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pastecleaner-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pastecleaner-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e36834e1837020ad5c236a8a4b486d35d63bb9f6876dfdf8665b4a48c7a62dcc
MD5 5e73fa7ef47ed38dde21e9aaedc66727
BLAKE2b-256 aa63ea6fe2bd389208dbac5b9a1d47b0cb2cb619da59d59c1178b301653cc510

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page