Skip to content

Commit 5a1529f

Browse files
glommerclaude
andcommitted
cachebro: add OpenCode support to init command
OpenCode uses a different MCP config format: `mcp` key (not `mcpServers`), `command` as a single array, and `type: "local"`. Config lives at ~/.config/opencode/opencode.json (XDG). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3355edd commit 5a1529f

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The cache persists in a local [Turso](https://turso.tech) (SQLite-compatible) da
4848
## Installation
4949

5050
```bash
51-
npx cachebro init # auto-configures Claude Code, Cursor, Windsurf
51+
npx cachebro init # auto-configures Claude Code, Cursor, Windsurf, OpenCode
5252
```
5353

5454
That's it. Restart your editor and cachebro is active. Agents discover it automatically.

packages/cli/src/index.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,45 @@ if (!command || command === "serve") {
3333
const { homedir } = await import("os");
3434

3535
const home = homedir();
36-
const mcpEntry = {
36+
37+
// mcpServers format (Claude Code, Cursor, Windsurf)
38+
const mcpServersEntry = {
3739
command: "npx",
3840
args: ["cachebro", "serve"],
3941
};
4042

43+
// opencode format (mcp key, command is a single array)
44+
const opencodeMcpEntry = {
45+
type: "local" as const,
46+
command: ["npx", "cachebro", "serve"],
47+
};
48+
49+
const xdgConfig = process.env.XDG_CONFIG_HOME || join(home, ".config");
50+
4151
const targets = [
4252
{
4353
name: "Claude Code",
4454
path: join(home, ".claude.json"),
55+
key: "mcpServers",
56+
entry: mcpServersEntry,
4557
},
4658
{
4759
name: "Cursor",
4860
path: join(home, ".cursor", "mcp.json"),
61+
key: "mcpServers",
62+
entry: mcpServersEntry,
4963
},
5064
{
5165
name: "Windsurf",
5266
path: join(home, ".codeium", "windsurf", "mcp_config.json"),
67+
key: "mcpServers",
68+
entry: mcpServersEntry,
69+
},
70+
{
71+
name: "OpenCode",
72+
path: join(xdgConfig, "opencode", "opencode.json"),
73+
key: "mcp",
74+
entry: opencodeMcpEntry,
5375
},
5476
];
5577

@@ -69,22 +91,22 @@ if (!command || command === "serve") {
6991
}
7092
}
7193

72-
if (config.mcpServers?.cachebro) {
94+
if (config[target.key]?.cachebro) {
7395
console.log(` ${target.name}: already configured`);
7496
configured++;
7597
continue;
7698
}
7799

78-
config.mcpServers = config.mcpServers ?? {};
79-
config.mcpServers.cachebro = mcpEntry;
100+
config[target.key] = config[target.key] ?? {};
101+
config[target.key].cachebro = target.entry;
80102
writeFileSync(target.path, JSON.stringify(config, null, 2) + "\n");
81103
console.log(` ${target.name}: configured (${target.path})`);
82104
configured++;
83105
}
84106

85107
if (configured === 0) {
86108
console.log("No supported tools detected. You can manually add cachebro to your MCP config:");
87-
console.log(JSON.stringify({ mcpServers: { cachebro: mcpEntry } }, null, 2));
109+
console.log(JSON.stringify({ mcpServers: { cachebro: mcpServersEntry } }, null, 2));
88110
} else {
89111
console.log(`\nDone! Restart your editor to pick up cachebro.`);
90112
}

0 commit comments

Comments
 (0)