You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,16 @@ OpenCode plugin that loads `.env` files at startup. This is a Bun runtime plugin
10
10
**Type**: OpenCode plugin
11
11
**Language**: TypeScript (ESM)
12
12
13
+
### Critical Architectural Limitation
14
+
15
+
This plugin **cannot** set environment variables for use in OpenCode's config file. OpenCode parses `opencode.jsonc` (including `{env:VAR}` resolution) **before** loading plugins. Therefore:
16
+
17
+
- Variables set by this plugin are available to chat sessions and tool executions
18
+
- Variables set by this plugin are **NOT** available to `{env:VAR}` references in `opencode.jsonc`
19
+
- For config variables (API keys, etc.), users must set them in shell profile before starting OpenCode
20
+
21
+
See `docs/ARCHITECTURE.md` for detailed startup sequence diagrams.
22
+
13
23
## Essential Commands
14
24
15
25
### Build & Install
@@ -78,14 +88,17 @@ bun run src/index.ts
78
88
```
79
89
opencode-dotenv/
80
90
├── src/
81
-
│ ├── index.ts # Main plugin entry point
82
-
│ ├── index.test.ts # Unit tests
91
+
│ ├── index.ts # Entry point, re-exports
92
+
│ ├── plugin.ts # Main plugin implementation
93
+
│ ├── test-utils.ts # Internal test utilities
83
94
│ └── profiler/
84
95
│ ├── index.ts # Profiler exports
85
96
│ └── profiler.ts # Performance profiler
86
97
├── bench/
87
98
│ ├── utils.ts # Benchmark utilities
88
99
│ └── init.bench.ts # Initialization benchmarks
100
+
├── docs/
101
+
│ └── ARCHITECTURE.md # Plugin architecture and startup sequence
89
102
├── dist/ # Built output (generated, not in git)
90
103
├── package.json
91
104
├── Makefile
@@ -99,6 +112,7 @@ opencode-dotenv/
99
112
- Tests co-located with source code
100
113
- Only `dist/` directory is published to npm (see `package.json``files` field)
101
114
- Source files are excluded from npm package via `.npmignore`
Copy file name to clipboardExpand all lines: README.md
+34-23Lines changed: 34 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,27 @@
2
2
3
3
OpenCode plugin to load `.env` files at startup.
4
4
5
+
> **Important Limitation**
6
+
>
7
+
> This plugin **cannot** set environment variables for use in OpenCode's config file (`opencode.jsonc`). The plugin loads *after* OpenCode parses its configuration, so `{env:VARNAME}` references in config are resolved before this plugin runs.
8
+
>
9
+
> **Use this plugin for:** Managing environment variables available during chat sessions, tool executions, and bash commands.
10
+
>
11
+
> **Do not use this plugin for:** Setting API keys or other config values referenced via `{env:VAR}` syntax in `opencode.jsonc`. For those, set variables in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
12
+
>
13
+
> See [Architecture](docs/ARCHITECTURE.md) for details on the OpenCode startup sequence.
14
+
5
15
## Features
6
16
7
17
- Load multiple `.env` files in order via config file
8
18
- Load `.env` from current working directory (optional)
- Configurable logging to `/tmp/opencode-dotenv.log` (enabled by default)
20
+
- Configurable logging to `~/.local/share/opencode/dotenv.log` (disabled by default)
11
21
- Prevents double loading with load guard
12
22
- JSONC config file format (supports comments and trailing commas)
13
23
-**Requires Bun runtime**
14
-
15
-
## Limitations
16
24
17
-
**Important:** This plugin loads AFTER OpenCode configuration is already parsed. Therefore:
25
+
## Limitations
18
26
19
27
1.**Cannot modify existing OpenCode config** - Variables loaded by this plugin cannot be referenced in `opencode.jsonc` using `{env:VAR}` syntax. OpenCode reads its config before plugins initialize.
20
28
@@ -45,12 +53,12 @@ After publishing to npm, you can use:
45
53
46
54
## Configuration
47
55
48
-
Create `opencode-dotenv.jsonc` in one of these locations:
56
+
Create `dotenv.jsonc` in one of these locations (searched in order, first found wins):
49
57
50
-
1.`~/.config/opencode/opencode-dotenv.jsonc`(recommended, global config)
51
-
2.`./opencode-dotenv.jsonc`in current working directory (project-specific)
58
+
1.`./dotenv.jsonc`in current working directory (project-specific)
**Note:** This plugin cannot inject these variables into OpenCode's configuration loading process. To use `OPENCODE_API_KEY` in `opencode.jsonc`, set it in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
159
+
**Note:** This plugin cannot inject variables into OpenCode's configuration loading process. To set `ANTHROPIC_API_KEY` or other provider API keys, set them in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
152
160
153
161
`./.env` (project-specific):
154
162
```bash
@@ -157,23 +165,23 @@ OPENCODE_DEBUG=false
157
165
PROJECT_API_KEY=project_specific_key
158
166
```
159
167
160
-
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `OPENCODE_API_KEY` from global, `PROJECT_API_KEY` from cwd.
168
+
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `MY_PROJECT_KEY` from global, `PROJECT_API_KEY` from cwd.
0 commit comments