Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

fix: pass environment variables to codex MCP process#29

Merged
bra1nDump merged 2 commits intoslopus:mainfrom
tianyn1990:fix-codex-env-variables
Oct 10, 2025
Merged

fix: pass environment variables to codex MCP process#29
bra1nDump merged 2 commits intoslopus:mainfrom
tianyn1990:fix-codex-env-variables

Conversation

@tianyn1990
Copy link
Copy Markdown
Contributor

Fix: Pass environment variables to codex MCP process

Problem

When running happy codex with custom environment variables configured in ~/.codex/config.toml, the command fails with "Missing environment variable: MY_ENV_KEY" error.

Steps to Reproduce:

  1. Add env_key = "MY_ENV_KEY" to ~/.codex/config.toml
  2. Set environment variable: export MY_ENV_KEY="some_value"
  3. Run happy codex
  4. Error: "Missing environment variable: MY_ENV_KEY"

Solution

The StdioClientTransport constructor was not passing environment variables to the codex subprocess. Added proper environment variable inheritance in src/codex/codexMcpClient.ts.

Code Changes:

// Before
this.transport = new StdioClientTransport({
    command: 'codex',
    args: ['mcp']
});

// After  
this.transport = new StdioClientTransport({
    command: 'codex',
    args: ['mcp'],
    env: Object.keys(process.env).reduce((acc, key) => {
        const value = process.env[key];
        if (typeof value === 'string') acc[key] = value;
        return acc;
    }, {} as Record<string, string>)
});

Testing

  • happy codex now starts without environment variable errors
  • ✅ Custom environment variables properly inherited by codex process
  • ✅ No breaking changes

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Fixes #[ISSUE_NUMBER] (if applicable)

tianyn1990 and others added 2 commits September 18, 2025 03:11
- Add env parameter to StdioClientTransport constructor calls
- Fixes missing environment variable error when running happy codex
- Ensures all environment variables are properly inherited by codex subprocess
@bra1nDump bra1nDump merged commit 7d253c7 into slopus:main Oct 10, 2025
@bra1nDump
Copy link
Copy Markdown
Contributor

Thank you for your contribution, apologies for a long wait to merging this

jasonnoahchoi pushed a commit to jasonnoahchoi/happy-cli that referenced this pull request Dec 5, 2025
- Add env parameter to StdioClientTransport constructor calls
- Fixes missing environment variable error when running happy codex
- Ensures all environment variables are properly inherited by codex subprocess

Co-authored-by: Kirill Dubovitskiy <kirill2003de@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants