thedotmack/claude-mem · warning

[uninstall] Could not read ${npxRoot}:

Error message

[uninstall] Could not read ${npxRoot}:

What it means

removeStrayClaudeMemPaths() lists ~/.npm/_npx with readdirSync to find hashed npx cache directories that contain a claude-mem copy. If the readdir fails, it warns with hashDirs left empty, so the whole npx-cache sweep is skipped and stray claude-mem copies under _npx survive the uninstall.

Source

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

    }
  }

  if (dirty) {
    writeJsonFileAtomic(claudeSettingsPath(), settings);
  }
}

function removeStrayClaudeMemPaths(): number {
  const home = homedir();
  let removedCount = 0;

  const npxRoot = join(home, '.npm', '_npx');
  if (existsSync(npxRoot)) {
    let hashDirs: string[] = [];
    try {
      hashDirs = readdirSync(npxRoot);
    } catch (error: unknown) {
      console.warn(`[uninstall] Could not read ${npxRoot}:`, error instanceof Error ? error.message : String(error));
    }
    for (const hashDir of hashDirs) {
      const candidate = join(npxRoot, hashDir, 'node_modules', 'claude-mem');
      if (!existsSync(candidate)) continue;
      try {
        rmSync(candidate, { recursive: true, force: true });
        removedCount++;
      } catch (error: unknown) {
        console.warn(`[uninstall] Could not remove ${candidate}:`, error instanceof Error ? error.message : String(error));
      }
    }
  }

  const cacheRoot = join(home, '.cache', 'claude-cli-nodejs');
  if (existsSync(cacheRoot)) {
    let projectDirs: string[] = [];
    try {
      projectDirs = readdirSync(cacheRoot);

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Run sudo chown -R $(whoami) ~/.npm, then re-run `npx claude-mem uninstall`
  2. Or sweep manually: rm -rf ~/.npm/_npx/*/node_modules/claude-mem
  3. Or remove the npx cache wholesale (npm recreates it): rm -rf ~/.npm/_npx
Defensive patterns

Strategy: validation

Validate before calling

import { accessSync, constants } from 'node:fs';
const npxRoot = `${process.env.HOME}/.npm/_npx`;
try { accessSync(npxRoot, constants.R_OK); }
catch { /* run: sudo chown -R $(whoami) ~/.npm — or the npx sweep is skipped */ }

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` when ~/.npm/_npx is unreadable, most commonly root-owned after any historical sudo npm/npx usage, or when the directory is deleted while uninstall runs.

Common situations: Past `sudo npm install -g` runs leaving root-owned ~/.npm content; permission resets; parallel npm operations changing the directory mid-sweep.

Related errors


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