Quickstart

From an env file full of secrets to a command that gets them at start-up, in four steps.

1. Install

Download the latest disk image and drag Latchkey to Applications, or install it with Homebrew: brew tap zachshallbetter/latchkey, brew trust zachshallbetter/latchkey, then brew install --cask latchkey. The cask adds both commands for you. With the disk image, open it and choose Latchkey › Install Command Line Tool…, which links ~/.local/bin/latchkey, and lk for short, to the copy inside the app so it updates with the app. Make sure ~/.local/bin is on your PATH; in zsh, echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc does it. With the Mac App Store version, see the command-line tool.

Terminal
latchkey status

You should see storage: iCloud Keychain storage (sync status not verified).

2. Import an env file

Look first. A dry run prints names and where each would go, never values:

Terminal
cd ~/Projects/shop
latchkey import .env.local --dry-run

The dry run also classes each line: secret, setting (such as PORT, left in the file), public value (such as NEXT_PUBLIC_*, saved as a plain value) or existing reference. It counts each class and lists each setting it would leave. Change a line with --class KEY=secret|setting|public.

Then import, and replace each value in the file with its reference. The project is named after the repository; the environment comes from the file name (.env.local is development).

Terminal
latchkey import .env.local --rewrite
.env.local
DATABASE_URL=latchkey://shop/development/DATABASE_URL
STRIPE_KEY=latchkey://shop/development/STRIPE_KEY

Imports support quoted multiline values and refuse malformed syntax before saving anything. Rewriting replaces the complete assignment and stops if the file changed while approval was pending.

The dry run, then the import: one approval, and each value in the file becomes its reference. Here --skip PORT leaves a plain setting as it is. Example data; the output is what Latchkey prints.

Every project at once: latchkey import --scan ~/Projects --dry-run, then again without --dry-run. Or latchkey import --batch files.txt, one path per line. Either way, one approval. See the import options.

3. Run a command

Terminal
latchkey run --env-file .env.local -- npm run dev
latchkey run --env shop/development -- npm test      # no env file needed
lk run reads the references, asks Latchkey for the values, and starts the command with them in its environment; anything it prints of them is concealed. Example data; the output is what Latchkey prints.

Reads ask unless a grant or the No Approval setting permits them. Values that reach the command’s output are replaced with <concealed by latchkey>. The command’s exit status becomes latchkey run’s.

4. Let an agent work

Before you step away, allow the folder for a while. Commands run from it, its subfolders and the repository’s worktrees read these items without asking until the grant ends.

Terminal
latchkey grant 'shop/development/*' --folder ~/Projects/shop --for 2h
latchkey grants
latchkey revoke all

Then tell the agent how to run things; see instructions for agents.