hindsight icon indicating copy to clipboard operation
hindsight copied to clipboard

Feature request(claude-code): exclude certain tool/command patterns from triggering retain

Open ChampPABA opened this issue 5 months ago • 2 comments

Running into a burst problem with tool-heavy sessions. I use a knowledge graph tool (graphify) that scans ~500+ files to build a dependency graph. During that session, the Stop hook fires frequently — and with retainEveryNTurns: 1, each stop queues a retain, which then queues a consolidation. End result: ~50 concurrent retain_extract_facts LLM calls in a few minutes, rate limit hit, consolidation worker stuck for 10+ minutes.

The retain mission already says "IGNORE bulk file scanning sessions" but that only reduces what gets stored, not how many LLM calls happen. The Mistral calls still fire, hit rate limits, and back up the consolidation queue.

What I'd find useful: a way to tell the hook "if this session looks like X, skip retain entirely." Something like:

  • A retainExcludePatterns config in claude-code.json that matches against the session content or cwd
  • Or an env var / hook-level skip mechanism the client can set before running a known-noisy command

The workaround I'm using now is bumping retainEveryNTurns to 5, which helps, but doesn't fully address sessions where a single graphify run spans the whole conversation.

Not a blocker since I have the workaround, but wanted to flag the pattern in case others hit it. Happy to dig into the hook internals if it helps scope a solution.

ChampPABA avatar Jun 11 '26 15:06 ChampPABA

Closing after re-measuring this against the Coding Agents plugin, which supersedes the per-agent claude-code plugin. The mechanism you described is still there, but the thing that made it hurt is not.

What still holds. Claude Code's Stop fires after every assistant response, not at session end, so a write-back is queued per response. Across 40 substantial real sessions: 66% of retained turns are tool actions, and 1,924 of 2,503 write-backs (77%) contain no user turn at all — the agent working on its own, exactly the shape your graphify run produced.

What changed. In the old plugin each of those re-sent the entire conversation and the server re-extracted it, which is how a tool-heavy session became ~50 concurrent retain_extract_facts calls. The plugin now tracks a per-session cursor and appends only the turns added since the last confirmed write, and the server's delta chunk-hashing extracts just that chunk. The burst is bounded by new content rather than by session size — the part that actually scaled badly.

Why not retainExcludePatterns as filed. It's a new config surface on a plugin that deliberately has almost none, and it's blunt — matching on cwd or session text to decide whether a session is worth remembering. I also checked whether there was a cleaner content-based rule available (skip write-backs that are purely mechanical) and there isn't: the agent narrates, so effectively every delta carries assistant prose. There is no tool-only delta to filter.

If it does still bite, the lever already exists. retainEveryTurns is honoured by the persistent-plugin harnesses (opencode, Kilo, Cline CLI) but not by the hook harnesses, because the host decides when those run and each Stop is a fresh process. Extending it to them is now feasible — the cursor is file-backed, so "turns written so far" already survives between processes — and with the cursor it would be lossless batching rather than dropped content. It needs a session-end flush first (Claude Code has a SessionEnd hook we don't currently wire), or the tail of every session would go unwritten.

That gap was undocumented until just now, which is the trap you'd have hit: bumping retainEveryTurns on Claude Code was a silent no-op. #3380 fixes the docs.

So: closing as not applicable in its filed form. If you see the burst on the new plugin, please open a fresh report with the numbers and I'll take the cadence route rather than pattern matching. Migrate with npx @vectorize-io/hindsight-coding-agents install claude-code (https://hindsight.vectorize.io/sdks/integrations/coding-agents).

nicoloboschi avatar Aug 11 '26 10:08 nicoloboschi

Correction to what I wrote when closing this.

I said that if the burst ever bit again on Coding Agents, the lever would be retainEveryTurns — extend the write-back cadence to the hook harnesses. That advice is now wrong twice over.

The cadence needed a flush that cannot exist. #2869 measured zero SessionEnd retains across 36 hours, because Claude Code cancels that hook at shutdown. A cadence on the hook harnesses would have stranded the tail of every session that ended below the threshold, with no event available to rescue it.

The batching moved server-side, where it is safe. Queued retains for one document now fold into a single execution (engine.retain.fold, #3395), on top of a claim predicate that serialises same-document work — so submitting every turn costs one extraction over the concatenated turns rather than one per turn. That is the burst control this issue asked for, done where a client closing cannot lose anything.

So retainEveryTurns has been removed outright (#3415) rather than extended. If tool-heavy sessions still cause extraction pressure for you on Coding Agents, please open a fresh issue with the numbers — the fix would be a server-side folding or scheduling change, not a client knob.

nicoloboschi avatar Aug 12 '26 06:08 nicoloboschi