Per-command secret injection for AI coding agents — values never enter model context
pip install keygrant==0.1.5 Copy PIP instructions
Why: anything placed in an LLM's context can be exfiltrated (prompt injection, logs, generated code). The fix is architectural: keys never enter context, only the execution environment.
uv tool install keygrant # or: pipx install keygrant Requires Python ≥ 3.10. macOS ships Python 3.9, so a bare pip install there fails; uv fetches a suitable Python automatically.
Then, in each project where agents should use secrets:
keygrant init init adds a keygrant entry to the project's .mcp.json (merging with any existing servers) and appends usage guidance for the model to CLAUDE.md, both idempotently. Restart Claude Code in that folder to load the server.
Values live in the login Keychain; approval is a native dialog.
What this does NOT protect against (known residual risks):
Every use of a secret — via the CLI or the MCP server — requires the user's approval through a native, topmost dialog that shows the full command (deny by default on a 60s timeout). Through the MCP server, approving lets that exact command reuse the secret for 15 minutes in that session — handy for retries — while any other command prompts again. Grants are held in the server's memory only. The CLI prompts on every keygrant exec, so an agent cannot bypass MCP approval by shelling out to it. keygrant revoke NAME|--all voids earlier grants in every running session. The dialog will be replaced by a resident tray app with toast notifications; the grant semantics stay the same.
The vault file also records usage metadata (use count, last used) as the seed of an audit trail.
Optional end-to-end encrypted sync between your devices (uv tool install 'keygrant[cloud]'). Values are encrypted on the device; the server only ever stores ciphertext. Nothing is uploaded until you push.
uv tool install 'keygrant[cloud]' keygrant cloud init # choose a password; prints your Emergency Kit keygrant push STRIPE_KEY # upload an existing local secret Write the Emergency Kit (Account ID + Secret Key) down and keep it offline. Your data can only be decrypted with your password and the Secret Key; nobody, including keygrant, can recover either for you.
More devices — the old device must be online (it can be over SSH or remote desktop; pairing needs both devices at once, not in one place):
keygrant devices add # old device: shows a pairing code keygrant pair # new device: enter the code Both screens then show a fingerprint. Check they match before typing yes on the old device — that check is what stops a malicious server from slipping in its own device. The new device asks for your password once.
echo "sk-..." | keygrant set STRIPE_KEY && keygrant push STRIPE_KEY # add / change keygrant push --delete STRIPE_KEY # remove everywhere keygrant sync # pull now list and exec also pull changes on their own (at most once a minute, silently skipped when offline). If two devices change the same secret, the later push is refused until you sync; a local edit you haven't pushed is never overwritten.
Lost every device? On a new machine, keygrant recover joins with the Emergency Kit and your password alone (accounts created before 0.1.4: run keygrant cloud enable-recovery once on an existing device).
Approve from your phone — run keygrant devices add and enter the code at https://keygrant.app/app on your phone; the same fingerprint check makes that browser a trusted approver. When nobody answers the desktop dialog, the request goes to that page instead; an explicit Deny on the desktop is final. The browser can approve and see names, never values.
Leave — keygrant cloud delete destroys the account and all ciphertext; secrets stay on each machine as local-only entries.
Design and threat model: docs/design/cloud-sync-client.md.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.




