Skip to content

Windows: claudemem auto-reindex spawns visible cmd.exe window on every file edit #14

Description

@mann1x

Bug

On Windows, the code-analysis plugin's handleAutoReindex in hooks/handler.ts spawns a visible cmd.exe console window every time a code file is written or edited. The window flashes in the foreground showing "Indexing C:\Users...\project..." and steals focus.

Root cause

claudemem is installed globally via npm, which creates a .cmd batch file wrapper (%APPDATA%\Roaming\npm\claudemem.cmd). On Windows, .cmd/.bat files always open a visible cmd.exe console window — Node's windowsHide: true flag is ignored because it only applies to .exe binaries.

This affects two call sites in hooks/handler.ts:

  1. handleAutoReindex (background spawn) — the most visible, fires on every Write/Edit of a code file:

    const child = spawn("claudemem", ["index", "--quiet"], {
      cwd: input.cwd,
      detached: true,
      stdio: "ignore",
      windowsHide: true,  // ← has no effect on .cmd files
    });
  2. runCommand (sync calls) — used for claudemem status and claudemem --version on SessionStart:

    const result = spawnSync(cmd, args, {
      cwd,
      encoding: "utf-8",
      timeout: 10000,
      windowsHide: true,  // ← same issue
    });

Suggested fix

On Windows, resolve claudemem to bun.exe + the actual JS entry point directly, bypassing the .cmd wrapper. The .cmd file itself reveals the path:

"%_prog%" "%dp0%\node_modules\mnemex\dist\index.js" %*

For the background spawn:

const claudememJs = join(
  process.env.APPDATA || "",
  "npm", "node_modules", "mnemex", "dist", "index.js"
);
const bunExe = existsSync(join(process.env.USERPROFILE || "", ".bun", "bin", "bun.exe"))
  ? join(process.env.USERPROFILE || "", ".bun", "bin", "bun.exe")
  : "bun";
const cmd = existsSync(claudememJs) ? bunExe : "claudemem";
const args = existsSync(claudememJs)
  ? [claudememJs, "index", "--quiet"]
  : ["index", "--quiet"];

const child = spawn(cmd, args, {
  cwd: input.cwd,
  detached: true,
  stdio: "ignore",
  windowsHide: true,  // now works because bun.exe is a real .exe
});

Same pattern for runCommand — detect Windows + claudemem command and redirect to bun + JS entry point.

Environment

  • Windows 11, Claude Code CLI
  • code-analysis plugin v3.2.2
  • mnemex installed globally via npm install -g mnemex
  • bun available at C:\Users\<user>\.bun\bin\bun.exe

Notes

This is a general Windows gotcha for any npm-installed CLI tool invoked via spawn/spawnSync — the .cmd wrapper will always flash a window. The same pattern applies to any future tools the plugin might spawn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions