Handle secrets in app environments
Open 💬 7 comments Opened Feb 3, 2026 by heddendorp
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What variant of Codex are you using?
App
What feature would you like to see?
I like the app and the idea of setup scripts but have some secrets in .env and .npmrc that are needed in a new worktree of my project.
It would be nice to have a way to carry such files over as they are not checked in.
Additional information
_No response_
7 Comments
Check out the "Environments" tab in the settings panel. This feature allows you to specify a setup script that runs when a worktree is created. You can use this script to copy over you
.envfiles.is there a
$CODEX_ROOT_PATH-like variable I can use to reference the main project path when copying the.envfiles?This worked for me in the end, but can't guarantee if this is a good way to handle this that works in 100% of the cases
MAIN_WORKTREE variable is now your root worktree path and you can copy .env files to the new one.
<details>
<summary>This is the setup script I use for copying .env files using @jkadamczyk's approach:</summary>
<br>
</details>
there should be a .worktreeinclude file
I ran into the same class of problem while thinking about Git worktrees and coding agents.
I ended up building local.env, an OSS tool that keeps local development env requirements tied to the repo while syncing the actual values separately through a CLI.
It doesn’t copy the entire working directory into a new worktree. The goal is more that a fresh checkout/worktree can figure out which local env values it needs and retrieve them securely instead of relying on manually copying .env.local.
I’m curious whether that model would actually help with the Codex worktree workflow described here:
https://github.com/mithatakbulut/local.env
Regarding handling and isolating ambient secrets in Codex environments:
Relying on application-level prompt rules or
.gitignoreis insufficient because subagents and shell tools (cat,env,grep, python scripts) still inherit full read access to ambient environment variables and local files.To enforce deterministic, kernel-level secret boundaries on macOS and Linux:
Vetto wraps Codex in an immutable OS perimeter:
How Vetto protects secrets:
~/.ssh,~/.aws,.env,.env.*) are mapped to/dev/nullat the kernel layer (Landlock/Seatbelt). Reading them returns EOF.sk-proj-...,ghp_...) before they hit the terminal or disk.