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

Open
opened 2026-02-16 18:05:08 -05:00 by yindo · 1 comment
Owner

Originally created by @zdzh on GitHub (Jan 18, 2026).

Originally assigned to: @thdxr on GitHub.

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 🙏

Originally created by @zdzh on GitHub (Jan 18, 2026). Originally assigned to: @thdxr on GitHub. ### 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 🙏
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2026):

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

  • #6936: [FEATURE]: Pass agents bash env variables OR pass agents bashrc files
  • #6055: [FEATURE]: mcp server environment must accept env var.
  • #5423: [FEATURE]: Store provider credentials in environment variables
  • #9292: [FEATURE]: Expose session context to child processes via environment variables

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.

@github-actions[bot] commented on GitHub (Jan 18, 2026): This issue might be a duplicate of existing issues. Please check: - #6936: [FEATURE]: Pass agents bash env variables OR pass agents bashrc files - #6055: [FEATURE]: mcp server environment must accept env var. - #5423: [FEATURE]: Store provider credentials in environment variables - #9292: [FEATURE]: Expose session context to child processes via environment variables 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6747