Skip to main content
coreydaley.dev
Docs menu

Using secrets in scripts and coding agents on Mac

Coming in Secret Store 1.3. It's built and arrives with the next update; the version on the App Store doesn't have it yet.

API keys often end up in plain-text .env files that any program on your Mac can read. Scripts & Agents lets the programs you choose ask Secret Store for them instead, and you approve each request with Touch ID or your password. It’s Mac only.

Ways to use it

The first two need the secretstore command and a token.

secretstore run is the safest of these: the keys go straight to the one command you run, and nowhere else.

Turning it on

  1. In Secret Store ▸ Settings… (⌘,), open Scripts & Agents and turn on Allow scripts and agents on this Mac to use secrets. Secret Store then listens on 127.0.0.1 (your Mac only, never your network) while it’s running.

  2. Click Add Client… and name it after the program that will use it, for example “Claude Code” or “deploy script”. Secret Store shows the client’s token once, with a command that stores it in your keychain: run it now, as described below. The sheet also links to this page.

  3. Click Choose Access… and choose what the client can use:

    • Search for a tag or secret, or open a tag in the list to see its sub-tags and the secrets tagged with it, then click +.
    • A tag includes its nested tags, like env/app under env, and any secret added under it later. Giving a project’s secrets one tag, like env/myproject, makes this easy; importing its .env file tags them for you.
    • What you’ve chosen shows at the top, each with × to remove it. Includes N secrets lists everything that adds up to.
    • Click Save. Nothing changes until you do.

    To change it later, click Access… next to the client, or right-click a tag in the sidebar and choose Allow for Client.

A client gets only what’s on its list, and each request still asks you first. A secret’s page shows who can use it, under Can be used by.

Approving a request

When a client asks, Secret Store shows a panel naming the client and the secrets. Choose Allow Once or Allow for 10 Minutes, then confirm with Touch ID or your password. Deny (or Escape) refuses it. A secret added to a tag since you last allowed it is marked New.

  • Allow for 10 Minutes lets any program holding that client’s token get the same secrets again without asking, until the time is up. Change how long in Settings ▸ Scripts & Agents ▸ Allow for: 5, 10, 30 or 60 minutes. Settings lists what’s allowed, each with End Now. When the menu bar item is on, it shows how many are running, with End All.
  • While an allowance runs, Secret Store doesn’t lock from inactivity, so a long script isn’t cut off. Locking your Mac, letting it sleep, or choosing Lock Secret Store (⌘L) still locks it at once and ends every allowance.
  • While Secret Store is locked, requests are refused without asking. Unlock it, then try again. Approving restarts the auto-lock timer, like any other use.
  • Adding a secret also needs your approval, and never replaces an existing one.

Installing the secretstore command

secretstore is a small shell script that comes inside Secret Store. You install it by making a link to it in /usr/local/bin, a folder every Mac searches for commands. Because it’s a link, not a copy, the command updates whenever Secret Store does.

Note: A future version will install it with one button, after you enter your Mac password. Mac App Store apps need Apple’s approval to create the link themselves, and that request is waiting with Apple. Until then, it takes one command in Terminal:

  1. In Settings ▸ Scripts & Agents, under The secretstore command, click Copy Command.
  2. Paste it in Terminal and press Return. Enter your Mac password when asked: creating files in /usr/local/bin needs an administrator.

The command looks like this, with the path to your copy of the app filled in:

sudo mkdir -p /usr/local/bin && sudo ln -sf '/Applications/SecretStore.app/Contents/Resources/SecretStoreCore_SecretStoreCore.bundle/Contents/Resources/secretstore' /usr/local/bin/secretstore
  • mkdir -p creates /usr/local/bin if your Mac doesn’t have it yet.
  • ln -s makes the link; -f replaces anything already at /usr/local/bin/secretstore, like an older copy.

Settings then shows Installed. Only an administrator can change /usr/local/bin, so other programs running as you can’t quietly replace the command there.

Checking it

ls -l /usr/local/bin/secretstore

This shows the link and, after ->, the script it points to. If you move Secret Store to another folder, copy the command from Settings again and run it.

Removing it

sudo rm /usr/local/bin/secretstore

This removes only the link; Secret Store and its script stay as they are.

Giving the command its token

Each client has its own token, and secretstore needs it to ask for secrets. The token sheet you saw after Add Client… shows the keychain command below with the client’s name filled in, with a Copy button.

security add-generic-password -U -s secretstore-cli -a "deploy script" -w
  • security is the Mac’s built-in keychain tool.
  • add-generic-password saves a password item, the same kind you see in Keychain Access.
  • -U replaces the item if one is already there, so you can run it again with a new token.
  • -s secretstore-cli is the item’s service name: secretstore looks for this name.
  • -a "deploy script" is the account name. Use the client’s name, so each client keeps its own token.
  • -w with nothing after it asks for the password, then asks you to retype it. Paste the token both times. That way it never appears on screen or in your shell history.

Then tell secretstore which client it’s acting as:

export SECRETSTORE_CLIENT="deploy script"

Put that line in your ~/.zshrc to make it permanent, or in a project’s .envrc if each project uses a different client. Without it, secretstore looks for an item with the account name default.

Any program running as you can read this item without asking, the same as a token in a file. What protects your secrets is that each request still needs your approval in Secret Store.

To remove a stored token:

security delete-generic-password -s secretstore-cli -a "deploy script"

In an environment variable

export SECRETSTORE_TOKEN="the-token"

When SECRETSTORE_TOKEN is set, secretstore uses it and doesn’t look in the keychain. It’s simpler, but every program started from that shell can read the variable, and if you put the line in a file, the token sits there in plain text. Use the keychain unless you have a reason not to.

Using the secretstore command

Each command needs Secret Store running and unlocked, with the switch in Settings on.

secretstore run

secretstore run --tag env/myproject -- npm test

Runs the command after -- with the secrets under the tag as environment variables, after one approval. Nested tags like env/myproject/db are included. The values go only to that command; nothing is written to disk.

Add --only to pass just some of them to the command, by variable name:

secretstore run --tag env/myproject --only STRIPE_KEY,DATABASE_URL -- ./deploy.sh

You still approve the whole tag: --only limits what the command gets, not what secretstore asks for. A name in --only that doesn’t match anything is ignored.

secretstore get

secretstore get STRIPE_KEY

Prints one secret’s value, after approval. Give the secret’s name, or its variable name exactly as written (STRIPE_KEY, not stripe_key). If two secrets you can use share that name, add --tag to say which:

secretstore get STRIPE_KEY --tag env/myproject

secretstore list and status

secretstore list prints, as JSON, the secrets this client can use: each one’s id, name, tags and variable name, and never a value. secretstore status checks that secretstore can reach Secret Store and that the token works, and shows which client it is. Neither asks for approval.

If you changed the port

Secret Store listens on port 7387. If you change Port in Settings, tell secretstore too:

export SECRETSTORE_PORT=7390

Which variables a command gets

secretstore run sets each secret as an environment variable named after its variable name. Edit a secret to set one, under Environment variable:

  • A new secret gets one suggested from its name as you type: “Stripe key (prod)” becomes STRIPE_KEY_PROD. Change it if you like.
  • If a secret has no variable name, its name is used when it’s already a valid one (letters, digits and _, not starting with a digit), like API_KEY.
  • Otherwise it’s left out, and secretstore says so. Edit the secret and click Use … to take the suggestion.
  • Renaming a secret doesn’t change its variable name, so your scripts keep working.

A few variables are never set, because they change how a shell or a program starts, like PATH, NODE_OPTIONS or anything starting with DYLD_. If two secrets under the tag have the same variable name, neither is set. secretstore also warns when a secret has expired or expires soon.

With direnv

In a project’s .envrc, load a key when you enter the folder (you’ll approve it then):

export STRIPE_KEY="$(secretstore get STRIPE_KEY --tag env/myproject)"

This puts the value into your shell, where every command you run can read it. Running a command through secretstore run keeps it narrower.

Claude Code

Add Secret Store to Claude Code as an MCP server, so it can ask for secrets itself. This command reads the client’s token from your keychain, where you stored it after Add Client… (it assumes you named the client “Claude Code”):

claude mcp add --scope user --transport http secretstore http://127.0.0.1:7387/mcp --header "Authorization: Bearer $(security find-generic-password -s secretstore-cli -a "Claude Code" -w)"
  • --scope user makes Secret Store available in every project. Without it, Claude Code only uses it in the folder you ran the command in.
  • Your shell fills in the token when you run the command, and Claude Code keeps it in its settings file, ~/.claude.json, in plain text. Nothing else changes in your Terminal.
  • If you change the port or add the client again, run claude mcp remove secretstore --scope user and then the command above again.

Claude Code can then list the secrets you granted it, get one after you approve it, and add new ones.

When Claude Code runs secretstore run itself, it acts as whichever client SECRETSTORE_CLIENT names in its environment, usually the one set in your ~/.zshrc. Set it to “Claude Code” there, or in the project’s .envrc, if you want those requests to show as Claude Code.

The Secret Store skill

A short skill tells Claude Code how to use Secret Store safely: run commands through secretstore run, never repeat a value, and what each error means. It works with the secretstore command, the MCP server or both, whichever you’ve set up. Install it with:

mkdir -p ~/.claude/skills/secretstore && curl -fsSL https://coreydaley.dev/apps/secretstore/claude-code/SKILL.md -o ~/.claude/skills/secretstore/SKILL.md

Run it again any time to get the latest version.

Other agents

Any agent that supports MCP over HTTP can use Secret Store the same way. Give it:

  • Address: http://127.0.0.1:7387/mcp
  • Header: Authorization: Bearer followed by the client’s token

Its tools are list_secrets, get_secret, add_secret, list_metadata and propose_changes; the skill describes each one, and you can adapt it as instructions for another agent. An agent that runs shell commands can also use secretstore run, which keeps the values out of its conversation.

Important: A value you give an agent is in its conversation, and in its transcript on disk. Prefer secretstore run, which hands keys to a command without the agent seeing them, and use short-lived keys where you can.

Letting an agent organize your secrets

After a big import, an agent can tidy names, tags, notes and kinds for you. It never sees a value:

  1. The agent asks for the secrets’ metadata. You approve once, as for any request. It gets each secret’s name, tags, notes and kind, and a short hint that Secret Store works out on your Mac, like “looks like recovery codes (10 lines)” or “PEM private key”. Hints come from a fixed list and never include any part of the value.
  2. The agent proposes its changes as one batch. Nothing changes yet.
  3. A Review Changes window opens, showing each change as old → new. Untick anything you don’t want, then click Accept N Selected and confirm with Touch ID or your password. If a new name and tags would match another secret, that secret is left as it was and the rest still apply.
  4. Undo Last Batch in the review window, or in Settings ▸ Scripts & Agents, puts back everything the batch changed.

Note: The names, tags and notes an agent reads leave your Mac with it, and go to its AI provider. Values never do. An agent can’t delete a secret, change a value, change a variable name or change who can use a secret this way.

A pending proposal ends when you lock Secret Store, quit it, turn off the switch or revoke the client.

What it can’t do

  • Reach your Mac from another computer: it listens on 127.0.0.1 only.
  • Connect out: Secret Store still can’t open any network connection.
  • Read everything at once, change a value or delete a secret. Name, tag and note changes only happen after you review and accept them.
  • Work while Secret Store isn’t running, or while the switch is off.

Before it sends the token, secretstore checks that the program listening is really Secret Store, by its code signature.

Settings shows the latest requests under Activity, allowed or refused, while Secret Store is unlocked. The list stays on this Mac and never includes a value.

If something goes wrong

secretstore saysWhat to do
no tokenStore the token in your keychain under the client’s name, and set SECRETSTORE_CLIENT to that name.
isn’t running, or Scripts & Agents is offOpen Secret Store and check the switch in Settings.
Scripts & Agents is offTurn on the switch in Settings.
SECRETSTORE_PORT must be a numberFix the value, or unset SECRETSTORE_PORT.
the program on port 7387 isn’t Secret StoreSomething else is using the port; quit it or change the port in Settings and set SECRETSTORE_PORT.
lockedUnlock Secret Store and run it again.
wasn’t approvedYou chose Deny, or the 60 seconds ran out.
can’t use thatShare the secret and grant it to this client.
no secret by that nameCheck the name with secretstore list.
more than one secret has that nameAdd --tag.
another request is waiting for approvalAnswer the panel that’s open, then try again.
the token was refusedThe client was revoked or the token is wrong; add the client again.
skipped “…”: it has no variable nameEdit the secret and set its variable name.