Skip to content

How to make OpenCode load environment variables from a file when executing commands in skills #9334

Closed

Description

@zdzh

Question

I’m trying to execute some shell commands inside an OpenCode skill, but these commands depend on several environment variables (for example API keys, custom paths, or runtime configs).

At the moment, it seems that OpenCode does not automatically load environment variables from a specified file (such as .env) when running commands defined in a skill.

What I want to achieve

I’d like OpenCode to be able to load environment variables from a designated env file before executing skill commands, so that:

Skills can run in a reproducible environment

Secrets and configs don’t need to be hard-coded in skill definitions

The behavior is closer to tools like dotenv, direnv, or envsubst

Expected behavior (examples)

Some possible approaches that would work:

Allow specifying an env file in the skill configuration, e.g.

envFile: .env

Or automatically load .env from the project root when executing skills

Or provide a hook / setting to inject environment variables before command execution

Question

What is the recommended way to make OpenCode load environment variables automatically when executing commands inside a skill?
If this is not currently supported, is there a plan or recommended workaround?

Thanks in advance 🙏

Activity

  1. github-actions commented on Jan 19, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    These issues discuss related requests for environment variable support in OpenCode, including passing environment variables to skills/agents and loading from .env files. Feel free to ignore if your specific use case differs.

  2. github-actions commented on Mar 27, 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.

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