feat: support for dedicated configuration file for API keys
Resolved 💬 6 comments Opened Apr 23, 2025 by tim-watcha Closed Aug 7, 2025
Current Behavior
Currently, the codex project supports setting the OpenAI API key in two ways:
- As an environment variable:
export OPENAI_API_KEY="your-api-key-here" - In a
.envfile at the root of the project:OPENAI_API_KEY=your-api-key-here
Requested Feature
Add support for storing the OpenAI API key in a dedicated, user-wide configuration file (e.g., ~/.codex.config) that would be specific to the codex tool.
Motivation
- Persistence: Avoids having to re-export environment variables in every new terminal session
- Separation of concerns: Keeps API keys separate from project files and specific to the codex tool
- Security: Provides a dedicated location for sensitive credentials outside of project directories
- User convenience: Makes it easier for users who work with multiple projects but want a consistent API key setup
Proposed Implementation
Add the ability to read OpenAI API keys from a dedicated configuration file at ~/.codex.config (or similar location). For example:
# ~/.codex.config
OPENAI_API_KEY=your-api-key-here
The configuration file could use a simple format like the existing .env approach or a more structured format like YAML/JSON if additional configuration options might be needed in the future.
6 Comments
You can add the export line to your shell's configuration file (e.g., ~/.zshrc) to persist through terminal sessions.
And if you mean, for like separate organization keys, you should use Docker or something, so you can load up .env files.
While using Docker is a good suggestion, having a dedicated configuration file as proposed would be more convenient for those who plan to use codex consistently.
This approach is particularly useful when:
Having a
~/.codex.configfile would allow for simple and consistent configuration in these scenarios.Having keys outside environment variables is not recommended with basically any provider, though. It's a security risk.
Thank you for the feedback! We're primarily focused on the native/Rust implementation of Codex CLI. Please check if this feature is still needed on the latest version and consider contributing to the
codex-rs/implementation if it is.Anyone finding this:
In
~/.codex/auth.json: