{"record":{"id":"1dc674a514a53292","repo":"thedotmack/claude-mem","slug":"uninstall-could-not-rewrite-filepath","errorCode":null,"errorMessage":"[uninstall] Could not rewrite ${filePath}:","messagePattern":"\\[uninstall\\] Could not rewrite (.+?):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/npx-cli/commands/uninstall.ts","lineNumber":127,"sourceCode":"  const aliasLineRegex = /^\\s*alias\\s+claude-mem\\s*=/;\n\n  for (const filePath of candidateFiles) {\n    if (!existsSync(filePath)) continue;\n    let content: string;\n    try {\n      content = readFileSync(filePath, 'utf-8');\n    } catch (error: unknown) {\n      console.warn(`[uninstall] Could not read ${filePath}:`, error instanceof Error ? error.message : String(error));\n      continue;\n    }\n    const lines = content.split('\\n');\n    const filtered = lines.filter((line) => !aliasLineRegex.test(line));\n    if (filtered.length === lines.length) continue; \n    try {\n      writeFileSync(filePath, filtered.join('\\n'));\n      console.error(`Removed legacy claude-mem alias from ${filePath}`);\n    } catch (error: unknown) {\n      console.warn(`[uninstall] Could not rewrite ${filePath}:`, error instanceof Error ? error.message : String(error));\n    }\n  }\n}\n\nexport function removeFromClaudeSettings(): void {\n  const settings = readJsonSafe<Record<string, any>>(claudeSettingsPath(), {});\n  let dirty = false;\n\n  if (settings.enabledPlugins?.['claude-mem@thedotmack'] !== undefined) {\n    delete settings.enabledPlugins['claude-mem@thedotmack'];\n    dirty = true;\n  }\n\n  // Symmetric counterpart to disableClaudeAutoMemory() in install.ts. The\n  // installer sets env.CLAUDE_CODE_DISABLE_AUTO_MEMORY = \"1\" to suppress\n  // Claude Code's built-in auto-memory; on uninstall we restore the host\n  // CLI's default behavior by removing that key. The value-equality guard\n  // (=== '1') ensures we only strip the specific token the installer wrote","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/npx-cli/commands/uninstall.ts#L109-L145","documentation":"After filtering out claude-mem alias lines, uninstall rewrites the rc file with writeFileSync (non-atomic, truncate-then-write). If the write throws, it warns and moves on, so the alias line stays. Because the write truncates first, a hard failure mid-write could leave the rc file partially written, so keep a backup of rc files before uninstalling.","triggerScenarios":"`npx claude-mem uninstall` rewrites ~/.bashrc or ~/.zshrc while the file is read-only, the filesystem is full, or another process (editor auto-save, sync client, indexer) interferes with the write.","commonSituations":"Read-only rc files; ENOSPC; files locked on Windows; heavily synced dotfiles where the sync client holds a lock during the rewrite.","solutions":["Run chmod u+w (and chown if needed) on the file from the message, then re-run uninstall","Free disk space if the failure was ENOSPC","Remove the `alias claude-mem =` line manually and restore the rc file from your dotfiles backup if it looks truncated"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'node:fs';\nconst rc = `${process.env.HOME}/.bashrc`;\ntry { accessSync(rc, constants.W_OK); }\ncatch { /* make it writable or remove the alias line yourself before uninstall */ }","typeGuard":"function isErrnoException(error: unknown): error is NodeJS.ErrnoException {\n  return error instanceof Error && typeof (error as NodeJS.ErrnoException).code === 'string';\n}","tryCatchPattern":null,"preventionTips":["Back up shell rc files before uninstalling: the rewrite is non-atomic truncate-then-write","Ensure rc files are writable (chmod u+w) and not locked by sync clients","Prefer removing the claude-mem alias manually when the file is managed by a dotfile tool"],"tags":["uninstall","shell-config","alias","file-write"],"backgroundTag":"file-write-permission-denied","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}