- TypeScript 100%
| docs | ||
| src | ||
| .gitignore | ||
| biome.json | ||
| bun.lock | ||
| package.json | ||
| README.md | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
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_KEYcomes from global configNODE_ENV=production(local overrides global)DEBUG=truecomes 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