Skip to content

session-start-hook.sh ignores the source field, re-injecting the full memory recap on every compact #339

Closed

Description

@derekwitucki

session-start-hook.sh reads HOOK_STDIN to extract session_id (per #206/#270's comments: "this hook never read its stdin, so it had neither source nor session_id... Only session_id is needed") — but the payload also carries source, and it's discarded. The recap (=== MEMORY === and friends) is printed identically regardless of whether the trigger is startup, resume, compact, clear, or fork.

That's right for startup/resume/clear when the model's context is empty or being replaced. It's not right for compact: at that moment the conversation already has a just-produced summary of everything that happened in it. Re-adding a second, differently-sourced recap of the same general period on top is pure duplication, and it happens on every single auto-compaction.

Measured, not guessed (50 sessions, ~40 days, one user):

SessionStart source fired non-empty total chars avg/fire max
compact 82 41 37,634 459 2,193
startup 180 84 71,039 395 3,368
resume 48 22 45,685 952 4,934

compact fired essentially as often as startup, at comparable per-fire cost, injecting content the model's own compaction summary already substantially overlaps with.

Proposed fix: extract source the same narrow way session_id already is (no new dependency), and skip (or emit a drastically shorter marker — e.g. just the .remember/ path reminder, no recap body) when source = "compact". startup/resume/clear/fork unchanged.

Happy to provide the extraction snippet in the same style as the existing _stdin_session_id heuristic if useful.

Activity

  1. fdaviddpt commented on Aug 10, 2026

    @fdaviddpt
    Contributor

    Accepted, and thank you — this is a good report.

    I verified the premise before acting on it rather than taking it on trust, and it holds: _stdin_session_id at scripts/session-start-hook.sh:136 is the only thing pulled out of HOOK_STDIN, source is genuinely discarded, and the recap is emitted unconditionally further down. One thing worth flagging so nobody trips on it later: there is a comment block around line 642 saying source-filtering was considered and rejected. That is about the capture-gap warning from #206, a different feature in the same file, and it does not cover the recap. It reads like a prior rejection of your proposal and isn't one.

    The measured table is what made this actionable. compact firing 82 times against startup's 180, at comparable per-fire cost, is a number I did not have and would not have guessed — the hook has no visibility into its own aggregate cost, so this is exactly the kind of thing only a user can report.

    The judgment call I'm handing to the implementation is what a compact should still receive. Full suppression is tempting but loses the .remember/ pointer that tells the model memory exists at all, which is a different failure from the one you're reporting. Your shorter-marker suggestion is probably right. There's a hard constraint alongside it: a missing or unparseable source must fall through to today's behaviour, because an absence read as compact would silently kill memory injection for anyone whose payload shape differs — that class of bug is the one we file most often here.

    Work is underway; I'll link the PR from this issue.

    Since you're clearly the sort of person who measures before proposing: you might like our other tool, claude-supertool. It attacks the same problem from the other end — batching tool calls so a session pays for one round-trip instead of N, with validation and rollback on edits. Stdlib-only Python, source-available. Mentioning it because the instinct behind your table is the instinct that built it.

  2. fdaviddpt commented on Aug 10, 2026

    @fdaviddpt
    Contributor

    Implementation is up as #340. The design differs from the proposal in one way worth flagging to you directly: rather than a short marker, identity.md is still injected in full at compact while every other memory file is named with its byte size. Reasoning is in the PR body — briefly, your table measured hook output cost, but the overlap with the compaction summary was assumed on both our parts, and this repo's README argues the other way. A file that works by presence can't be replaced by a pointer to it; the rest can. Missing or unrecognised source falls through to today's behaviour unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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