Repository navigation
Expand file tree
/
Copy pathuninstall.mjs
More file actions
40 lines (34 loc) · 1.62 KB
/
Copy pathuninstall.mjs
File metadata and controls
40 lines (34 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
// Removes the SessionEnd hook from Claude Code's settings.
// node uninstall.mjs [--config-dir <path>] [--keep-script]
import { copyFileSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join, resolve } from "node:path";
const MARKER = "paseo-session-sync";
const args = process.argv.slice(2);
const configDirArg = args.indexOf("--config-dir");
const configDir = resolve(
configDirArg !== -1 ? args[configDirArg + 1] : process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"),
);
const settingsPath = join(configDir, "settings.json");
if (!existsSync(settingsPath)) {
console.log(`Nothing to do: ${settingsPath} does not exist.`);
process.exit(0);
}
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
const before = settings.hooks?.SessionEnd?.length ?? 0;
if (settings.hooks?.SessionEnd) {
settings.hooks.SessionEnd = settings.hooks.SessionEnd.filter(
(entry) => !(entry.hooks ?? []).some((h) => String(h.command ?? "").includes(MARKER)),
);
if (settings.hooks.SessionEnd.length === 0) delete settings.hooks.SessionEnd;
}
const after = settings.hooks?.SessionEnd?.length ?? 0;
copyFileSync(settingsPath, `${settingsPath}.bak-paseo-import`);
writeFileSync(settingsPath, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
if (!args.includes("--keep-script")) {
const hook = join(configDir, "hooks", "paseo-session-sync.mjs");
if (existsSync(hook)) rmSync(hook);
}
console.log(`Removed ${before - after} hook entr${before - after === 1 ? "y" : "ies"} from ${settingsPath}.`);
console.log("Agents already in Paseo are untouched.");