github rohitg00/agentmemory v0.8.10
v0.8.10 — SessionStart gate (#143) + retention-evict semantic leak (#124)

latest release: v0.8.11
16 hours ago

Behavior change: the PreToolUse and SessionStart hooks no longer run enrichment by default. SessionStart saves 1-2K input tokens per session you start (the only path that was actually reaching the model, per the Claude Code hook docs). PreToolUse stops spawning a Node process and POSTing to `/agentmemory/enrich` on every file-touching tool call — a pure resource cleanup, not a token fix. If you were relying on either path, set `AGENTMEMORY_INJECT_CONTEXT=true` in `/.agentmemory/.env` and restart.

Fixed

#143 — Gate SessionStart context injection

`src/hooks/session-start.ts` previously wrote ~1-2K chars of project context to stdout at every session start. Per the Claude Code hook docs, `SessionStart` stdout is injected into the model's context (one of the two documented exceptions alongside `UserPromptSubmit`), so this was adding real tokens to the first turn of every new session. Now gated behind `AGENTMEMORY_INJECT_CONTEXT`, default off. The session still gets registered for observation tracking — only the stdout echo is skipped.

`src/hooks/pre-tool-use.ts` was POSTing `/agentmemory/enrich` on every `Edit`/`Write`/`Read`/`Glob`/`Grep` tool call and piping up to 4000 chars to stdout. The Claude Code docs make clear that PreToolUse stdout goes to the debug log, not the model context, so this was not burning user tokens — but it was spawning a Node process + full HTTP round-trip ~20x per user message with no effect on the conversation. Gating it makes the disabled hot path a ~15ms no-op Node startup instead of a ~100-300ms REST round-trip. Resource cleanup, not a token fix.

Honest note on #143: my initial diagnosis on the issue thread pattern-matched too quickly to #138 and overclaimed that PreToolUse stdout was the smoking gun behind "Claude Pro burned in 4 messages". It wasn't — per the docs, PreToolUse stdout is debug-log only. The actual background cause is that Claude Pro's Claude Code quotas are documented as tight and Anthropic has publicly confirmed "people are hitting usage limits in Claude Code way faster than expected." agentmemory contributes ~1-2K tokens per session via SessionStart, and that contribution is worth eliminating, but this release does not and cannot make Claude Pro's base quotas roomier. Users on heavy tool-call workloads should consider Max 5x or Team tiers regardless of whether agentmemory is installed. 0.8.8's #138 fix remains the correct fix for users with `ANTHROPIC_API_KEY` set.

#124 — mem::retention-evict no longer leaks semantic memories

The eviction loop was unconditionally calling `kv.delete(KV.memories, id)` for every below-threshold candidate, but retention scores are computed for both episodic (`KV.memories`) and semantic (`KV.semantic`) memories. When a candidate came from `KV.semantic`, the delete silently became a no-op and the semantic row stayed alive forever with a sub-threshold score. Semantic memories could not be evicted by this path at all.

Fix: new `source: "episodic" | "semantic"` discriminator on `RetentionScore`, tagged at score creation. The eviction loop branches on `candidate.source`. For pre-0.8.10 rows with no `source` field (including semantic retention rows written by the old scorer), the loop probes both namespaces to find where the `memoryId` actually lives, so upgraded stores get their stranded semantic memories evicted without needing to re-score first. Response now includes `evictedEpisodic` and `evictedSemantic` counts.

Added

  • `AGENTMEMORY_INJECT_CONTEXT` env var — default `false`. When `true`, restores the old SessionStart stdout write and the old PreToolUse `/enrich` round-trip. Startup banner prints a loud WARNING when it's on.
  • `isContextInjectionEnabled()` helper in `src/config.ts` — single source of truth for the flag.
  • Audit coverage for retention operations — both `mem::retention-score` (new `retention_score` operation) and `mem::retention-evict` (`delete` operation) now emit batched audit rows per sweep, making retention visible to audit consumers. Zero-eviction sweeps intentionally skip the evict audit row to avoid flooding.
  • Parallelized retention-score writes — the score loop now collects pending writes and flushes with `Promise.all`, turning O(n) sequential KV round-trips into O(1) wall time on backends that can pipeline.
  • 12 new regression tests across `test/context-injection.test.ts` (5 subprocess tests that spawn the compiled `pre-tool-use.mjs` and `session-start.mjs` hooks and assert stdout is empty in all off/default paths) and `test/retention.test.ts` (7 tests covering source tagging, mixed episodic+semantic eviction, legacy-row probing for both scopes, audit coverage for score and evict, zero-eviction skip audit).

Full suite: 731 passing (was 719 + 12 new).

Infrastructure

  • Startup banner now prints `Context injection: OFF (default, #143)` or a prominent WARNING when opt-in is enabled, so the mode is never silent.
  • README `.env` section has a new `AGENTMEMORY_INJECT_CONTEXT` entry with the note that only SessionStart actually reaches the model (PreToolUse stdout is debug-log only).

Migration

If you were relying on the old SessionStart project-context injection or the old PreToolUse enrichment round-trip, add to `~/.agentmemory/.env`:

```env
AGENTMEMORY_INJECT_CONTEXT=true
```

and restart Claude Code.

Upgrade

```bash
npm install @agentmemory/agentmemory@0.8.10

or standalone:

npx -y @agentmemory/mcp@0.8.10
```

Full changelog: v0.8.9...v0.8.10

Don't miss a new agentmemory release

NewReleases is sending notifications on new releases.