Record Claude Code session transcripts and link every git commit to the session that produced it.
Prerequisites: Node.js 23.6 or later (node -v), git, and Claude Code. On Windows, also install Git for Windows: its sh runs the git hooks, and the Claude Code hooks use the same paths.
npm install -g @mhingston5/session-logsThis installs two commands: sessions-init and sessions. Check the install with sessions --help.
To run from a git clone instead, see Development.
cd /path/to/your-repo
sessions-init
sessions doctordoctor should report no warnings (info no unlinked commits found during recorded sessions).
claude # work in a session (from the repo root or any subdirectory)
git commit -am "Your change"Every commit made during or after a session gets two trailers automatically:
Session: 2c087fae-f67a-4647-8eb6-e790c1e31844
Transcript: a53e7356f3e25c3e299a87cf142a603eff5d3c99c3fa3b619ed0aadf1fcb3713
Transcript: is the snapshot ID — it points to the transcript as it was at commit time, even if the session continues later.
sessions list
sessions show HEADIf show finds nothing, run doctor first.
- Captures each session's conversation at every turn end (Claude Code
Stophook) and stores it in.session-logs/at the repository root (even if Claude Code was launched from a subdirectory). The folder is gitignored, so transcripts never enter git history. - Links each commit to the session that produced it, with
Session:andTranscript:trailers, through a git hook. The link survives amend, squash, cherry-pick, revert and rebase. - Reads a commit's transcript as it was when the commit was made, even after the session continued. On squashed commits that combine multiple sessions,
showrenders every linked transcript (or pass--session <id>to filter to one). - Extracts decisions (opt-in) with a deterministic rule set: sentences with explicit decision language, tied to the snapshot they came from. No model or network call. See Decision extracts.
- Redacts common secret formats (private keys, cloud and API keys, bearer tokens, connection strings) before anything is written. This is best effort. Do not rely on it as the only control.
- Keeps your git hooks working. Your global hooks (for example Husky or Repowise) still run first.
- Links commits made mid-turn. A commit made while Claude is working links to that session, however many commits it makes in that turn. A turn left open for more than 2 hours (for example after an interrupt) no longer claims commits.
Run these from anywhere inside the repository. Run sessions --help at any time for a summary.
sessions list # sessions recorded in this repository (12-char snapshot IDs)
sessions list --full # sessions with full 64-char snapshot IDs
sessions commits <session-id> # commits linked to a session
sessions show <rev> # transcript(s) as of that commit (conversation turns only)
sessions show <rev> --session <id> # one session's transcript from a squashed commit
sessions show <rev> --raw # stored JSONL, one entry per line
sessions doctor # health check: hooks, store integrity, unlinked commits, missing notes
sessions notes show <rev> # the git note for a commit (its session trailers)
sessions notes rebuild # rebuild every note from trailers
sessions decisions <rev> # deterministic decision extract for a commit's transcript (needs opt-in)
sessions decisions <rev> --json # same, as JSON with snapshot and content hash
sessions summary <rev> # LLM summary of a commit's transcript (needs opt-in; generates if missing)
sessions fork <session> --at <snapshot> # new session record from a snapshot (full ID or unique prefix from list)
sessions prune --older-than 30 # dry run: which old, unlinked sessions would be removed
sessions prune --older-than 30 --apply # delete them
sessions remote push <rev> # push a commit's linked snapshots and summaries (needs remote config)
sessions remote fetch <rev> # fetch a commit's linked snapshots from the remotePruning is off unless you pass --older-than or set prune.olderThanDays in .session-logs/config.json. It removes whole sessions only, and never linked ones unless you pass --include-linked. Pruning a linked session makes show fail for those commits.
Git notes: each linked commit also has a git note, sessions notes show <rev>, derived from its trailers. Notes are updated on commit and rewrite. They live under .session-logs/notes.git, not in the main repository's refs.
Forks link to their parent automatically when Claude Code forks a session (claude --resume <id> --fork-session). The parent is found from message IDs that the fork shares with stored transcripts.
Three separate layers. Each is controlled on its own:
| Layer | Enabled by | Makes an LLM call |
|---|---|---|---|
| Transcript capture and commit links | sessions-init | No |
| Deterministic decision extract | decisions.enabled in .session-logs/config.json | No |
| LLM-generated summary (opt-in) | summaries.enabled in .session-logs/config.json | Yes: claude -p, in a background worker |
Git notes are commit-link metadata (the session trailers). They are not decision summaries.
Enabling capture never enables extraction. To opt in, create .session-logs/config.json in the repository:
{ "decisions": { "enabled": true } }With that set, every snapshot captured by the Stop hook also gets an extract. You can also generate one on demand with sessions decisions <rev>, which is refused while the setting is off.
What the extract does:
- Scans each stored
userandassistantmessage, sentence by sentence, and keeps sentences that contain an explicit signal:Decision:,decided,chose,opted,settled on,going with,instead of, ortrade-off. This is a heuristic. It finds stated decisions, not every choice the agent made. - Repeated sentences are reported once, at their first occurrence.
- Runs on the redacted snapshot only, so it cannot contain anything the transcript store does not.
- Is written to
.session-logs/decisions/<snapshot>.json, keyed by the snapshot ID. It records the snapshot ID, the session ID, the hash of the snapshot's content, and each decision's message index and UUID. An extract is never rewritten; a changed transcript gets its own snapshot and extract. - Is deterministic: the same transcript always gives the same decisions.
LLM summaries are a separate opt-in layer. They are off by default and are not turned on by capture or by decision extraction. Enable them with "summaries": { "enabled": true } in .session-logs/config.json. Other keys in that file are unaffected.
- Model: Claude Code itself, run headless (
claude -p). It uses the login you already have for Claude Code. session-logs makes no other network call for summaries. - Input: only the stored, redacted
userandassistanttext of the snapshot (D24, D44). Redaction is best effort, and a summary can still repeat anything that survived it. Transcripts over 200,000 characters keep their most recent messages, and the record says so. - Trigger: the Stop hook starts a detached worker, so the hook returns at once. The worker writes
.session-logs/summaries/<snapshot>.json. Failures go toerrors.logas error text only, with the exit status or signal and never the model's stderr or output. A snapshot that already has a summary is not summarized again. - Locking: a per-snapshot lock file is held while the model runs. Workers,
sessions summaryandpruneall use it. Two callers never call the model for the same snapshot, andpruneskips a session whose summary is in progress. A lock older than 15 minutes is treated as left behind by a dead process. - Size limit: if even the newest message is over 200,000 characters, no summary is made and the error is logged.
- Recursion guard: the summarizer's own run sets
SESSION_LOGS_SUMMARIZING=1, and the Stop hook ignores any run that has it. The run uses no tools, saves no session, and starts in a temporary directory. - Not deterministic: the output is model text. Each record names its snapshot and the source content hash, so you can trace it to the transcript version it describes. Treat it as a draft and check it against the transcript.
sessions summary <rev> prints the stored summary. If none exists yet and summaries are enabled, it generates one in the foreground.
skills/session-logs/SKILL.md teaches Claude Code to answer "why was this commit made?" from a session's transcript, and to run doctor. Claude Code only loads skills from ~/.claude/skills or .claude/skills, so link it once:
mkdir -p ~/.claude/skills && ln -s "$(npm root -g)/@mhingston5/session-logs/skills/session-logs" ~/.claude/skills/session-logsOn Windows (PowerShell), create a junction instead, which needs no admin rights: New-Item -ItemType Junction -Path "$HOME\.claude\skills\session-logs" -Target "C:\path\to\session-logs\skills\session-logs". Create the skills folder first if it does not exist.
- Only
userandassistantconversation entries are stored. Session metadata, cost data, and injected system context (your CLAUDE.md, managed policy text, memory) are not stored. Each snapshot's manifest counts what was left out, by type. - Transcripts are split into segments of up to 500 messages or 1 MB. Closed segments never change, so later snapshots reuse them.
- A snapshot's ID is the SHA-256 of its manifest. A segment is stored under the SHA-256 of its bytes.
| What | Where | Notes |
|---|---|---|
| Transcripts, snapshots, session records | .session-logs/ in the repository |
Gitignored. Local only. |
| Commit hooks | .session-logs/git-hooks/ |
Set as the repository's core.hooksPath. |
| Claude Code hook registration (Stop, UserPromptSubmit) | .claude/settings.local.json |
Per developer. Gitignored. |
| Git notes (session links per commit) | .session-logs/notes.git |
A bare repository, read through git alternates. Rebuildable from trailers. Nothing is written to the main repository's refs. |
| Decision extracts (opt-in) | .session-logs/decisions/<snapshot>.json |
Gitignored. Local only. Created only when decisions.enabled is true. |
| Summaries (opt-in) | .session-logs/summaries/<snapshot>.json |
Gitignored. Local only. Created only when summaries.enabled is true. |
| Opt-in settings | .session-logs/config.json |
{ "decisions": { "enabled": true }, "summaries": { "enabled": true }, "remote": { ... } }. Also holds prune.olderThanDays. The remote block is described in Remote storage. |
| Hook errors | .session-logs/errors.log |
Error text only; never transcript content. |
| Decisions | docs/DECISIONS.md |
sessions-init does three things in the repository:
- Points
core.hooksPathat.session-logs/git-hooks. Each git hook shim runs your global hook of the same name first, then session-logs:prepare-commit-msgadds the session trailers, and also runs the repository's own.git/hooksscript.post-commitandpost-rewriterefresh the git notes.post-commitalso pushes the linked snapshots when remote storage is enabled.pre-commitandcommit-msgonly chain to your existing hooks.
- Registers two Claude Code hooks in
.claude/settings.local.json:UserPromptSubmit(marks a turn open, so commits made mid-turn link to it) andStop(snapshots the transcript). - Adds
.session-logs/and.claude/settings.local.jsonto.gitignore.
It refuses to replace a core.hooksPath it did not set (for example Husky's), so it cannot silently disable other tools. It is safe to re-run.
If you move or reinstall session-logs (for example after changing Node versions or upgrading the global install path), re-run sessions-init in each repository. The hooks and settings contain its absolute path; re-running sessions-init replaces stale paths cleanly, and doctor warns if any registered hook points to a missing script.
showsays "has no Transcript trailer". The commit was made outside a session, or the hook did not run. Rundoctor.doctorwarns "commit hooks are not installed". Runsessions-initin this repository.doctorreports an unlinked commit during a session. This is a heuristic: it thinks a session was active when the commit was made. Check it. Commits made with--no-verifyare still linked, by design (D45).- A commit has no trailers. Read
.session-logs/errors.log. The commit still succeeds when a hook fails, by design. prunesays it is off. Pass--older-than <days>.doctorwarns that linked commits have no note. Runsessions notes rebuild.- Commits made mid-turn have no link. Re-run
sessions-init. It registers theUserPromptSubmithook, which older installs lack. - Hooks stopped working after moving or reinstalling session-logs. Re-run
sessions-init.
Remote storage is off by default. When enabled, the post-commit hook pushes the snapshots that commit links to Azure Blob Storage, with each snapshot's summary and decision extract when they exist. A summary written after its commit is pushed when it is written. Enable it in .session-logs/config.json in the repository:
{
"remote": {
"enabled": true,
"provider": "azure-blob",
"accountUrl": "https://<account>.blob.core.windows.net",
"container": "<container>"
}
}- Auth: by default, Entra ID through
DefaultAzureCredential(for exampleaz login). Your identity then needs Storage Blob Data Contributor on the container to push and Storage Blob Data Reader to fetch. Alternatively, setSESSION_LOGS_AZURE_SASin your shell to a SAS token (the query string, startingsp=or?sp=); it is used instead of Entra ID. The token is read from the environment only and is never written toconfig.jsonor the repository. Set it per session, for exampleexport SESSION_LOGS_AZURE_SAS='sv=...&sig=...'. Account keys are not supported.accountUrlmust be the bare account URL; a path, query string or credentials there are rejected. - Push: runs in the post-commit hook. Failures are logged to
.session-logs/errors.log(error text only) and never block the commit. The hook waits for the upload, so a slow connection delays it. - Redaction gate (D24): a snapshot with redactions is not pushed and is logged.
sessions remote push <rev> --allow-redactedoverrides this; the override is logged by count only. - Fetch:
sessions showandsessions summaryfetch a missing snapshot from the remote on demand, along with its summary and decision extract. A snapshot already in the local store is never re-fetched.sessions remote fetch <rev>brings in a commit's snapshots explicitly. A clone needs the sameremoteblock in its own.session-logs/config.json. Every object's hash is verified. - Who can read: anyone with read access to the container can read every transcript in it. Access tiers are not part of the MVP.
- Deletion: removing blobs does not remove copies held by clones or teammates.
The decision log is docs/DECISIONS.md.
Unit tests do not call Claude Code. To check the hooks against a live session, run this in your own terminal (it needs API access):
git clone https://github.com/mhingston/session-logs
cd session-logs
npm install
node scripts/live-check.tsIt creates a throwaway repository, runs a session and a fork, and prints the hook payload fields and the fork's SessionStart source. Output goes to ~/Downloads/live-check-<time> unless you pass a directory.
npm install
npm test # unit and integration tests; no network access
npm run typecheck # TypeScript, strict
npm run build # compile src/ to dist/ (what the npm package ships)
npm run check # typecheck and testsThe published package runs the compiled dist/ output. Node refuses to strip types from files under node_modules, so the TypeScript sources are compiled to JavaScript on npm pack and npm publish. Source files stay .ts, and tests run against them directly.
Layout:
src/cli/ sessions (read and maintenance) and init entry points
src/capture/ capture core, redaction, commit-trailer rules
src/hooks/ Claude Code Stop and UserPromptSubmit hooks; git commit, post-commit and post-rewrite hooks
src/install/ init: hook shims and settings registration
src/notes/ git notes under .session-logs/notes.git
src/read/ show, commits, list
src/maintain/ fork, doctor, prune
src/decisions/ deterministic decision extracts (opt-in)
src/summaries/ LLM summaries via claude -p (opt-in, background worker)
src/remote/ push and fetch (opt-in, Azure Blob)
src/storage/ object store interface and Azure Blob adapter (opt-in)
scripts/live-check.ts live Claude Code checks (run in your terminal; needs API access)
test/ node:test suites
docs/ decision log
Claude Code is the only supported agent. Agent-specific code lives in src/hooks/ and src/install/, so another agent would need its own hook adapter.
MIT. See LICENSE.