keystash 🔑
Local-first encrypted vault for API keys, tokens and passwords — one file, fuzzy search, env injection, expiry tracking, Touch ID unlock, and a leak hunter that cleans up the mess you already have.
Your LLM API keys, cloud tokens and passwords are scattered across .env files, shell
histories and notes apps. keystash puts them in one encrypted file that you own:
no server, no account, no subscription. Sync that file with iCloud / Dropbox / SeaDrive /
Syncthing — it's ciphertext, so syncing it is safe.
pip install keystash
keystash init # once; then `keystash unlock` for Touch ID–gated daily use
Why keystash
| keystash | pass / gopass | Bitwarden / 1Password | Infisical / Vault | |
|---|---|---|---|---|
| Setup | pip install + one password |
GPG key ceremony | Account + app | Self-host a server |
| Storage | one encrypted file you own | many GPG files | vendor cloud | server |
| Offline | ✅ always | ✅ | partial | ❌ |
| Touch ID unlock | ✅ built-in | ❌ | app-only | ❌ |
| Finds scattered plaintext keys on your machine | ✅ doctor |
❌ | ❌ | ❌ |
Dev workflow (env injection, run) |
✅ built-in | ❌ | ❌ | ✅ (heavy) |
| Token expiry tracking | ✅ built-in | ❌ | ❌ | enterprise |
Touch ID unlock
Typing the master password for every command is exactly the kind of friction that pushes people back to plaintext notes. Unlock once and macOS gates it instead:
keystash unlock # verify master password, store it behind Touch ID
keystash get openai -c # → Touch ID prompt → copied
keystash lock # remove the stored credential again
Every read shows the system authentication prompt (Touch ID → Apple Watch → device
passcode fallback). --no-keychain or KEYSTASH_PASSWORD bypass it for scripts and CI.
On machines without biometry the keychain still removes the typed password.
keystash doctor — clean up the mess you already have
Browser password managers only guard the keys you remember to move. doctor
actively hunts the ones littering your machine:
keystash doctor # scan cwd + ~/.zshrc, ~/.zsh_history, ~/.env …
keystash doctor ~/projects # scan any path
keystash doctor --import-all # store every new finding in the vault
keystash doctor --import-all --shred --yes # …and redact the plaintext in place
Knows OpenAI / Anthropic / GitHub / AWS / Google / Slack / Stripe / Hugging Face /
SendGrid token shapes, PEM private keys, JWTs, plus an entropy-checked
API_KEY=... sweep. Secrets already in the vault are reported as stored; --shred
replaces each value with a [redacted→keystash:<name>] placeholder so file structure
and comments survive.
AI agents, zero plaintext: keystash mcp
Run keystash as an MCP server so AI agents (Claude Desktop, ZCode, Cursor, …) can orchestrate secrets without ever seeing their values:
{
"mcpServers": {
"keystash": {
"command": "keystash",
"args": ["mcp"],
"env": { "KEYSTASH_VAULT": "/path/to/vault.json" }
}
}
}
What the agent gets — and what it can never get:
| Tool | Agent sees |
|---|---|
list_entries, status |
names, tags, expiry, env-var names — never values |
run_command |
command output with every injected secret scrubbed; obvious dumpers (printenv, env, /proc/*/environ) are refused |
copy_secret |
"copied to clipboard" — the value goes to your clipboard, not the conversation |
generate_and_store |
confirmation only; the generated secret never exists in the conversation |
add_secret |
⚠️ the one intentional exception, for keys the human already pasted into the chat |
update_entry, delete_entry |
metadata edits; deletion requires confirm: true |
Unlock first (keystash unlock) so the server picks the password up from the
keychain; a locked server reports a helpful hint instead of prompting on stdio.
Remaining risk, stated honestly: an agent deliberately writing code that
exfiltrates (encode, split, transform) cannot be stopped — that is visible in
its transcript and auditable by you. The server removes the accidental
exposure path entirely.
Quick start
# 1. Create your vault (encrypted with AES-128-CBC + HMAC, PBKDF2-HMAC-SHA256 600k iters)
keystash init
# 2. Store a secret
keystash add openai --secret sk-... --tags llm,prod --expires 2027-01-31 --env-var OPENAI_API_KEY
# 3. Retrieve it
keystash get openai # masked preview
keystash get openai -c # → clipboard, auto-clears after 30 s
keystash get openai -q # raw secret for scripts: export K=$(keystash get openai -q)
# 4. Find things (fuzzy)
keystash ls # everything, expiry warnings included
keystash ls oprod # fuzzy: matches openai-prod
keystash ls --tag llm --json
# 5. Inject secrets into any command — nothing touches your shell or disk
keystash run -n openai -n anthropic -- python train.py
keystash run --tag llm -- python train.py
eval "$(keystash env --tag llm)" # or export them explicitly
# 6. Migrate off plaintext .env files
keystash import .env # then delete the .env file
Commands
| Command | Purpose |
|---|---|
init |
Create the vault |
add NAME |
Store a secret (-s value, -g LEN to generate, -t tags, --expires YYYY-MM-DD, --env-var) |
get NAME |
Show (-r reveal), copy (-c), raw output (-q) |
ls [QUERY] |
List / fuzzy search (--tag, --json) |
edit NAME |
Update any field in place |
rm NAME |
Delete an entry |
gen [LEN] |
Generate a strong secret (--save NAME to store it) |
env NAME… / --tag |
Print export lines for shell eval |
run -n NAME… -- CMD |
Run a command with secrets injected as env vars (--tag selects by tag) |
import FILE |
Bulk-import .env or JSON |
export |
Export metadata (or secrets with --with-secrets) as JSON / dotenv |
unlock / lock |
Store / remove the master password behind Touch ID (macOS) |
doctor |
Scan for scattered plaintext secrets; --import-all, --shred |
mcp |
MCP server for AI agents (zero-plaintext tool surface) |
status |
Vault health + expired / expiring-soon report |
Multi-machine sync
The vault is a single encrypted file. Point KEYSTASH_VAULT at any synced folder:
export KEYSTASH_VAULT="~/CloudStorage/SeaDrive/vault.json" # or iCloud, Dropbox, …
Each write re-encrypts with a fresh random salt, so last-writer-wins applies — prefer one writer per vault at a time, like any sync file.
Security model
- Cipher: Fernet (AES-128-CBC + HMAC-SHA256, encrypt-then-MAC) via
cryptography. - Key derivation: PBKDF2-HMAC-SHA256, 600 000 iterations, per-save 128-bit random salt.
- File mode:
0600; nothing is ever written to disk in plaintext. - Clipboard: copied secrets are auto-cleared after 30 s (best effort, detached process).
- No network. No telemetry. The CLI is fully offline.
- Secrets live in process memory only while a command runs; Python cannot guarantee zeroization after exit — the same is true of any CLI in a GC'd language.
Environment variables
| Variable | Purpose |
|---|---|
KEYSTASH_VAULT |
Vault file path (also --vault) |
KEYSTASH_PASSWORD |
Master password (for scripts/CI; prefer the interactive prompt) |
Development
git clone https://github.com/thu-lawyer/keystash && cd keystash
uv pip install -e ".[dev]"
pytest
License
Metadata
Release files for keystash 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keystash-0.3.0.tar.gz | 34.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keystash-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 66.4 kB
Release files / keystash-0.3.0.tar.gz
| Download URL | keystash-0.3.0.tar.gz |
|---|---|
| Size | 34.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
069b45a3fc7f67dfa089dff38ec9b20945725b91b431b84f6c0058bb36629339
|
|
BLAKE2b-256 checksum How to use checksums |
9ed1cc4a14c99fd3226c85c35f24e7a7a2380f0c734a8a3ff523327eb06fdcca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logRelease files / keystash-0.3.0-py3-none-any.whl
| Download URL | keystash-0.3.0-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
775ce84c1c1b9288cad06401b8ed263e0a53492b6abc8a9c0bd6bb6e69170566
|
|
BLAKE2b-256 checksum How to use checksums |
75ed210fca96cd9af4266eb1835fbf526ac58404fd792f8c20fa2ff409a9cd99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency log