thedotmack/claude-mem · warning

[uninstall] Could not rewrite ${filePath}:

Error message

[uninstall] Could not rewrite ${filePath}:

What it means

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.

Source

Thrown at src/npx-cli/commands/uninstall.ts:127

  const aliasLineRegex = /^\s*alias\s+claude-mem\s*=/;

  for (const filePath of candidateFiles) {
    if (!existsSync(filePath)) continue;
    let content: string;
    try {
      content = readFileSync(filePath, 'utf-8');
    } catch (error: unknown) {
      console.warn(`[uninstall] Could not read ${filePath}:`, error instanceof Error ? error.message : String(error));
      continue;
    }
    const lines = content.split('\n');
    const filtered = lines.filter((line) => !aliasLineRegex.test(line));
    if (filtered.length === lines.length) continue; 
    try {
      writeFileSync(filePath, filtered.join('\n'));
      console.error(`Removed legacy claude-mem alias from ${filePath}`);
    } catch (error: unknown) {
      console.warn(`[uninstall] Could not rewrite ${filePath}:`, error instanceof Error ? error.message : String(error));
    }
  }
}

export function removeFromClaudeSettings(): void {
  const settings = readJsonSafe<Record<string, any>>(claudeSettingsPath(), {});
  let dirty = false;

  if (settings.enabledPlugins?.['claude-mem@thedotmack'] !== undefined) {
    delete settings.enabledPlugins['claude-mem@thedotmack'];
    dirty = true;
  }

  // Symmetric counterpart to disableClaudeAutoMemory() in install.ts. The
  // installer sets env.CLAUDE_CODE_DISABLE_AUTO_MEMORY = "1" to suppress
  // Claude Code's built-in auto-memory; on uninstall we restore the host
  // CLI's default behavior by removing that key. The value-equality guard
  // (=== '1') ensures we only strip the specific token the installer wrote

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Run chmod u+w (and chown if needed) on the file from the message, then re-run uninstall
  2. Free disk space if the failure was ENOSPC
  3. Remove the `alias claude-mem =` line manually and restore the rc file from your dotfiles backup if it looks truncated
Defensive patterns

Strategy: validation

Validate before calling

import { accessSync, constants } from 'node:fs';
const rc = `${process.env.HOME}/.bashrc`;
try { accessSync(rc, constants.W_OK); }
catch { /* make it writable or remove the alias line yourself before uninstall */ }

Type guard

function isErrnoException(error: unknown): error is NodeJS.ErrnoException {
  return error instanceof Error && typeof (error as NodeJS.ErrnoException).code === 'string';
}

Prevention

When it happens

Trigger: `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.

Common situations: Read-only rc files; ENOSPC; files locked on Windows; heavily synced dotfiles where the sync client holds a lock during the rewrite.

Related errors


AI-assisted analysis of thedotmack/claude-mem@e2d1df569a (2026-08-20). Data as JSON: /api/errors/1dc674a514a53292. Report an issue: GitHub.