summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJacob Hands <[email protected]>2025-07-29 10:03:11 -0500
committerGitHub <[email protected]>2025-07-29 11:03:11 -0400
commit862a50d61de5d054418ae205c7f791d1e3cbc081 (patch)
treeb95bfd2b17c39c1cfbccb9ed3132288e6332b3c2
parenta7cfd36b075052e0a40b635665d7d4be90327c48 (diff)
downloadopencode-862a50d61de5d054418ae205c7f791d1e3cbc081.tar.gz
opencode-862a50d61de5d054418ae205c7f791d1e3cbc081.zip
feat: add OPENCODE_CONFIG env var for specifying a custom config file (#1370)
-rw-r--r--packages/opencode/src/config/config.ts7
-rw-r--r--packages/opencode/src/flag/flag.ts1
-rw-r--r--packages/web/src/content/docs/docs/config.mdx11
3 files changed, 19 insertions, 0 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index 9aaa31ea6..2d896a534 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -10,6 +10,7 @@ import fs from "fs/promises"
import { lazy } from "../util/lazy"
import { NamedError } from "../util/error"
import matter from "gray-matter"
+import { Flag } from "../flag/flag"
export namespace Config {
const log = Log.create({ service: "config" })
@@ -23,6 +24,12 @@ export namespace Config {
}
}
+ // Override with custom config if provided
+ if (Flag.OPENCODE_CONFIG) {
+ result = mergeDeep(result, await load(Flag.OPENCODE_CONFIG))
+ log.debug("loaded custom config", { path: Flag.OPENCODE_CONFIG })
+ }
+
result.agent = result.agent || {}
const markdownAgents = [
...(await Filesystem.globUp("agent/*.md", Global.Path.config, Global.Path.config)),
diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts
index e6f54440b..afc610b66 100644
--- a/packages/opencode/src/flag/flag.ts
+++ b/packages/opencode/src/flag/flag.ts
@@ -1,6 +1,7 @@
export namespace Flag {
export const OPENCODE_AUTO_SHARE = truthy("OPENCODE_AUTO_SHARE")
export const OPENCODE_DISABLE_WATCHER = truthy("OPENCODE_DISABLE_WATCHER")
+ export const OPENCODE_CONFIG = process.env["OPENCODE_CONFIG"]
function truthy(key: string) {
const value = process.env[key]?.toLowerCase()
diff --git a/packages/web/src/content/docs/docs/config.mdx b/packages/web/src/content/docs/docs/config.mdx
index 34184107b..abd05c335 100644
--- a/packages/web/src/content/docs/docs/config.mdx
+++ b/packages/web/src/content/docs/docs/config.mdx
@@ -34,6 +34,17 @@ This is also safe to be checked into Git and uses the same schema as the global
---
+### Custom config file
+
+You can specify a custom config file using the `OPENCODE_CONFIG` environment variable. This takes precedence over the global and project configs.
+
+```bash
+export OPENCODE_CONFIG=/path/to/my/custom-config.json
+opencode run "Hello world"
+```
+
+---
+
## Schema
The config file has a schema that's defined in [**`opencode.ai/config.json`**](https://opencode.ai/config.json).