Clean up old plugin versions from cache after auto-update#48
Clean up old plugin versions from cache after auto-update#48
Conversation
|
Claude finished @kaghni's task in 3m 37s —— View job Review
The Claude Code path ( |
src/hooks/codex/session-start.ts
Outdated
| // Clean up old cached versions | ||
| try { | ||
| const cacheBase = join(homedir(), ".codex", "plugins", "cache"); | ||
| const hivemindDirs = execSync(`find "${cacheBase}" -maxdepth 3 -name "hivemind" -type d 2>/dev/null`, { encoding: "utf-8" }).trim().split("\n").filter(Boolean); | ||
| for (const hDir of hivemindDirs) { | ||
| const entries = readdirSync(hDir, { withFileTypes: true }); | ||
| for (const e of entries) { | ||
| if (e.isDirectory() && e.name !== latest) { | ||
| rmSync(join(hDir, e.name), { recursive: true, force: true }); | ||
| log(`cache cleanup: removed old version ${e.name}`); | ||
| } | ||
| } | ||
| } | ||
| } catch (e: any) { | ||
| log(`cache cleanup failed: ${e.message}`); | ||
| } |
There was a problem hiding this comment.
The Codex update copies files in-place into the existing version directory (which keeps its old name, e.g. "0.6.22"), so e.name !== latest ("0.6.22" !== "0.6.23") is always true — this block will delete the freshly-updated plugin on every successful auto-update, leaving the cache empty. Additionally, findCmd always exits 0 (the final rm -rf "$TMPDIR" succeeds even when git clone fails), so execSync(findCmd) never throws and this cleanup can also wipe existing plugin dirs when the update silently failed.
Remove this cleanup block for Codex — the in-place copy strategy never creates a new versioned directory, so there is nothing stale to remove.
| // Clean up old cached versions | |
| try { | |
| const cacheBase = join(homedir(), ".codex", "plugins", "cache"); | |
| const hivemindDirs = execSync(`find "${cacheBase}" -maxdepth 3 -name "hivemind" -type d 2>/dev/null`, { encoding: "utf-8" }).trim().split("\n").filter(Boolean); | |
| for (const hDir of hivemindDirs) { | |
| const entries = readdirSync(hDir, { withFileTypes: true }); | |
| for (const e of entries) { | |
| if (e.isDirectory() && e.name !== latest) { | |
| rmSync(join(hDir, e.name), { recursive: true, force: true }); | |
| log(`cache cleanup: removed old version ${e.name}`); | |
| } | |
| } | |
| } | |
| } catch (e: any) { | |
| log(`cache cleanup failed: ${e.message}`); | |
| } | |
| // Codex update is in-place (files copied into the existing versioned dir); | |
| // no stale version directories are created, so no cache cleanup is needed. |
After a successful auto-update, remove all cached version directories except the newly installed one. Prevents unbounded cache growth at ~/.claude/plugins/cache/hivemind/hivemind/ and ~/.codex/plugins/cache/.../hivemind/.
The Codex update uses find to dynamically locate the hivemind cache directory. The cleanup should match that approach instead of hardcoding the path.
Add || true to each scope's update command so a failure in one scope (e.g. managed) doesn't abort the entire update and skip cache cleanup.
Codex update does cp -r into the same directory (no versioned subdirectories), so there are no old versions to clean up.
f69e7c4 to
3dd49bc
Compare
Summary
~/.claude/plugins/cache/hivemind/hivemind/) and Codex (~/.codex/plugins/cache/.../hivemind/) cachesTest plan