Skip to content

lib-memory-dir.sh's EXIT-trap cleanup leaks remember-config-*.json on Windows — 23,908 found in one %TEMP% #362

Closed

Description

@wayneseguin

Description

scripts/lib-memory-dir.sh writes a per-invocation merged-config file at $SYS_TMPDIR/remember-config-$$.json (line ~274) and relies solely on an EXIT trap (line ~336-344) to remove it. On Windows / Git Bash, that trap does not reliably fire for the short-lived hook processes this plugin spawns (user-prompt-hook.sh, post-tool-hook.sh, etc.), so the file is never cleaned up. Over time this leaves tens of thousands of stale remember-config-*.json files sitting directly in the OS temp directory.

Reproduction

  1. On Windows, use Claude Code with this plugin installed and Git Bash as the shell, for normal interactive sessions over several days (the hook fires on every tool call per post-tool-hook.sh: apply the #227 env-cache fast path to PostToolUse (~0.75-1.0 s per tool call on Windows) #350's description of post-tool-hook.sh).
  2. Watch $TEMP (C:\Users\<user>\AppData\Local\Temp) accumulate remember-config-<pid>.json files that are never removed.

Actual behavior

Observed on a live machine: 23,908 leaked remember-config-*.json files in %TEMP%, accumulating at roughly one every ~13 seconds during active use, with the oldest dated 12 days prior to observation. Each file is tiny ({}, ~2 bytes), so this isn't a disk-space problem, but the sheer directory-entry count (this alone was ~42% of ~57k total items in the user's %TEMP% root) makes any tool that enumerates that directory (Get-ChildItem, antivirus scans, backup software) measurably slower — a plain non-recursive Get-ChildItem $env:TEMP took multiple minutes and had to be killed.

Expected behavior

The merged-config temp file should be removed regardless of how the hook process's lifetime ends on Windows — i.e. cleanup shouldn't depend solely on a bash EXIT trap firing, since on this platform the hook process appears to often not exit through a path that runs it (most likely: the harness terminates/kills the short-lived hook process after collecting its output rather than letting it exit normally).

Notes / possible directions

  • Confirmed the same trap-only cleanup is still present on main (checked via the GitHub API against scripts/lib-memory-dir.sh), so this isn't fixed by picking up a newer release.
  • A defensive fix might pair the EXIT trap with an opportunistic sweep: on each new invocation, delete any remember-config-*.json in $SYS_TMPDIR whose mtime is older than some small threshold (e.g. a few minutes) before writing the new one. That bounds the leak regardless of why individual traps fail to fire, without needing to root-cause the Windows process-termination path.
  • Happy to test a fix against this machine if useful — the leak reproduces readily here.

Environment

  • claude-remember version: 0.7.3 (as cached under claude-plugins-official; confirmed same code path present on current main)
  • Claude Code version: 2.1.173
  • Shell: bash 5.3.15 (Git for Windows / MINGW64)
  • OS: Windows 10 Pro 10.0.19045

Activity

  1. self-assigned this
    on Aug 27, 2026
  2. fdaviddpt commented on Aug 27, 2026

    @fdaviddpt
    Contributor

    Thank you for this — and for the measurement. "23,908 files, ~42% of the temp root, oldest 12 days old, a non-recursive Get-ChildItem had to be killed" is what turned this from a theoretical trap-may-not-fire note into something with an obvious cost. Noting that the file itself is ~2 bytes so it isn't a disk problem, it's a directory-entry problem, aimed the fix correctly.

    Your suggested direction is what shipped in v0.22.0 (#371): the EXIT trap stays, paired with an opportunistic sweep of stale remember-config-*.json on each invocation, so the leak is bounded regardless of why an individual trap fails to fire — no need to root-cause the Windows termination path first. Fixing it also surfaced a path-normalization mismatch between resolve-paths.sh and bootstrap-dirs.sh on Windows separators, which is fixed as well.

    One follow-up worth flagging: the first cut of the sweep introduced a quoting bug in the trap path, filed and fixed as #375 before the release, so v0.22.0 is the version to take.

    If you do get a chance to check %TEMP% on that machine after a few days on v0.22.0, I'd be glad to hear the count held flat.


    Unrelated, but since you were digging through %TEMP% and hook internals anyway: two sibling plugins from the same shelf —

    • claude-supertool — batched file ops for autonomous runs; collapses N reads/greps/globs into one Bash round-trip, so fewer output tokens and less cache growth.
    • claude-jit-context — project rules and conventions matched against the prompt, the file being touched, or the tool being run, and injected just in time instead of sitting in context all session.

    Both are in the same marketplace: /plugin marketplace add Digital-Process-Tools/claude-marketplace. Both are shell-and-Windows-sensitive in the same ways this plugin is, so if you hit anything like #362 there, that report would be just as welcome.

  3. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions