Windows: per-hook start-token probe runs a WMI query on every tool call (use Get-Process instead)
Version: claude-mem 13.27.1, Windows 11, Claude Code 2.1.280 (desktop app, ~38 concurrent sessions)
What happens
src/shared/process-identity.ts reads a PID's start token on Windows with:
`(Get-CimInstance Win32_Process -Filter \"ProcessId=${pid}\").CreationDate.ToString('yyyyMMddHHmmss.ffffff')`The PostToolUse hook (worker-service.cjs hook claude-code observation) is a fresh process
on every tool call, so the 5s in-process cache never hits across calls. Each tool call in every
session spawns powershell.exe and issues one WMI query against the worker PID.
Measured with a process-spawn watcher (psutil, parent chains recorded):
- 527 of 701 WMI-client processes on the box over 11 minutes came from this probe (up to ~1.5/s during busy periods, several thousand WMI queries per hour)
- Median probe cost: 1,251 ms (CIM) vs 204 ms with
Get-Process - When the WMI provider host is throttled (event 5858, 0x80041032, memory quota), the
query outlives the
spawnSync5000 ms timeout, PowerShell is killed, and WMI logs0x800706BA "Could not send status to client"for each one
Proposed fix (drop-in, no WMI)
`(Get-Process -Id ${pid}).StartTime.ToString('yyyyMMddHHmmss.ffffff')`Process.StartTime is read from the same kernel creation time as CIM CreationDate, so the
token is byte-identical. Verified on a live worker PID: both methods returned
20260926101423.210916. A missing PID fails the same way as before (non-zero exit, so null).
One behavioural note: for a PID owned by another user, StartTime is not readable
without elevation, so the read returns null ("proceed") where CIM would have returned a
token. The only callers act on the current user's own worker, and a non-elevated
taskkill on another user's process fails anyway, so this does not widen what can be killed.
Applied locally to the four bundles that carry the probe (worker-service.cjs, mcp-server.cjs, server-service.cjs, transcript-watcher.cjs). Hooks and the worker kept running normally, the daemon was not respawned, and the WMI probe count from claude-mem went to zero.
Related (heavier, less frequent)
kill-process-tree.ts:423 and port-reclaim.ts:121 enumerate the whole process table via
Get-CimInstance Win32_Process (port-reclaim also pulls CommandLine, the most expensive
property). On a box with ~1,350 processes these are large WMI result sets. A single
Get-Process (plus CommandLine, which PowerShell 7 reads from the PEB without WMI) or
CreateToolhelp32Snapshot would avoid WmiPrvSE entirely.
Related: #3744 (PID reuse). This keeps the same start-token guard; only the way the token is read changes.
Source: thedotmack/claude-mem