Skip to content

Claude Code secrets and env variables, without pasting keys in the chat

Claude Code needs your app's API keys to run it, and the easy way to give them is to paste them in the chat or leave a .env file for it to read. Both put the value in the conversation. With Envshed, Claude Code lists which keys exist, asks you for one that is missing, and runs the app with the values injected. You enter a missing value on a page, and it never goes through the chat.

This takes about ten minutes. You need an Envshed account, Node.js 20.12 or later and Claude Code.

Steps

Step 1: Install the CLI and sign in

Run this in your own terminal, not in the agent:

npm install -g envshed
envshed login

envshed login opens the browser and prints a code. Check that the browser shows the same code, then choose Approve sign-in. The agent's envshed commands use this login, with your permissions.

Step 2: Add the hooks and the skill

envshed agent install

This adds two hooks and a skill to ~/.claude. The hooks stop a prompt that contains a secret and block commands that would print one, such as cat .env or envshed secret get. The skill tells the agent to use envshed request and envshed run. Restart Claude Code afterwards.

Step 3: Connect the MCP server

claude mcp add --transport http envshed https://app.envshed.com/api/mcp
claude mcp login envshed

claude mcp login envshed opens the browser. Check that it names Claude Code, then choose Approve. To confirm, run claude mcp get envshed: it shows Status: Connected.

Step 4: Write the project rule

From the project folder:

envshed agent rules

It shows the files and the text, then asks before writing. The rule tells every agent that opens the repository to use envshed run --redact --, to list key names without values, and to ask for a missing key instead of asking you to paste it. Commit the files: they hold no secret.

Step 5: Give Claude Code a task

Paste this, with your organization, project and start command:

Run this app with Envshed. Organization: acme. Project: my-app. Environment: development.
1. Use the Envshed MCP server to list the key names and find any that are missing.
2. For each missing key, call request_secret, give me the link and wait until I fill it.
3. Run the app with: envshed run -- npm start
Never read .env files, never print secret values and never ask me to paste a value in the chat.

Claude Code gets each key name with a status (set, placeholder, disabled or missing) and no values. For a missing key it gives you a link to the dashboard, and you enter the value there. When the app prints a secret, the output shows a marker instead:

DATABASE_URL=[ENVSHED:DATABASE_URL]
EMAIL_API_KEY=[ENVSHED:EMAIL_API_KEY]

Step 6: Check the history

envshed scan

envshed scan searches the agent's local history for your vault's values and for known token formats. It never shows a value. If it finds something, rotate that secret.

What this does and does not do

It reduces accidental leaks. It is not a barrier against an agent with shell access: the agent can reach what your login can, for example by copying .env to another name and reading the copy. The hooks block the common routes, and a project rule is an instruction the agent can ignore. Limits that must hold, such as who can read production, belong on the server: use roles and scoped service tokens. See what Envshed guarantees and what it does not.

FAQ

Can Claude Code read my API key?

Not through the Envshed MCP server: no tool returns a secret value, and no tool has a field for one. When you run the app with envshed run, the process gets the values and Claude Code sees masked output. An agent with shell access can still try to print its own environment, which is why the limits above matter.

How do I give Claude Code an env variable that is missing?

The agent calls request_secret and gives you a link. You open it and enter the value in the dashboard. You can also ask for a key from any terminal with envshed request EMAIL_API_KEY --reason "send email".

Do I still need a .env file?

No. envshed run -- <command> injects the secrets as environment variables and writes no .env file to disk.

What if I pasted a real key in the chat?

The prompt hook stops it from reaching the model, but Claude Code still writes what you typed to its local files. Rotate the key.

Using another agent? See the Cursor or Codex guide.

Envshed