Stats path opens every session DB (not read-only), causing sustained fsevents/AV load on macOS

Author: flowq-CCreated Sep 27, 2026Updated Sep 27, 2026

Version: context-mode 1.0.169 (Claude Code plugin, autoUpdate on), macOS (Apple Silicon), ~13 concurrent Claude Code sessions.

Related: #949 (sessions/ has no retention). This issue is about something different: even if the session DBs are kept, reading stats should not write to all of them.

Observed

sudo fs_usage -w -f filesys -t 60 BDLDaemon mdworker_shared fseventsd over 60 s:

Process FS ops / 60 s Main path
fseventsd 334,394 ~/.claude/context-mode/sessions (310,152)
endpoint AV daemon (Bitdefender BDLDaemon) 201,838 ~/.claude/context-mode (149,168 stat/getattrlist)
node (context-mode) 39,078 19,225 WrData into sessions/*.db-wal / *.db-shm
  • node wrote into 1,437 distinct session DBs within those 60 s, while only ~13 sessions were active.
  • sessions/ holds 5,989 files / 1.6 GB, 1,363 *.db; 652 of them older than 14 days, oldest from 2026-05-11 (consistent with #949).
  • Side effect: the AV menu-bar icon shows "Scanning" ~90 % of the time and the AV daemon peaks at 65 % CPU, although the directory is excluded (exclusion suppresses content scans, not per-event attribute lookups).

Code locations (1.0.169, server.bundle.mjs, minified line numbers)

  • :592 $u(t) (real-bytes stats): enumerates sessionsDir, keeps every *.db unless a worktreeHash is passed, and opens each one. Opening a WAL-mode DB writes -wal/-shm, so every call touches every file and emits fsevents for all of them.
  • bin/statusline.mjs:269: comment "Statusline doesn't know the worktree hash, so scan every db in the dir".

Suggestion (keeps all data)

  1. Open DBs for stats read-only (mode=ro / immutable=1), or use stat() file sizes instead of opening them.
  2. Scope stats to the current session/worktree by default.
  3. Cache aggregate cross-session stats with a TTL instead of recomputing per call.

Not verified

Which call site triggers the all-DB loop per turn (server init is confirmed; per-turn trigger not isolated by PID).