Every developer has a drawer of "useful code" scattered across five places:
- Browser bookmarks — that Stack Overflow answer with the exact flag
- Chat history — the one-liner a coworker sent in Slack three months ago
- Old terminals — scroll back 200 lines, it's gone
- Project READMEs — findable only if you remember which project
- Your brain — a terrible database
By the time you find the snippet again, you've re-typed half of it, guessed the other half, and lost 15 minutes. The snippet is never long. The searching is what costs.
Why existing snippet managers miss
I tried the obvious options:
- GUI tools (Raycast, Alfred, ...) — great, but they want your code in a GUI layer, usually an account, often a subscription. I live in the terminal 90% of the day and I don't want to leave it.
- Web snippet sites — pasting internal code into a public service is a non-starter. Some of my "snippets" contain internal hostnames and tokens.
- IDE snippets — scoped per project, per editor, not searchable across projects, and useless from the terminal where most emergency commands actually live.
What I wanted was boring: one local file, zero accounts, everything in the terminal.
So I built snippetx.
Install
npm i -g @wuchunjie/snippetx
~5 KB, zero dependencies, MIT licensed. Your snippets live in a single JSON file at ~/.snippetx/snippets.json. No daemon, no account, no telemetry, no cloud. Close the laptop — your snippets survive.
The six commands
# Save: pipe anything in
echo 'docker ps -a --format "table {{.Names}} {{.Status}}"' | snippetx add docker-ps bash
# List (optionally filter by name or language)
snippetx list
snippetx list js
# Search across all snippet content
snippetx search retry
# View
snippetx show a1b2c3d4
# Copy to clipboard (macOS) — pipe to clip on Windows
snippetx copy a1b2c3d4 | pbcopy
# Delete
snippetx rm a1b2c3d4
That's the entire API. There is nothing to configure.
A real workflow: the once-a-month emergency command
The snippet I use least often but need most desperately is a Postgres recovery command. Once a quarter something breaks at 11pm and I need it exactly right — no guessing, no Stack Overflow round-trip.
With snippetx:
snippetx search postgres
# 🔹 7f3a9c21 pg-recovery
# ...pg_ctl -D /var/lib/postgresql/14/main -o "-c config_file=..."...
snippetx copy 7f3a9c21 | pbcopy
Two commands. The exact command, straight into my clipboard, under ten seconds.
Your snippets are just a text file
This is the part I actually care about. ~/.snippetx/snippets.json is plain JSON:
- Back it up — copy one file.
-
Search with your own tools —
grep -r "docker" ~/.snippetx/works as well as any built-in search. - Version it — drop it in your dotfiles repo and your snippet library follows you to every new machine.
One warning before you push: scan first. If any snippet contains a token, a key, or an internal hostname, it doesn't belong in a public repo. I run dotguard over my dotfiles before every push — here's the full GitHub Actions setup.
The bigger picture
snippetx is one of a few small, local-first tools I ship:
- snippetx — your code snippets, in your terminal
- dotguard — secret scanning for dotfiles and repos
- gitpulse — repo health and maintainer pulse
- scaffoldx-cli — interactive project scaffolding
All local-first, all zero-dependency, all MIT. If one of these saves you a few minutes, a ko-fi genuinely funds the next tool.
GitHub: github.com/wuchunjie00
What's the one snippet you re-type so often it deserves its own tool? Tell me in the comments.
Top comments (0)