Once: a CLI that caches command output for a while
https://github.com/alex0ptr/once
- discussion_url
- https://news.ycombinator.com/item?id=50018239
Article
once is a small Go command-line tool that runs a command in the current directory, prints its stdout, and keeps that output in memory inside a per-user background daemon. Repeated calls with the same command, directory and tenant key are answered from memory until the entry expires. The daemon shuts itself down once its last entry has expired.
The stated motivation is reducing repeated secret prompts: the README's example reads a token from 1Password with `op read`, so the first call asks for a fingerprint and further calls within the TTL do not. Usage is `once --ttl DURATION [--until TIME] [--tenant KEY] [--refresh] [--no-dir] -- COMMAND [ARGS...]`, installed via `go install github.com/alex0ptr/once@latest` (Go 1.27+, standard library only, macOS and Linux). Everything after `--` is executed directly without a shell, so pipes and globs must be wrapped with `sh -c`.
Only stdout is cached; stdin and stderr pass through, so interactive prompts still work. Results of commands exiting non-zero are never cached, and the exit code is forwarded. By default the working directory is part of the cache key, because commands such as `git rev-parse HEAD` vary by directory; `--no-dir` omits the directory, and entries created with and without it are separate. `--until` sets an absolute deadline, and the entry expires at whichever comes first, `--ttl` or `--until`; the tool never computes relative dates, so the shell must supply them. If `--until` is already past, the command runs but is not cached. The cache key is HMAC-SHA256 over tenant, working directory and command plus args. The author notes the tenant key is a namespace rather than a security boundary and is not meant to be secret. `once status` shows the daemon and entry count; `once clear` drops all values and stops it.
HN discussion
Based on 10 selected comments and replies.
Several commenters focused on the 1Password example. ShakataGaNai said the secret-reading use case landed hardest, describing frustration with repeatedly approving credential access during agent-driven test runs, and admitted having asked agents to write credentials to a .env file to avoid approving every time; the author (alex0ptr) replied that they had feared nobody shared that workflow. Others compared prior art: aktau pointed to their own shell-script tool memo, noting it needs no build and stores compressed output under /tmp, whereas once keeps the cache in a running daemon, calling the trade-offs a security consideration. thomascountz said they use that script daily and learned from its design. __MatrixMan__ wished applications exposed enough metadata for the OS to decide when reruns are needed, citing NixOS for builds but not arbitrary processes, and jchw observed that some use cases can be forced into the Nix build system with varying success. deadbunny quipped about finally getting cache invalidation in the terminal.
Selected comments: ShakataGaNai · alex0ptr · aktau · thomascountz · __MatrixMan__ · deadbunny