Store MFA secrets and generate TOTP/HOTP codes from the command line.
Secrets are kept either in a native database encrypted with a master password, or in pass(1). The project is a Cargo workspace:
crates/otp-core: library (code generation,otpauth://URIs, storage backends, QR decoding), meant to be reused by a future UI.crates/otp-cli: theotpbinary.
cargo install --path crates/otp-cli # installs ~/.cargo/bin/otp
cargo install --path crates/otp-cli --root ~/.local # or ~/.local/bin/otpThe interactive otp tui command is an optional feature:
cargo install --path crates/otp-cli --features tuiRun the same command again to update. To remove the binary, run
cargo uninstall otp-cli (the package is otp-cli, the binary is otp).
Optional runtime tools, looked up in $PATH: pass (for --pass), grimshot (for
insert --qrcode) and wl-copy (for --clip). The last two can be changed in the
configuration.
Completion is generated by otp itself, so it covers subcommands, flags and entry
names. Folders along entry paths are offered too, so Web/amazon.fr/[email protected] can be
completed one level at a time (Web/, Web/amazon.fr/). otp insert offers only
folders, since it creates a new name. Add the line for your shell:
# fish
echo 'COMPLETE=fish otp | source' > ~/.config/fish/completions/otp.fish
# bash
echo 'source <(COMPLETE=bash otp)' >> ~/.bashrc
# zsh
echo 'source <(COMPLETE=zsh otp)' >> ~/.zshrcCompletion never prompts. pass entry names come from the filesystem. Native entry names
are only offered when the master password is available without a prompt, through
password_command or OTP_PASSWORD; each completion then decrypts the database
(about 80ms, compared with about 2ms for pass names alone). With backend = "pass"
the database is never opened.
The completion interface is unstable in clap_complete (the dependency is pinned). The
lines above regenerate the shell code each time a shell starts, so it stays in sync
with the installed binary.
# Without an exact entry name, otp lists entries (like pass)
otp # list all entries
otp google.com # list entries starting with google.com
# Print a code (TOTP or HOTP)
otp google.com/[email protected]
otp -c google.com/[email protected] # copy instead; cleared after 45 s
# Export instead of generating a code (combines with -c; HOTP counters are untouched)
otp --secret google.com/[email protected] # base32 secret
otp --otpauth google.com/[email protected] # full otpauth:// URI
otp --qrcode google.com/[email protected] # QR code, drawn in the terminal
otp --qrcode=google.png google.com/[email protected] # QR code as a PNG
# Insert: paste an otpauth:// URI (hidden prompt, or read from stdin)
otp insert google.com/[email protected]
# Insert from a QR code: select a screen area with grimshot...
otp insert google.com/[email protected] --qrcode
# ...or decode an image file
otp insert google.com/[email protected] --qrcode=qr.png
# Insert a raw base32 secret (with optional --digits/--period/--algorithm/--counter)
otp insert google.com/[email protected] --secret
# Store in pass as google.com/[email protected]
otp insert --pass google.com/[email protected] --qrcode
otp list [PREFIX] [--long] # entries from both stores (or --pass / --native)
otp show NAME [--uri] # parameters, or the otpauth:// URI (includes the secret)
otp rm NAME [--force]
otp mv FROM TO [--force] # rename within its store; TO ending in / keeps the name
# Copy entries to the other store (all, or those starting with PREFIX);
# --remove moves them instead, --dry-run only shows what would happen
otp migrate --to native [PREFIX] [--remove] [--dry-run]
otp migrate --to pass [PREFIX] [--remove] [--dry-run]
otp passwd # change the native database's master passwordLookups check pass first, since that doesn't need the master password, then the native
database. --pass / --native restrict any command to one store; backend = "pass"
or backend = "database" in the configuration makes that the default. With pass chosen
that way, otp never opens the database, so it does not ask for its master password.
otp migrate refuses, before changing anything, when an entry already exists in the
destination or a pass entry has notes after its URI, which the database cannot keep;
--overwrite replaces those entries and drops the notes. Entries keep their parameters,
HOTP counter and dates. Copying (without --remove) leaves HOTP entries in both stores
with the same counter: use only one copy, or codes will repeat.
New names are kept unique across stores: insert and mv refuse a name the other
store already has. The exception is that same pass-only case, where the database is not
checked: an entry may then exist in both, and lookups find the pass one first.
otp tui (built with --features tui) lists all entries, or only those in one store
with --pass / --native:
- Type to filter the list: case-insensitive substring match; Backspace edits, Ctrl-U clears.
- ↑/↓ select an entry, PgUp/PgDn move a page at a time, and Home/End go to the first and last entry. Its code, time left, issuer and account show in the right-hand column. pass entries are decrypted the first time they are selected.
- Enter copies the selected code with
clipboard_commandand quits. HOTP codes are only generated here, since generating one advances the counter. Esc or Ctrl-C quits. - Tab or Ctrl-I opens the inspect window. It shows the current code, the base32 secret,
every parameter and the
otpauth://URI. There,scopies the secret anducopies the URI (then otp quits),rshows the QR code (Esc goes back), and Esc closes it. - Ctrl-R shows the selected entry's QR code directly; Esc goes back to the list.
- Ctrl-N creates an entry. The name starts as the current filter; then choose
uto paste an otpauth URI,sto type a base32 secret (TOTP with the defaults ofotp insert --secret), orqto capture a QR code withcapture_command. It goes to the storeotp insertwould use (--pass/--native, thenbackend, then native). Esc cancels at any step. - Codes are shown as one unbroken string, so a mouse selection copies them as they are;
set
group_digits = trueunder[tui]in the configuration to show123 456. - Ctrl-H hides or shows the code, and the secret in the inspect window (the countdown
stays, and copying still gives the real values). It works in the inspect window too.
To start hidden, run
otp tui --hiddenor sethidden = trueunder[tui]. After 30 seconds without a key press the TUI switches to hidden mode by itself, and closes the QR code window; sethide_afterunder[tui]to change the delay (0 disables it). After 5 minutes without a key press it quits, so the decrypted entries do not stay in memory; setquit_afterto change that delay (0 disables it). - Ctrl-?, Ctrl-/ or F1 shows the help with all shortcuts; Esc closes it.
Most terminals send Ctrl-I as Tab and Ctrl-? as Backspace. otp turns on the kitty keyboard protocol where it's available (kitty, foot, WezTerm, Ghostty, recent Alacritty) so they can be told apart. Elsewhere, use Tab and Ctrl-/ or F1.
The master password, if needed, is asked before the TUI starts, and never while it runs.
When the database was not opened at startup (e.g. with --pass), creating an entry
checks it for duplicates only if password_command or OTP_PASSWORD can open it. The
same applies to creating the database from the TUI. The same goes for the gpg key of
pass entries: if it is locked, otp decrypts one entry before the TUI starts, so your
usual pinentry asks for the passphrase, and quits if that fails or is cancelled. gpg
never asks while the TUI runs (a terminal pinentry would draw over it); if a pass
command fails then, for instance for an entry encrypted to another, still locked key,
the TUI quits with the error.
Native database: ~/.local/share/otp/otp.db by default. A JSON envelope whose
payload is encrypted with XChaCha20-Poly1305. The key is derived from the master password
with Argon2id (256 MiB, 3 passes, 4 lanes in parallel). Databases created by earlier
versions keep their 64 MiB, 1 lane settings, and otp warns about them: otp passwd
upgrades them (typing the same password again is fine). Settings over 1 GiB, 10 passes
or 16 lanes are refused before any work, so a tampered file cannot make otp hang or
exhaust memory. The header (format, KDF parameters, salt) is authenticated. A new master password needs at least 12 characters and zxcvbn's top
strength score, 4: more than 10^10 estimated guesses (4 random words or 12 random
characters pass); password_score_check = false keeps only the length. Opening a
database with a weaker typed password prints a warning suggesting otp passwd.
Entry names are encrypted too. Writes are atomic, and the file is mode
0600. Every change takes an exclusive lock on otp.db.lock and applies to the file as it
is at that moment, so several otp processes (a TUI left open, an insert waiting at its
prompt) never undo each other's changes.
pass: entry NAME is stored as NAME-otp. The first line is the otpauth:// URI,
so pass-otp and other tools can still read it. The lines after it hold JSON metadata:
otpauth://totp/Google:[email protected]?secret=...&issuer=Google&algorithm=SHA1&digits=6&period=30
{
"created_at": "2026-09-25T18:54:47Z",
"updated_at": "2026-09-25T18:54:47Z"
}
Existing pass-otp entries (*-otp, URI on the first line) work as they are. If one
has free-form notes after the URI, those lines are kept when otp rewrites the entry
(for example, to advance an HOTP counter).
~/.config/otp/config.toml, or the file given with --config FILE or
$OTP_CONFIG_FILE (--config wins). A file named this way must exist. Every key is
optional. A commented
sample is in contrib/config.toml.sample.
backend = "pass" # or "database"; default for --pass/--native (unset: both)
database = "~/.local/share/otp/otp.db"
password_score_check = true # refuse guessable new master passwords (zxcvbn)
# Get the master password from a command instead of prompting:
password_command = ["pass", "show", "otp/master"]
capture_command = ["grimshot", "save", "area", "{file}"] # {file}: PNG to write
clipboard_command = ["wl-copy", "--sensitive"]
clipboard_timeout = 45 # seconds before a copied value is cleared; 0 keeps it
qrcode_viewer_command = ["chafa", "{file}"] # for otp --qrcode; unset: drawn by otp
password_store_dir = "~/.password-store"
[tui]
group_digits = false # true: show codes as "123 456" instead of "123456"
hidden = false # true: start with codes hidden (like Ctrl-H, or --hidden)
hide_after = 30 # seconds without a key press before hiding them; 0 never
quit_after = 300 # seconds without a key press before quitting; 0 neverEnvironment variables:
OTP_DB: overrides the database path.PASSWORD_STORE_DIR: selects the pass store, as it does for pass.OTP_PASSWORD: supplies the master password. It is meant for scripts and tests; it is visible to other processes of the same user.
cargo test --workspace --all-features # pass test skipped without pass/gpg
cargo clippy --workspace --all-targets --all-featuresGitHub Actions runs cargo fmt --check, cargo clippy -D warnings and the tests on
pushes to main and on pull requests (.github/workflows/ci.yml).
.github/workflows/audit.yml runs cargo audit daily, and whenever Cargo.toml or
Cargo.lock change, to catch security advisories published after a dependency was
locked.
Set the new version in the root Cargo.toml, commit, then push a matching tag:
git tag v0.2.0 && git push origin v0.2.0.github/workflows/release.yml runs CI and checks that the tag matches the crate
version. It then builds static binaries for x86_64-unknown-linux-musl and
aarch64-unknown-linux-musl and publishes them, with SHA-256 checksums, as a GitHub
release. Tags containing a - (e.g. v0.2.0-rc.1) become pre-releases.