Skip to content

fix: context.md describes the session being saved, even with parallel sessions - #14

Open
ArtUT1582 wants to merge 5 commits into
raiyanyahya:masterfrom
ArtUT1582:fix/context-per-session
Open

ArtUT1582 wants to merge 5 commits into
raiyanyahya:masterfrom
ArtUT1582:fix/context-per-session

Conversation

@ArtUT1582

@ArtUT1582 ArtUT1582 commented Sep 22, 2026 •

Copy link
Copy Markdown

Summary

context.md should describe the session being saved. With more than one Claude Code session running in a project folder at the same time (common with the desktop app), it did not, in three separate ways. This PR fixes all three, plus a small Goal issue.

1. Summary came from the whole project history. Goal, Files and Commands came from the session's transcript, but Summary and Next steps came from .recall/history.md, which accumulates every session ever captured. On a long-lived project the summary filled with unrelated older work. Now the summary is built from the session's own transcript; history is only a fallback.

2. All sessions appended to one history.md. Parallel sessions interleaved their turns in the one file, so no slice of it was reliably one session. Each session now logs to its own file, .recall/history/<id8>.md. The id is sanitised to 8 safe characters, so it can never name a path outside history/.

3. /recall:save saved the wrong session. With no transcript path from a hook, locate_transcript() took the newest .jsonl in the project's transcript dir, i.e. whichever parallel session wrote last, and saved that session's goal and state. It now uses CLAUDE_CODE_SESSION_ID, which Claude Code sets in every tool call:

  • the session's own transcript is matched exactly (the id is unique, so a match in any project dir is safe);
  • a known id with no file returns None rather than a guess;
  • with no id it falls back to the newest file, as before.

Each save also writes .recall/context/<id8>.md, so a parallel session's save cannot overwrite it. context.md stays the latest save, which is what session_start reads.

4. Goal skips image-only messages. A session that opened with a pasted screenshot got [Image: source: …png] as its Goal. Image placeholders are now dropped and the first message with real text is used.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs / CI only

Checklist

  • ruff check scripts tests passes
  • bandit -c pyproject.toml -r scripts passes
  • pytest passes with and without numpy installed: 39 passed with numpy; 38 passed + 1 skipped (the numpy-only comparison) without. On Windows the three symlink tests in test_security.py fail with WinError 1314 because a standard account cannot create symlinks; they are untouched by this PR.
  • claude plugin validate . passes
  • Added/updated tests under tests/: parallel sessions land in separate files and never in history.md; a hostile session id stays inside history/; /recall:save picks its own transcript over a newer peer's, returns nothing for a missing one, and falls back to newest without an id; Goal skips image-only messages. The session-slice test moved from scripts/ to tests/ (bandit flagged its asserts, and pytest did not run it).
  • Updated CHANGELOG.md
  • No new runtime dependency, no network call, no API key (numpy stays optional)

Compatibility

Existing projects keep their history.md; it is no longer written, and it is still read as a fallback, sliced to one session, when a session's own log does not exist yet.

🤖 Generated with Claude Code

ArtUT1582 and others added 4 commits September 22, 2026 16:13
…t history

context.md drew Goal, Files and Commands from the session's transcript but its
Summary and Next steps from .recall/history.md, which accumulates every session
ever captured for the project. On a long-lived project the document mixed one
session's facts with unrelated older threads and read as current state.

Slicing history to the current "## Session <id>" block is not enough on its own:
history.md is shared mutable state. When several sessions run in one project
folder at once they all append to the one file, and a session that has not written
its own header lands inside another session's block, so no per-header slice is
reliably the session being saved.

The corpus is therefore the session's own transcript, which is per-session by
construction. history.md remains the fallback when the transcript yields no prose,
sliced to a single block by _session_slice(). test_session_slice.py covers that
helper, including an earlier block staying reachable after a later one appended.
…n session

Several Claude sessions routinely run in one project folder. They all appended
to one .recall/history.md, and /recall:save summarized the NEWEST transcript in
the folder - whichever parallel session wrote last - so context.md described a
different session's goal and state (2026-09-24: an SLB-catalog session showed up
in a finance session's save).

- capture: each session appends to .recall/history/<id8>.md. The session id is
  sanitised to 8 safe chars, so it can never name a path outside history/.
- locate_transcript: uses CLAUDE_CODE_SESSION_ID (set in every tool call) to
  find the session's own transcript. Known id but no file returns None, never a
  guess; no id falls back to the newest file, as before.
- make_context: also writes .recall/context/<id8>.md, so a parallel session's
  save cannot overwrite yours; context.md stays the latest save. The history
  fallback reads the session's own file first, then the legacy shared file.
- session_start: names the per-session log file.

Tests: parallel sessions land in separate files and never in history.md; a
hostile session id stays inside history/; save picks its own transcript over a
newer peer's. 33 pass; the 3 symlink tests need Windows Developer Mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pasted screenshot reaches the transcript as "[Image: source: C:\...png]". When
a session opened with one, Goal became that temp-file path. first_user_goal now
drops image placeholders and takes the first user message with real text; a
message with an image plus text keeps the text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CHANGELOG [Unreleased] entry for the per-session fixes on this branch.
- ruff: sort make_context imports, wrap four long lines, def instead of lambda.
- scripts/test_session_slice.py -> tests/test_session_slice.py as a pytest
  test. It sat in scripts/, where bandit flagged its asserts (B101) and pytest
  never ran it.

ruff and bandit are clean; pytest passes with and without numpy (the three
symlink tests need symlink rights, which a standard Windows account lacks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ArtUT1582 ArtUT1582 changed the title fix(context): summarize the session being saved, not the whole project history fix: context.md describes the session being saved, even with parallel sessions Sep 24, 2026
…session

Conflicts:
- scripts/make_context.py: kept this branch's per-session helpers
  (_sid_of, _session_slice) and upstream's build(..., events=None) signature for
  harness adapters. The OpenCode capture still writes the shared history.md,
  which the fallback path still reads, sliced to one session.
- CHANGELOG.md: this branch's [Unreleased] entry above upstream's [0.4.0].

ruff and bandit clean; pytest 58 passed with numpy, 57 + 1 skipped without
(the three symlink tests need symlink rights on Windows).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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