No description
  • TypeScript 100%
Find a file
2026-06-12 14:47:30 -06:00
docs feat: working env-inject plugin 2026-05-19 16:19:05 -06:00
src feat: add biome, build types, dist-only publish 2026-06-12 14:24:41 -06:00
.gitignore chore: prepare package for publishing 2026-06-12 14:32:12 -06:00
biome.json feat: add biome, build types, dist-only publish 2026-06-12 14:24:41 -06:00
bun.lock feat: add biome, build types, dist-only publish 2026-06-12 14:24:41 -06:00
package.json chore: add repo to package 2026-06-12 14:47:30 -06:00
README.md chore: prepare package for publishing 2026-06-12 14:32:12 -06:00
tsconfig.build.json feat: add biome, build types, dist-only publish 2026-06-12 14:24:41 -06:00
tsconfig.json feat: working env-inject plugin 2026-05-19 16:19:05 -06:00

opencode-env-inject

OpenCode plugin that injects environment variables from JSON config files into every shell session.

Installation

Copy dist/env-inject.ts to the local or home plugins path.

cp dist/env-inject.ts ~/.config/opencode/plugins/

Configuration

Global Config

Create ~/.config/opencode/env.json:

{
  "MY_API_KEY": "your-api-key-here",
  "NODE_ENV": "development"
}

Local Config

Create .opencode/env.json in your project directory:

{
  "NODE_ENV": "production",
  "DEBUG": "true"
}

Merge Behavior

Local config overrides global config on key conflicts.

In the example above:

  • MY_API_KEY comes from global config
  • NODE_ENV = production (local overrides global)
  • DEBUG = true comes from local config

Usage

Once installed, all shell commands executed through OpenCode will have these environment variables available automatically.

Error Handling

  • Missing config files are ignored gracefully
  • Invalid JSON is ignored with no error
  • Existing environment variables are preserved (not overwritten)

Building

bun run build

Produces dist/index.js (bundle) and dist/index.d.ts (type declarations). @opencode-ai/plugin is external — opencode provides it at runtime.

Publishing

Build first, then publish with bun publish:

bun run build
bun publish --access public

bun publish is Bun's native publish command (not an npm wrapper). The --access public flag is required for public packages. Alternatively, set it once in package.json:

"publishConfig": { "access": "public" }

With files: ["dist"] in package.json, only the build output is shipped — src/, biome.json, tsconfig*.json, and other dev files are excluded.

For local development, symlink the bundle into the opencode plugins dir instead of installing:

ln -sf $(pwd)/dist/index.js ~/.config/opencode/plugins/env-inject.ts