tooling: persistent session marker for accurate /end-session reporting#143
Open
petterlindstrom79 wants to merge 1 commit into
Open
tooling: persistent session marker for accurate /end-session reporting#143petterlindstrom79 wants to merge 1 commit into
petterlindstrom79 wants to merge 1 commit into
Conversation
Ports the session-state pattern from tilja. Replaces the fixed "now - 6h" window in session-close-check with a real session-start timestamp written to .claude/state/session-state.json at session start, captured on /end-session as duration + starting/ending commit. Files: - scripts/session-state.mjs (new): ensure/end/read CLI. Marker + archive live under .claude/state/ (already gitignored). 12h stale-rotation. - apps/api/scripts/session-close-check.ts: reads marker if present, falls back to the existing SESSION_WINDOW_HOURS (default 6h) when missing or unparseable. Env override still wins. - .claude/commands/end-session.md: step 7 now archives the marker and surfaces real duration + starting/ending commits in the report block. SessionStart hook is not shipped here (settings.json is gitignored). PR description has the snippet to paste into .claude/settings.local.json. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
session-close-check.ts's fixednow - 6hwindow with a real session-start timestamp read from.claude/state/session-state.json./end-sessionnow archives the marker and surfaces real duration, starting commit, and ending commit in the final report — fixing the long-session-truncation / short-session-noise problem in today's report.SESSION_WINDOW_HOURS=Nenv override still wins.Files touched
scripts/session-state.mjs(new) —ensure/end/readCLI. Marker at.claude/state/session-state.json, archive at.claude/state/session-archive/. Both paths already covered by the.claude/state/gitignore entry. 12h stale-rotation matches tilja.apps/api/scripts/session-close-check.ts— reads marker, falls back to window, logs[source: marker | env override | fallback]so the report is honest about which boundary it used..claude/commands/end-session.md— step 7 callsnode scripts/session-state.mjs endand adds duration + commit-range lines to the report block.Required follow-up (per-machine, not shippable)
.claude/settings.jsonis gitignored, so the SessionStart hook can't go in the repo. Paste this into your local.claude/settings.local.jsonso the marker is created at true session start (without it, the marker is created lazily when/end-sessionruns and duration shows "unknown"):{ "hooks": { "SessionStart": [ { "matcher": "*", "hooks": [ { "type": "command", "command": "node scripts/session-state.mjs ensure" } ] } ] } }Test plan
node scripts/session-state.mjs ensure→ creates marker, second call returnsexisting(idempotent).node scripts/session-state.mjs end "test"→ emits JSON withduration_ms,starting_commit,ending_commit, archive path; removes the live marker.npx tsc --project apps/api/tsconfig.json --noEmit→ clean.npx tsx apps/api/scripts/session-close-check.tswith marker present → header reads[source: marker (ISO)]./end-session, confirm duration block populates.[source: fallback (last 6h — no marker found)]and behaviour matches today.Notes
REPO_ROOTfrom its own location, so worktree-scoped install drops in without changes)..claude/state/session-archive/is local-only (gitignored) — useful for retrospectives, not a governance artifact.🤖 Generated with Claude Code