Skip to content

Support environment variable expansion #2680

Open

Description

@Epokhe

What feature would you like to see?

From CC docs: https://docs.anthropic.com/en/docs/claude-code/mcp#environment-variable-expansion-in-mcp-json

I think codex doesn't support this yet, at least the same ${ENV_VAR} syntax didn't work for me. Currently I have to put secrets directly into ~/.codex/config.toml, I think?

Are you interested in implementing this feature?

No

Additional information

No response

Activity

  1. added
    enhancement
    on Aug 25, 2025
  2. masda70 commented on Sep 2, 2025

    @masda70

    I tried different syntaxes as well and couldn't manage to make environment variable interpolation work, so I believe Codex CLI does not yet support this feature indeed.

    This kind of feature would be great when you need to share and sync Codex CLI config across multiple, possibly ephemeral, dev environments (e.g., devcontainers, Gihub Codespaces) while letting each machine manage its own secrets or instance specific params.

  3. kossnocorp commented on Oct 2, 2025

    @kossnocorp

    Env var expansion will help a lot with stuff like this:

    [shell_environment_policy]
    set = { GIT_CONFIG_GLOBAL = "${HOME}/.config/git/agent.config" } # Use agent git config
    

    GIT_CONFIG_GLOBAL needs to be absolute, so ~/ won't work.

    I have this in my dotfiles that automatically pulled in Dev Containers, so having project-specific config is not an option.

    I currently have an Ansible playbook that solves this (that also merges local config), sharing it in case anyone needs a workaround:

    ---
    - name: Apply project Codex configurations
      hosts: localhost
      gather_facts: no
      vars:
        start_marker: "#@project"
        end_marker: "#@project-end"
    
      tasks:
        - name: Read project config
          slurp:
            src: "{{ project_config }}"
          register: project_content
    
        - name: Merge project config into global config
          blockinfile:
            path: "{{ global_config }}"
            marker_begin: "{{ start_marker }}"
            marker_end: "{{ end_marker }}"
            block: "{{ project_content['content'] | b64decode }}"
            create: yes
            backup: yes
    
        - name: Read merged config
          slurp:
            src: "{{ global_config }}"
          register: merged_content
    
        - name: Expand ${HOME} in merged config
          copy:
            dest: "{{ global_config | expanduser }}"
            content: >-
              {{ merged_content['content'] | b64decode | regex_replace('\$\{HOME\}', lookup('env','HOME')) }}
            backup: yes
            mode: "0644"

    I use such a script to run it:

    #!/usr/bin/env bash
    
    # This script merges global and local Codex config and expands necessary
    # environment variables (as they aren't supported yet: https://github.com/openai/codex/issues/2680).
    
    set -eo pipefail
    root_dir="$(dirname "$0")/.."
    
    echo -e "⚡️ Setting up Codex\n"
    
    # Merge local Codex config to global config, as it doesn't support relative
    # paths yet: https://github.com/openai/codex/issues/3706
    
    echo -e "🌀 Merging project Codex config to ~/.codex/config.toml"
    
    codex_config_path_chunk=".codex/config.toml"
    local_codex_config_tmpl_path=$(realpath "$root_dir/$codex_config_path_chunk")
    global_codex_config_path="$HOME/$codex_config_path_chunk"
    
    ansible-playbook "$root_dir/scripts/setup-codex/playbook.yaml" \
      -i localhost, --connection=local \
      --extra-vars "global_config=$global_codex_config_path project_config=$local_codex_config_tmpl_path"
    
    echo -e "\n💚 Codex setup complete!"
  4. LimLLL commented on Dec 19, 2025

    @LimLLL

    can't believe codex still doesn't support the env expansion......

  5. added
    mcp
    on Feb 23, 2026
  6. jeroenwienk commented on Feb 28, 2026

    @jeroenwienk

    Really need this as well there is now way to have a shared config now.

  7. michaelfrog commented on Jun 30, 2026

    @michaelfrog

    What is the best workaround today? assuming i have dynamic url for remote MCP that i want to plant in plugin ?

  8. starryeyez024 commented on Sep 30, 2026

    @starryeyez024

    Any updates on this?

  9. ghobadimhd commented on Oct 21, 2026

    @ghobadimhd

    I have a project-scoped MCP configuration where the server expects generic environment variable names such as OPENSEARCH_USERNAME and OPENSEARCH_PASSWORD.

    For security, I do not want to place credential values in the project’s .codex/config.toml. I also do not want to require contributors to rename their existing locally managed environment variables just to match one MCP server’s expected names.

    A supported expansion/alias mechanism would solve this cleanly, for example:

    [mcp_servers.example.env]
    OPENSEARCH_USERNAME = "${LOCAL_CLUSTER_A_OPENSEARCH_USERNAME}"
    OPENSEARCH_PASSWORD = "${LOCAL_CLUSTER_A_OPENSEARCH_PASSWORD}"
    
    or an explicit mapping form:
    
    [mcp_servers.example]
    env_vars = [
      { name = "OPENSEARCH_USERNAME", from = "LOCAL_CLUSTER_A_OPENSEARCH_USERNAME" },
      { name = "OPENSEARCH_PASSWORD", from = "LOCAL_CLUSTER_A_OPENSEARCH_PASSWORD" },
    ]

    This would keep secrets out of repository-scoped configuration while allowing portable MCP configuration that uses the environment variable names required by the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions