Codex secrets and env variables, without pasting keys in the chat
Codex needs your app's API keys to run it, and pasting them in the chat or leaving a .env file for it to read puts the value in the conversation. With Envshed, Codex signs in to the Envshed MCP server with your account and runs the app through envshed run, which injects the values. You enter a missing value on a page, not in the chat.
You need an Envshed account, Node.js 20.12 or later and Codex. Codex connects to Envshed's remote MCP server with OAuth, so there is no key to copy.
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
The browser shows a code. Check that it matches the one in the terminal, then choose Approve sign-in.
Step 2: Connect the MCP server
codex mcp add envshed --url https://app.envshed.com/api/mcp
This opens the OAuth sign-in in your browser. Check that the page asks you to approve the connection, and approve it only if you started it. Afterwards, run:
codex mcp list
The envshed row should show Auth as OAuth. If the browser does not open, run codex mcp login envshed. To disconnect from Codex, run codex mcp logout envshed.
Step 3: Write the project rule
From the project folder:
envshed agent rules
It shows the files and the text, then asks before writing. It writes AGENTS.md, which Codex reads. The rule tells the agent 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 file: it holds no secret.
Step 4: Give Codex 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 --redact -- npm start Never read .env files, never print secret values and never ask me to paste a value in the chat.
Step 5: Check the history
envshed scan
envshed scan searches local agent history for your vault's values and for known token formats, and never shows a value. It reads Claude Code's history by default; for other files, pass --path <file or folder>. If it finds something, rotate that secret.
What this does and does not do
The OAuth connection was tested with Codex. Tool use follows the same protocol as other clients. envshed run works with Codex as with any other process.
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. Nothing in this setup blocks Codex from reading a .env file; the project rule only asks it not to, and an agent can ignore a rule. 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 Codex 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 the app runs with envshed run, the process gets the values and the output is masked if you use --redact. An agent with shell access can still try to print its own environment.
How do I give Codex an env variable that is missing?
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.
How do I disconnect Codex?
Run codex mcp logout envshed. To cut off access from Envshed's side, open Account > Personal API tokens, and under Connected MCP clients choose Revoke. The client stops working on its next request.
Using another agent? See the Claude Code or Cursor guide.