How to Copy Code From a Screenshot (Clean & Private)
Published 2026-11-24 · Local browser OCR
Copying prose from a screenshot is forgiving — a missing comma still reads fine. Copying code from a screenshot is brutal: one 0 read as O, one curly quote, or one dropped underscore breaks the whole script.
Here is the fastest workflow for turning a code screenshot, stack trace, or terminal window into runnable text — and the exact six characters you should always check before running it.
Why copying code locally matters more than usual
Developer screenshots leak secrets without looking like secrets. A terminal window shows internal hostnames, AWS account IDs, .env paths, customer IDs in a stack trace, or proprietary source code from a private repository.
Uploading that screenshot to a random cloud OCR website puts internal code on someone else's server. Shot2Text runs Tesseract directly inside your browser tab — the image never leaves your machine, which you can verify in your browser's Network panel.
The clean workflow for code screenshots
- Crop out the gutter and line numbers. Leaving line numbers (
14,15,16) inside your screenshot forces the reader to merge them into the start of every line of code. Drag your screenshot box strictly around the code itself. - Zoom in before capturing. If the code is in a browser, documentation page, or YouTube tutorial, zoom to 150% or go full-screen first. Monospace punctuation (
.,,,;,:,',`) vanishes below 12–14 pixels tall. - Avoid low-contrast dark themes when you have a choice. Dark editors with pastel syntax colors (muted red or blue on charcoal) convert poorly to greyscale. If you control the screen, switch to a light theme for five seconds before screenshotting. If you cannot (for example, a colleague's screenshot or a video), crop tightly so bright window borders do not skew contrast.
- Paste straight from the clipboard (
Ctrl + V/⌘ + V) into Shot2Text instead of exporting a compressed JPG. PNG or raw clipboard captures keep sharp pixel edges on thin characters like|and/. - Run a formatter after pasting. Plain OCR does not reliably preserve 2-space vs 4-space indentation. Paste the extracted text into VS Code (or your editor) and run Prettier, Black,
gofmt, orrustfmt— it fixes indentation instantly and flags any syntax typo immediately.
The six character pairs OCR gets wrong in code
Even on a sharp screenshot, scan your pasted code for these six classic OCR swaps before running a command:
| What was in the image | What OCR often outputs | Where it bites hardest |
|---|---|---|
0 (zero) vs O (capital O) |
Swapped either way | Hex codes, port numbers, hashes, CLI flags |
1 (one) vs l (lowercase L) vs I (capital I) |
Merged into l or 1 |
Variable names, URLs, Base64 tokens |
_ (underscore) |
Dropped or read as - or space |
Python snake_case, env vars |
' / " / ` |
Curly quotes or missing backticks | Shell commands, JS template literals |
{ / } / ( / ) |
Misread as [ or 1 |
JSON objects, arrow functions |
== / === / != |
Collapsed to = or l= |
Conditionals (valid syntax, wrong logic!) |
Never paste OCR'd shell commands straight into a production terminal. Paste into a scratch editor first, glance over flags like -rf, paths, and hostnames, then run it.
Honest limits: when not to use plain OCR for code
- Two-column diffs (GitHub split view): Plain OCR reads line by line across the entire width of the image, which interleaves the left and right columns into gibberish. Crop one side of the diff at a time.
- Tiny screenshots sent over Slack or WhatsApp: Chat apps recompress PNGs into fuzzy JPEGs. Ask for the raw code block or the original PNG if punctuation looks smeared — see best image format for OCR for why compression destroys thin characters.
- Python indentation inside huge screenshots: Because Python uses whitespace for structure, paste smaller 15–25 line blocks rather than a full 80-line screen, so fixing indentation takes seconds.
For general troubleshooting on blurry captures, check why OCR comes out messy and six ways to fix it or how to copy text from a YouTube video.
Quick answers
- Does screenshot-to-text preserve code indentation?
- No. Plain OCR reads characters accurately on sharp captures but does not reliably reconstruct 2-space or 4-space indentation. Paste the extracted text into your editor and run an auto-formatter (Prettier, Black, gofmt) to restore clean indentation and highlight syntax typos.
- Should I include editor line numbers in a code screenshot?
- Always crop out line numbers before running OCR. Otherwise, the reader treats line numbers as the first token of every line of code, forcing you to delete them manually line by line.
- Is it safe to paste proprietary code or stack traces into Shot2Text?
- Yes. Shot2Text runs recognition completely inside your browser tab using local language data — your code screenshot or stack trace is never uploaded to any server.