# Connect OpenCode to Repowise

Wire OpenCode to the local or hosted Repowise MCP server and AGENTS.md, see which files change, verify the connection and remove it.

OpenCode registers MCP servers under its own `mcp` key and reads `AGENTS.md`
for instructions. Repowise writes both, at project and user scope.

## Install

**Local, with your agent.** Paste this into OpenCode:

```text
Read https://docs.repowise.dev/setup.md and set up Repowise in this repository.
```

**Local, by hand.** `repowise init` wires OpenCode when it is installed. To
wire it later:

```bash
repowise agents add --target=opencode
```

The default writes the project pair and the user pair. Pass
`--scope=project` or `--scope=user` for one.

**Hosted.** Run in the repository, then sign in:

```bash
repowise agents add --target=opencode --hosted
opencode mcp auth repowise
```

## What gets written where

| File | Scope | What repowise writes |
|---|---|---|
| `opencode.jsonc` | project | `mcp.repowise`: `{"type": "local", "command": ["repowise", "mcp", ...]}` |
| `AGENTS.md` | project | The managed Repowise block, shared with Codex and Hermes |
| `~/.config/opencode/opencode.jsonc` | user | The same server entry |
| `~/.config/opencode/AGENTS.md` | user | The managed block |

The user directory is `$XDG_CONFIG_HOME/opencode` when that is set, else
`~/.config/opencode`, on Windows too: OpenCode does not read `%APPDATA%`. An
existing `opencode.json` is updated in place. `command` is one array holding
the binary and its arguments, unlike the `command` plus `args` shape other
hosts use. The hosted entry is `"type": "remote"` with a `url`, named
`repowise-hosted` when a local `repowise` exists.

## Restart

Quit and start OpenCode again in the repository. For a hosted entry, run
`opencode mcp auth repowise` (or `repowise-hosted`) and approve Repowise in
the browser.

## Verify

```bash
opencode mcp list
repowise agents
```

You should see `repowise` in OpenCode's list and `opencode` with status
`configured`.

## Uninstall

```bash
repowise agents remove --target=opencode
```

This removes the `repowise` entry and the managed `AGENTS.md` block, keeping
your own content and other servers. The block stays while Codex or Hermes
still uses it.

## Troubleshooting

| Symptom | Fix |
|---|---|
| `opencode.jsonc left unchanged` | OpenCode accepts comments in this file and repowise does not rewrite one it cannot parse as strict JSON. Run `repowise agents print-config opencode` and paste the entry under `mcp`. |
| The user entry never loads on Windows | Check it is in `~/.config/opencode`, not `%APPDATA%\opencode`. |
| `AGENTS.md left unchanged` | Its Repowise markers are unpaired or duplicated. Fix them by hand and re-run. |
| Only five Repowise tools are listed | OpenCode gets the core profile by default. See [Tool profiles](https://docs.repowise.dev/agents/tool-profiles). |

## Next
- [Codex](https://docs.repowise.dev/agents/codex), which shares `AGENTS.md`.
- [Tool profiles](https://docs.repowise.dev/agents/tool-profiles) to list all ten tools.
- [repowise agents](https://docs.repowise.dev/cli/agents) for every flag.
