Clean Up Copied Code Formatting on Mac
Clean Up Copied Code Formatting on Mac
Copy a snippet from a chat app, a PDF, or a web page and it almost never pastes cleanly. You get curly "smart" quotes instead of straight ones, non-breaking spaces, broken indentation, or invisible characters that make the compiler complain. ClipHistory fixes this at the clipboard level so the code you paste is the code you meant.
The problem with copied code
Rich-text sources mangle code in predictable ways:
- Smart quotes (
"") replace straight quotes and break string literals. - Non-breaking spaces look like spaces but are different bytes.
- Trailing whitespace and inconsistent indentation sneak in.
- Zero-width characters ride along invisibly from web pages.
Pasting that into an editor produces syntax errors that are hard to spot because the code looks right.
Clean it from the clipboard
ClipHistory keeps a history of everything you copy, reachable with the global shortcut Cmd+Shift+V. Any clip can be run through an AI transform, and the one you want here is Clean.
- Copy the snippet from wherever it lives.
- Press Cmd+Shift+V to open ClipHistory.
- Select the clip and choose the Clean transform.
- Paste the cleaned version into your editor.
Clean normalizes the text: it straightens quotes, strips stray characters, and tidies spacing so the snippet behaves like plain code again.
Pair Clean with your editor's formatter
Clean handles the characters; your editor's formatter (Prettier, gofmt, Black, and so on) handles style. The good combination is Clean first to remove the junk, then format in the editor for canonical indentation. Clean removes the errors a formatter cannot, because a formatter chokes on a syntax error before it can reformat.
Your own API key, your own model
The Clean transform runs through whichever AI provider you connect with your own API key. ClipHistory supports five: Anthropic, OpenAI, DeepSeek, Google, or a custom endpoint. There is no hosted service and no per-use fee from ClipHistory; you pay your provider directly.
For cleaning code, even a smaller, cheaper model usually does the job, since the task is mechanical normalization rather than reasoning.
Snippets: stop re-cleaning the same code
If you paste the same boilerplate often, clean it once and save it as a snippet in ClipHistory. Snippets are reusable clips you can recall any time, so you only pay the cleaning cost once. Combined with boards for grouping related snippets, you can build a tidy library of ready-to-paste code.
Everything stays on your Mac
ClipHistory stores your clips, snippets, and history locally. There is no cloud and no account. The only thing transmitted is the clip you explicitly run through a transform, sent to your configured provider. Code you never transform stays entirely on your machine, which matters when the snippet contains keys, internal paths, or proprietary logic.
A note on the paste stack
When you are assembling several snippets, ClipHistory's paste stack lets you queue multiple clips and paste them in order. Clean each one, stack them, and paste them sequentially into your file without juggling the clipboard.
A concrete example
You copy this from a chat app:
const greeting = "hello world";
It looks fine, but the quotes are curly and there is a non-breaking space before the semicolon. Paste it and your compiler throws an error pointing at a line that appears correct. Run Clean first and the quotes become straight, the space becomes a normal space, and the snippet compiles. The whole detour took one shortcut.
Why this beats manual fixes
There are other ways to clean code, and each has a drawback:
- By hand: reliable but slow, and easy to miss invisible characters you cannot see.
- A regex or shell pipeline: fast once written, but you have to remember it and run it somewhere.
- An editor plugin: works only inside that editor, not on text from a PDF or chat.
Clean at the clipboard covers the gap: it works on text from any app, requires nothing to remember, and runs from the same shortcut you already use for paste history.
Privacy for proprietary code
Code is often the most sensitive thing on your machine: keys, internal endpoints, business logic. Pasting it into a random "format my code" website is a real risk. With ClipHistory the cleaned text is produced either locally or by the single provider you configured with your own key, and only the clip you explicitly transform is sent. Snippets you never transform stay entirely on disk.
Why fix it at the clipboard
You could clean code by hand or with a regex you keep forgetting. Doing it at the clipboard means the fix happens in the same place the problem appears: between copy and paste. It works no matter which app the code came from, and the cleaned result is sitting right there, ready to paste, behind a single shortcut. ClipHistory is a universal binary for Apple Silicon and Intel, runs on macOS 12 or later, and is signed and notarized by Apple.
Ready to put AI one keystroke away? Get ClipHistory for macOS for a one-time $19.99 (12-month license, no auto-renewal). Signed and notarized by Apple, universal binary, everything stays on your Mac.