# opencode-lazy

[![npm](https://img.shields.io/npm/v/opencode-lazy)](https://www.npmjs.com/package/opencode-lazy)
[![CI](https://github.com/griffinmartin/opencode-lazy/actions/workflows/ci.yml/badge.svg)](https://github.com/griffinmartin/opencode-lazy/actions/workflows/ci.yml)
[![Socket Badge](https://socket.dev/api/badge/npm/package/opencode-lazy)](https://socket.dev/npm/package/opencode-lazy)

Plugin manager for OpenCode. Search, install, and manage plugins without leaving your session.

Inspired by [lazy.nvim](https://github.com/folke/lazy.nvim) — you should never have to leave your editor to manage plugins.

## How it works

The plugin registers a `/plugin` slash command and four tools via OpenCode's plugin hooks. When you run a command, the LLM calls the appropriate tool, which hits the npm registry and modifies your `opencode.json` directly. Config modifications use `jsonc-parser` to preserve any comments in your config files.

## Installation

```bash
npm install -g opencode-lazy
```

Then add to the `plugin` array in your `opencode.json`:

```json
{
  "plugin": ["opencode-lazy"]
}
```

## Usage

```
/plugin search <query>     Search npm for OpenCode plugins
/plugin install <name>     Add a plugin to your config
/plugin list               Show all installed plugins
/plugin remove <name>      Remove a plugin from your config
```

### Search for plugins

```
/plugin search auth
```

Searches the npm registry for packages prefixed with `opencode-` and returns matching results with name, version, and description. Supports scoped packages (`@org/opencode-*`).

### Install a plugin

```
/plugin install opencode-wakatime
```

Validates the package on npm, adds it to your `opencode.json` plugin array. Restart OpenCode to activate.

By default, plugins are added to the global config (`~/.config/opencode/opencode.json`). The LLM can also install to the project config if you ask.

### List installed plugins

```
/plugin list
```

Shows all plugins from both global and project configs.

### Remove a plugin

```
/plugin remove opencode-wakatime
```

Removes the plugin from your config. Restart OpenCode to apply.

## How it works (technical)

- Registers a `/plugin` command via the `config` hook at startup
- Registers four tools via the `tool` hook (`plugin_search`, `plugin_install`, `plugin_list`, `plugin_remove`)
- Searches npm using the public registry API (`registry.npmjs.org/-/v1/search`)
- Filters results to packages prefixed with `opencode-` or tagged with `opencode-plugin`
- Modifies `opencode.json` using `jsonc-parser` to preserve comments and formatting
- Supports both global (`~/.config/opencode/`) and project-level configs

## Limitations

- **Restart required** after install/remove — OpenCode doesn't support hot-reloading plugins
- **Token cost** — Each `/plugin` command uses a small number of tokens since the LLM is in the loop
- **No version pinning** — Always installs the latest version from npm

## Disclaimer

This project is not built by the OpenCode team and is not affiliated with [OpenCode](https://github.com/anomalyco/opencode) in any way.

## License

MIT
