Codex
Codex CLI is OpenAI’s coding agent for the terminal. Use varlock to inject API keys at runtime so they never sit in a plain text .env or shell history.
For install, schema setup, and shared patterns, see the AI Tools overview.
Authentication: Codex supports ChatGPT sign-in (subscription) and API key auth (usage-based). Interactive ChatGPT login is fine for local work. Prefer an API key (via varlock) for headless/codex exec workflows.
Environment variables (see Codex environment variables):
CODEX_API_KEY: API key for a single non-interactivecodex execrunOPENAI_API_KEY: commonly used for API key login and custom model providers that setenv_key
In a project
Section titled “In a project”Add to .env.schema:
# @sensitive @requiredOPENAI_API_KEY=op(op://api-local/openai/api-key)
# @sensitive @requiredCODEX_API_KEY=op(op://api-local/openai/api-key)For interactive Codex, use varlock to pass the key into the one-time login command. Codex stores the resulting credentials for later sessions:
varlock run -- sh -c 'printenv OPENAI_API_KEY | codex login --with-api-key'codexFor a single non-interactive run, inject CODEX_API_KEY directly:
varlock run -- codex exec "summarize the recent git changes"From any directory
Section titled “From any directory”Personal schema at ~/.env.codex:
# @sensitive @requiredOPENAI_API_KEY=op(op://api-local/openai/api-key)
# @sensitive @requiredCODEX_API_KEY=op(op://api-local/openai/api-key)varlock run -p ~/.env.codex -- sh -c 'printenv OPENAI_API_KEY | codex login --with-api-key'codex
varlock run -p ~/.env.codex -- codex exec "summarize the recent git changes"