Skip to content

add ability to load secrets from external command or environment variables in the config file #231

Closed

Description

@adikari

I have all my dotfiles in a github repository. I want the opencode configuration to be part of my dotfiles. I am using github mcp which requires the github personal access token so I cant commit the file.

Can we make the config file to

  1. evaluate environment variables OR
  2. evaluate command (eg pass)

Activity

  1. thdxr commented on Jun 20, 2025

    @thdxr
    Member

    i believe opencode will load .env files - does that help? typically we try to avoid too much env loading as people always have complex wasy they want to load the env

    can you ensure the env is loaded before opencode starts? if not we can figure something out

  2. self-assigned this
    on Jun 20, 2025
  3. adikari commented on Jun 20, 2025

    @adikari
    Author

    Actually, I ended up doing it differently which works perfectly for my use case. I added a bash script that uses pass to dynamically load the github token, then use the base script as local tool.

    Example for others who run into similar issue

    # /home/user/.config/opencode/commands/github
    #!/bin/bash
    TOKEN=$(pass personal/github_token)
    docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN=$TOKEN ghcr.io/github/github-mcp-server
    "mcp": {
        "github": {
            "type": "local",
            "command": ["/home/user/.config/opencode/commands/github"]
        }
    }
    

    @thdxr i did not try the .env route. I had the variable loaded in my shell via .zshrc and it did not work. The script solution works fine for my usecase, so feel free to close this issue if you dont want to investigate further into environment variables.

  4. aspiers commented on Jun 28, 2025

    @aspiers
    Contributor

    See also #318 and #342.

  5. caleb-reyes-op commented on Dec 15, 2025

    @caleb-reyes-op

    I'm also having the same issue with .zshrc -- I have my .env sourced, with all values printable in my terminal, but they arent being loaded in opencode:

    expected:

    "context7": {
          "type": "remote",
          "url": "https://mcp.context7.com/mcp",
          "headers": {
            "CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"
          },
          "enabled": true
    },

    opencode debug config:

    "context7": {
          "type": "remote",
          "url": "https://mcp.context7.com/mcp",
          "enabled": true,
          "headers": {
            "CONTEXT7_API_KEY": ""
    }
    

    the API key is printable in my shell.

  6. added a commit that references this issue on Jan 1, 2026
    fc158ca
  7. betaboon commented on Jan 14, 2026

    @betaboon

    https://github.com/olimorris/codecompanion.nvim uses a syntax like this {cmd:pass some-token} which is quite nice.

  8. evannotfound commented on Jan 17, 2026

    @evannotfound

    I agree this feature will be pretty helpful, because in this way I can e.g. use 1Password cli to retrieve secrets, and never store the secrets locally.

    right now i am using an approach where i put all my keys inside .secrets directory and use file references {file:./.secrets/xxx.key} to inject them. this way i can commit my opencode config to my private remote repo

  9. liby commented on Jan 19, 2026

    @liby

    opencode will load .env files

    Heads-up: the packaged CLI currently does NOT auto-load project .env files. It only reads existing environment variables.

    Dev build sets autoloadDotenv: false, and earlier builds used --env-file="".

    So {env:VAR} resolves only if the env var is already set before opencode starts. The docs line about project .env looks outdated.

  10. nikaro commented on Jan 20, 2026

    @nikaro

    Did not found this issue before, so i closed mine.

    Here is the associated PR: #8917

    @thdxr do you mind taking a look at it?

  11. github-actions commented on Mar 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

  12. nikaro commented on Mar 26, 2026

    @nikaro

    For those looking to a coding agent that supports this:

  13. malikwirin commented on Apr 9, 2026

    @malikwirin

    For those looking to a coding agent that supports this:

    How does crush support this? This would resolve charmbracelet/crush#2334

  14. ivucica commented on Jul 30, 2026

    @ivucica

    This should be reopened and expanded:

    Beyond just secrets management, as an example, external tools may be needed to recompute authentication credentials for MCPs. Supporting something like calling $(gcloud auth print-access-token) for every connection establishment towards an MCP would be great. The bearer token expires hourly (though seemingly slightly adjustable).

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions