summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Silverlock <[email protected]>2025-12-29 11:37:41 -0500
committerGitHub <[email protected]>2025-12-29 10:37:41 -0600
commit56b5cdf88316af25a58215de899f90eea23db9b9 (patch)
treeeff79a55df1e88980fdbb8fd2eb7e50840d92bb2
parentfb0e1e4d8d3adc54b382c9daa5cdae7435d82e35 (diff)
downloadopencode-56b5cdf88316af25a58215de899f90eea23db9b9.tar.gz
opencode-56b5cdf88316af25a58215de899f90eea23db9b9.zip
feat: install local plugin dependencies from package.json (#6302)
Co-authored-by: OpenCode <[email protected]>
-rw-r--r--packages/opencode/src/config/config.ts4
-rw-r--r--packages/web/src/content/docs/plugins.mdx32
2 files changed, 35 insertions, 1 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index 66f42e5a8..0132bb91d 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -191,6 +191,10 @@ export namespace Config {
cwd: dir,
},
).catch(() => {})
+
+ // Install any additional dependencies defined in the package.json
+ // This allows local plugins and custom tools to use external packages
+ await BunProc.run(["install"], { cwd: dir }).catch(() => {})
}
const COMMAND_GLOB = new Bun.Glob("command/**/*.md")
diff --git a/packages/web/src/content/docs/plugins.mdx b/packages/web/src/content/docs/plugins.mdx
index e806046c1..ef2f1338d 100644
--- a/packages/web/src/content/docs/plugins.mdx
+++ b/packages/web/src/content/docs/plugins.mdx
@@ -47,7 +47,7 @@ Browse available plugins in the [ecosystem](/docs/ecosystem#plugins).
**npm plugins** are installed automatically using Bun at startup. Packages and their dependencies are cached in `~/.cache/opencode/node_modules/`.
-**Local plugins** are loaded directly from the plugin directory. Dependencies are not installed automatically. If your local plugin requires external packages, publish it to npm instead and add it to your config.
+**Local plugins** are loaded directly from the plugin directory. To use external packages, you must create a `package.json` within your config directory (see [Dependencies](#dependencies)), or publish the plugin to npm and [add it to your config](/docs/config#plugins).
---
@@ -71,6 +71,36 @@ functions. Each function receives a context object and returns a hooks object.
---
+### Dependencies
+
+Local plugins and custom tools can use external npm packages. Add a `package.json` to your config directory with the dependencies you need.
+
+```json title=".opencode/package.json"
+{
+ "dependencies": {
+ "shescape": "^2.1.0"
+ }
+}
+```
+
+OpenCode runs `bun install` at startup to install these. Your plugins and tools can then import them.
+
+```ts title=".opencode/plugin/my-plugin.ts"
+import { escape } from "shescape"
+
+export const MyPlugin = async (ctx) => {
+ return {
+ "tool.execute.before": async (input, output) => {
+ if (input.tool === "bash") {
+ output.args.command = escape(output.args.command)
+ }
+ },
+ }
+}
+```
+
+---
+
### Basic structure
```js title=".opencode/plugin/example.js"