Skip to content

Commit 3355edd

Browse files
glommerclaude
andcommitted
cachebro: add init command for zero-config setup
`npx cachebro init` auto-detects Claude Code, Cursor, and Windsurf, and adds the MCP server config. Idempotent — safe to run multiple times. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 38c675a commit 3355edd

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

README.md

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

5050
```bash
51-
npx cachebro serve # just works, no install needed
51+
npx cachebro init # auto-configures Claude Code, Cursor, Windsurf
5252
```
5353

54-
Or install globally:
54+
That's it. Restart your editor and cachebro is active. Agents discover it automatically.
5555

56-
```bash
57-
npm install -g cachebro
56+
Or configure manually — add to your MCP config (`.claude.json`, `.cursor/mcp.json`, etc.):
57+
58+
```json
59+
{
60+
"mcpServers": {
61+
"cachebro": {
62+
"command": "npx",
63+
"args": ["cachebro", "serve"]
64+
}
65+
}
66+
}
5867
```
5968

6069
## Usage

bun.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/index.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,72 @@ if (!command || command === "serve") {
2727
console.log(` Tokens saved (total): ~${stats.tokensSaved.toLocaleString()}`);
2828

2929
await cache.close();
30+
} else if (command === "init") {
31+
const { existsSync, readFileSync, writeFileSync, mkdirSync } = await import("fs");
32+
const { join } = await import("path");
33+
const { homedir } = await import("os");
34+
35+
const home = homedir();
36+
const mcpEntry = {
37+
command: "npx",
38+
args: ["cachebro", "serve"],
39+
};
40+
41+
const targets = [
42+
{
43+
name: "Claude Code",
44+
path: join(home, ".claude.json"),
45+
},
46+
{
47+
name: "Cursor",
48+
path: join(home, ".cursor", "mcp.json"),
49+
},
50+
{
51+
name: "Windsurf",
52+
path: join(home, ".codeium", "windsurf", "mcp_config.json"),
53+
},
54+
];
55+
56+
let configured = 0;
57+
58+
for (const target of targets) {
59+
// Only configure tools that are already installed (config dir exists)
60+
const dir = join(target.path, "..");
61+
if (!existsSync(dir)) continue;
62+
63+
let config: any = {};
64+
if (existsSync(target.path)) {
65+
try {
66+
config = JSON.parse(readFileSync(target.path, "utf-8"));
67+
} catch {
68+
config = {};
69+
}
70+
}
71+
72+
if (config.mcpServers?.cachebro) {
73+
console.log(` ${target.name}: already configured`);
74+
configured++;
75+
continue;
76+
}
77+
78+
config.mcpServers = config.mcpServers ?? {};
79+
config.mcpServers.cachebro = mcpEntry;
80+
writeFileSync(target.path, JSON.stringify(config, null, 2) + "\n");
81+
console.log(` ${target.name}: configured (${target.path})`);
82+
configured++;
83+
}
84+
85+
if (configured === 0) {
86+
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));
88+
} else {
89+
console.log(`\nDone! Restart your editor to pick up cachebro.`);
90+
}
3091
} else if (command === "help" || command === "--help") {
3192
console.log(`cachebro - Agent file cache with diff tracking
3293
3394
Usage:
95+
cachebro init Auto-configure cachebro for your editor
3496
cachebro serve Start the MCP server (default)
3597
cachebro status Show cache statistics
3698
cachebro help Show this help message

0 commit comments

Comments
 (0)