Instant, offline code extractor for Linux (Wayland & GNOME).
Turn video tutorials, PDFs, conference talks, and IDE screenshots into clean, formatted code on your clipboard in milliseconds.
Hotkey TriggerSuper + Shift + L
|
Selection Native Desktop Portal Crosshair |
Processing Denoise + Invert + PSM 6 OCR |
Formatting Blazing-fast Ruff (Rust) |
Result Clean Code in Clipboard |
Standard OCR tools stumble on code: dark themes fail contrast checks, indentation gets mangled, language keywords are misread, and Wayland compositors (like GNOME Mutter) block legacy capture utilities.
codesnap is purpose-built for developers:
| Feature | Standard OCR Utilities | codesnap v2.4 |
|---|---|---|
| Wayland Support | β Fails on Mutter / GNOME 40+ | β
Native XDG Desktop Portal + slurp fallback |
| Dark Theme IDEs | β Poor contrast, missing symbols | β Automatic polarity detection & contrast inversion |
| OCR Code Cleaning | β Leaves stray |, broken def |
β
AST-safe token correction (preserves 100, utf8) |
| OCR Architecture | β Rigid single legacy engine | β Dual-Engine: RapidOCR (ONNX) + Tesseract fallback |
| Indentation & Formatting | β Random tabs, mangled blocks | β Multi-language auto-formatting (Ruff, rustfmt, gofmt, biome, prettier) |
| Resource Footprint | numpy), 100MB+ |
β Zero NumPy bloat β C-accelerated Pillow, <400ms runtime |
| Language Intelligence | β Plain unformatted text | β 11+ languages auto-detected & highlighted |
| Privacy & Security | β 100% offline and local β zero network requests |
Run this single command in your terminal. It installs system tools, configures the environment with uv, and registers Super + Shift + L:
curl -sSL https://raw.githubusercontent.com/aswin402/codesnap/main/setup.sh | bashInstall globally as a CLI tool:
# Using uv (fastest & recommended)
uv tool install codesnap-cli
# Run instantly without installing
uvx codesnap-cli
# Or using standard pip
pip install codesnap-cligit clone https://github.com/aswin402/codesnap.git
cd codesnap
chmod +x setup.sh
./setup.shVerify your installation:
codesnap --versionIf you already have codesnap installed, upgrade in-place without touching system packages:
git pull
./localupdate.sh- Press Super + Shift + L anywhere on your system.
- Select any code block on your screen (press Esc anytime to cancel).
codesnapextracts, cleans, normalizes, and auto-formats the code.- A desktop notification confirms:
Python β’ 14 lines copied. - Paste directly into your editor with Ctrl + V.
# Extract code directly from an existing image file
codesnap /path/to/screenshot.png
# Save extracted code straight to a file
codesnap /path/to/screenshot.png -o snippet.py
# Pipe extracted code directly to stdout
codesnap /path/to/screenshot.png -c | bat -l python
# Override language auto-detection
codesnap /path/to/screenshot.png -l rust
# High-quality preprocessing for low-res or blurry screenshots
codesnap --high-quality
# Select OCR engine (auto, rapidocr, or tesseract)
codesnap --engine rapidocr
# Review and edit OCR output in $EDITOR before copying to clipboard
codesnap --interactive
# Inspect diagnostics, installed OCR engines, and system backend health
codesnap --versionflowchart TD
A["β¨οΈ Super + Shift + L"] --> B{"Display Server & Desktop"}
B -->|"GNOME Wayland"| C["XDG Desktop Portal (jeepney D-Bus)"]
B -->|"wlroots (Sway/Hyprland)"| D["slurp + grim"]
B -->|"X11 Session"| E["gnome-screenshot -a"]
C --> F["Raw Screenshot PNG"]
D --> F
E --> F
F --> G["Image Preprocessor"]
G --> H["Dark Mode Detection & Inversion"]
H --> I["Contrast Enhancement & Denoising"]
I --> J["Tesseract OCR (--psm 6 uniform code)"]
J --> K["Smart Character Cleaner"]
K --> L["Multi-Language Detector (11+ Languages)"]
L --> M{"Formatter Available?"}
M -->|"Python"| N1["Ruff (Rust engine)"]
M -->|"Rust"| N2["rustfmt"]
M -->|"Go"| N3["gofmt"]
M -->|"JS / TS / JSON"| N4["biome / prettier"]
M -->|"Bash"| N5["shfmt"]
M -->|"C / C++"| N6["clang-format"]
M -->|"HTML / CSS"| N7["prettier / biome"]
M -->|"Fallback"| O["Normalized Clean Code"]
N1 --> P["wl-copy / xclip Clipboard"]
N2 --> P
N3 --> P
N4 --> P
N5 --> P
N6 --> P
N7 --> P
O --> P
P --> Q["π Desktop Notification"]
| Language | Primary Formatter | Fallback Formatter | Offline / Auto-fallback |
|---|---|---|---|
| Python | ruff (bundled in venv) |
β | β Guaranteed |
| Rust | rustfmt |
β | β Graceful passthrough |
| Go | gofmt |
β | β Graceful passthrough |
| JavaScript / TypeScript / JSON | biome |
prettier |
β Graceful passthrough |
| Bash / Shell | shfmt |
β | β Graceful passthrough |
| C / C++ | clang-format |
β | β Graceful passthrough |
| HTML / CSS | prettier |
biome |
β Graceful passthrough |
| Environment | Display Protocol | Capture Backend | Status |
|---|---|---|---|
| Ubuntu 24.04 / 26.04 (GNOME 46+) | Wayland | XDG Desktop Portal (jeepney) |
π’ Native |
| Sway / Hyprland | Wayland | slurp + grim |
π’ Supported |
| Ubuntu / Debian (GNOME / XFCE) | X11 | gnome-screenshot / xclip |
π’ Supported |
| KDE Plasma | Wayland / X11 | Portal / spectacle |
π‘ Compatible |
codesnap/
βββ pyproject.toml # Modern build metadata & dependency manifest (hatchling)
βββ codesnap.py # Compatibility proxy CLI entrypoint
βββ setup.sh # First-time installation & hotkey registration script
βββ localupdate.sh # Fast in-place upgrade script for existing installs
βββ src/codesnap/
β βββ __init__.py # Package metadata & version
β βββ cli.py # CLI entrypoint & pipeline orchestration
β βββ capture.py # Wayland XDG Desktop Portal & slurp capture engine
β βββ image.py # Dark theme polarity detection & image enhancement
β βββ ocr.py # Tesseract OCR engine with uniform code tuning
β βββ cleaner.py # Token-safe character normalization
β βββ languages.py # Heuristic language pattern detection
β βββ formatters.py # Rust-based Ruff code formatter integration
β βββ clipboard.py # wl-copy / xclip & desktop notification handlers
β βββ exceptions.py # Typed domain exceptions
βββ tests/ # 37 automated unit tests
βββ test_capture.py
βββ test_cleaner.py
βββ test_cli.py
βββ test_formatters.py
βββ test_image.py
βββ test_languages.py
βββ test_ocr.py
All features and bug fixes are accompanied by automated tests:
# Run unit test suite (37 tests)
uv run pytest
# Check code formatting & style with Ruff
uv run ruff check .
uv run ruff format --check .
# Auto-format codebase
uv run ruff format .Detailed release notes and migration guides are documented in CHANGELOG.md.
rm -rf ~/.local/share/codesnap
rm ~/.local/bin/codesnapThen remove the custom shortcut in Settings β Keyboard β Keyboard Shortcuts β Custom Shortcuts.