Skip to content

fix(round-trip-tracker): detect SessionStart hook brain context#93

Open
rajkripal wants to merge 1 commit into
mainfrom
fix/round-trip-tracker-hook-attachment
Open

fix(round-trip-tracker): detect SessionStart hook brain context#93
rajkripal wants to merge 1 commit into
mainfrom
fix/round-trip-tracker-hook-attachment

Conversation

@rajkripal

Copy link
Copy Markdown
Owner

Claude Code stores hook outputs as JSONL entries with `type="attachment"`
and content in `entry["attachment"]["content"]`. The tracker's
`load_from_jsonl` gated the attachment branch on `entry.get("message")`,
but attachment entries have no `message` field, so all hook content was
silently dropped. This is why brain usage has shown 0% for weeks despite
the SessionStart hook firing on every interactive session.

Two bugs fixed:

  1. Attachment entries now read content from `entry["attachment"]["content"]`
    (with `stdout` as fallback) and store as `role="hook"`. The hook role
    is excluded from chain detection but visible to brain detection.
  2. New `detect_session_brain_preamble()` scans hook and user messages up to
    the first chain start. If a SessionStart hook injected brain context before
    any task began, all chains in that session are marked `brain_used=True`.

Also moves this script from the untracked workspace `scripts/` dir into the
cashew repo, where it belongs alongside the tracking log it writes to.

Claude Code stores hook outputs as JSONL entries with type="attachment"
and content in entry["attachment"]["content"]. The tracker's load_from_jsonl
checked entry.get("message") to gate the attachment branch, but attachment
entries have no "message" field, so all hook content was silently dropped.

Two bugs fixed:
1. Attachment entries now read content from entry["attachment"]["content"]
   (falling back to "stdout") and use role="hook" so chain logic ignores
   them as chain starts but brain detection can still see them.
2. detect_session_brain_preamble() now scans hook + user messages up to
   and including the first chain, so a SessionStart brain query marks all
   chains in that session as brain_used=True.

Also adds this script to the cashew repo (was an untracked workspace file)
so it can be version-controlled alongside the tracking log it writes to.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant