[Bug]: Claude Code plugin re-captures copied parent history when a session is forked (Claude Desktop side chats / btw)
Issue Origin
Observed or reproduced in a real environment
Bug Description
In the Claude Desktop app (Code tab), a side chat opened with Cmd+; or /btw is created as a forked child session: it gets its own session_id and its own transcript JSONL, and that transcript starts with a full copy of the parent session's history.
The Claude Code memory plugin's auto-capture.mjs (Stop hook) tracks progress per session_id (capturedTurnCount in the per-session state file). For the new side-chat session the counter starts at 0, so the first Stop hook in the side chat captures the entire copied parent history again and commits it to a new OpenViking session. The parent conversation therefore gets extracted twice, producing duplicated memories.
The same mechanism should apply to any Claude Code session that starts from copied history (/fork, /branch, --resume --fork-session), but I only verified the Desktop side-chat case.
Steps to Reproduce
- Install the
openviking-memoryClaude Code plugin with auto-capture enabled. - In Claude Desktop → Code tab, have a normal session with some turns and let it commit (session A).
- Open a side chat from that session (
Cmd+;or/btw) and send one message (session B). - Inspect the plugin capture state and the OpenViking sessions/tasks.
Expected Behavior
Turns inherited from the parent session are not captured again; only the turns created in the side chat/fork are captured (or derived sessions can be skipped entirely by configuration).
Actual Behavior
- Claude Desktop
~/Library/Logs/Claude/main.logshows the side chat is a fork:
LocalSessions.startBtwChild: parentSessionId=local_9a1c73e1-...
[CCD] side session (user fork) local_c86b652f-... <- local_9a1c73e1-...
~/.claude/projects/<project>/c86b652f-....jsonlexists (~1 MB) and contains the copied parent history.- Plugin state
$TMPDIR/openviking-cc-capture-state/c86b652f-....json→{"capturedTurnCount":74}after the first side-chat turn;last-capture.jsonreportstotal_message_count: 74,ov_session_id: cc-c86b652f-.... - OpenViking ran a separate
session_commitforcc-c86b652f-...(memory_write: 8, memory_edit: 3) in addition to the parent's commit forcc-375ddc8a-...(memory_write: 4, memory_edit: 1). - Comparing the two
memory_diff.jsonfiles: two event memories from the parent commit were written again by the side-chat commit under different file names (one Chinese, one English), both quoting the same original user message.
Two side observations from the same commit (possibly separate issues):
- One extracted event memory quotes an assistant message but attributes it to the user peer.
- Several "preferences" memories were derived from instruction-file text (
CLAUDE.mdcontent that Claude Code re-injects as a system reminder mid-session), not from anything the user said.
Minimal Reproducible Example
See Steps to Reproduce. Relevant logic: auto-capture.mjs keys incremental state on input.session_id only and has no notion of a parent/forked session.
Possible fixes:
- Detect history inherited from another session (e.g. compare leading message
uuids against already-captured sessions, or use fork/parent metadata in the transcript if present) and set the starting cursor after the inherited part. - Or provide an option to skip capture for side chats / forked sessions.
Error Logs
No errors; capture and commit both report success.
OpenViking Version
Server: openviking 0.5.0; Claude Code plugin openviking-memory 0.7.6
Python Version
3.12.14
Operating System
macOS 26.6.2
Model Backend
N/A (issue is in capture logic, independent of model backend)
Additional Context
- Claude Desktop 3.6556.2, Claude Code 2.1.310.
- The official Claude Code desktop docs still say side chats are not saved to disk, which may be why this case wasn't anticipated: https://code.claude.com/docs/en/desktop
- A Claude Code issue log also shows desktop side chats are created as
side session (user fork)child sessions: https://github.com/anthropics/claude-code/issues/103631 - Related: #4170 (skip capture for derived sessions in another host plugin; fork-type sessions noted as still uncovered), #3007 (no built-in dedup).
I'd like to take this. Plan for auto-capture.mjs: on the first Stop of a session, detect inherited history before capturing — prefer fork/parent metadata when the transcript or session state carries it, and otherwise compare the leading messages' uuids against message uuids already captured for other sessions; the incremental cursor then starts after the inherited prefix so only genuinely new turns are committed. I'll keep the current per-session capturedTurnCount semantics for non-forked sessions, add regression tests for the forked-history detection, and link the PR here.