agentleFS
jasonmichaelbell78-creatorjasonmichaelbell78-creator/sonash-v0/.claude/skills/session-end/SKILL.md

session-end

Skill2 starsChanged 9 months agoApache-2.0View on GitHub

Structured closure workflow that preserves session context for the next session, runs compliance checks, captures metrics, and commits all changes. Designed to prevent stale context — the #1 cause of wasted time in subsequent sessions. 1. **MUST update SESSION_CONTEXT.md* — all three sections (summary, status table, next goals). Skipping this causes the next session to start with wrong priorities, wrong metrics, wrong status. 2. *MUST show pre-commit summary* before pushing — git status, script results, and any warnings. Never push…

We split this skill into the rules it gives an agent

33 rules. 0 are common, 26 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 18 edited versions we read keep these.

  • 26

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    MUST show pre-commit summary: before pushing — git status, script results, and any warnings.

    line 20
  2. Distinctive:

    Before closing Claude Code

    line 30
  3. Distinctive:

    When switching to a different project

    line 31
  4. Distinctive:

    Compaction recovery (MUST): If conversation context is unavailable after compaction, reconstruct from git commits — they are the most …

    line 54
  5. Distinctive:

    Before running, check if session-end already ran this session:

    line 75
  6. Distinctive:

    If yes, skip redundant steps.

    line 80
  7. Distinctive:

    Use git log to review what was done.

    line 98
  8. Distinctive:

    Use the commit summary from Step 1 to update all three sections:

    line 110
  9. Distinctive:

    Add this session's summary.

    line 114
  10. Very specific:

    Keep only the last 3 session summaries — archive older ones to docs/SESSION_HISTORY.md (add new entries at the top of the most recent month …

    line 120
  11. Distinctive:

    Update to reflect current reality — TDMS numbers, sprint progress, plan step status.

    line 129
  12. Very specific:

    If you implemented features or completed tasks, verify ROADMAP.md reflects current status.

    line 141
  13. Distinctive:

    Check if agents suggested during the session were actually invoked:

    line 152
  14. Very specific:

    If pending-reviews.json shows queued: true but no code-reviewer was invoked, flag as a compliance gap.

    line 165
  15. Very specific:

    Read .claude/state/agent-invocations.jsonl to summarize agent activity:

    line 170
  16. Distinctive:

    If the file doesn't exist or has no current-session entries, skip silently.

    line 187
  17. Distinctive:

    If either file doesn't exist, skip silently

    line 196
  18. Distinctive:

    If no recent changes, note: "Planning data stable (no changes in 7d)"

    line 197
  19. Distinctive:

    If recent changes exist, summarize: "N decisions total, M changes in last 7d"

    line 198
  20. Distinctive:

    If overrides exist: Were they justified?

    line 209
  21. Distinctive:

    Should it be made non-blocking?

    line 210
  22. Distinctive:

    Run these commands sequentially.

    line 249
  23. Very specific:

    Ecosystem health triage check (SHOULD): After 7b, check if .claude/state/task-ecosystem-health-triage.state.json exists.

    line 259
  24. Distinctive:

    If the file doesn't exist, skip silently (triage wasn't run this session).

    line 262
  25. Distinctive:

    After running metrics, include a one-liner in the session summary (Step 2A) if any hook data is notable:

    line 279
  26. Very specific:

    Read .claude/state/commit-log.jsonl for today's entries to provide commit pattern insights:

    line 299
  27. Distinctive:

    Before committing, present a summary to the user:

    line 355
  28. Distinctive:

    Run git status — show all files that will be committed

    line 357
  29. Distinctive:

    Dirty tree check: If files outside session-end's expected output are staged, warn the user before proceeding

    line 358
  30. Distinctive:

    Ask: "Ready to commit and push?

    line 361
  31. Very specific:

    If --no-push was specified, skip this step.

    line 373
  32. Distinctive:

    If any script fails during execution:

    line 416
  33. Distinctive:

    If a MUST script fails (7b-7e), warn that metrics may be stale

    line 421

“Common” is measured: kept by at least 6 in 10 of the 18 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Session End Pipeline

Structured closure workflow that preserves session context for the next session, runs compliance checks, captures metrics, and commits all changes. Designed to prevent stale context — the #1 cause of wasted time in subsequent sessions.

Critical Rules (MUST follow)

  1. MUST update SESSION_CONTEXT.md — all three sections (summary, status table, next goals). Skipping this causes the next session to start with wrong priorities, wrong metrics, wrong status.
  2. MUST show pre-commit summary before pushing — git status, script results, and any warnings. Never push blind.
  3. MUST note script failures — if any script fails, log it, continue with remaining steps, and flag in the pre-commit summary.
  4. MUST show health score dashboard and velocity summary to the user. Summarize other script output only if errors occurred.

When to Use

  • End of work session (done for the day)
  • Before closing Claude Code
  • When switching to a different project
  • User explicitly invokes /session-end

When NOT to Use

  • Mid-session save — use /checkpoint instead (preserves state without closure)
  • Quick break without pushing — use /session-end --no-push (runs steps 1-8, skips commit)
  • Still actively working — don't run yet; session-end is for closure

Routing: session-end = full closure (context + metrics + commit + push). checkpoint = mid-session state preservation without closure or metrics.

Inputs

This skill needs:

  • Conversation context — what was accomplished this session
  • SESSION_CONTEXT.md — current state to update
  • State files — .claude/hooks/.session-agents.json, .agent-trigger-state.json, pending-reviews.json

Compaction recovery (MUST): If conversation context is unavailable after compaction, reconstruct from git commits — they are the most reliable context source:

git log --oneline -20
git diff --stat HEAD~10

State files are secondary (may already be cleaned up by Step 7).

Anti-Patterns

  • Running mid-task — finish current work first, then close the session
  • Skipping Step 2 — stale SESSION_CONTEXT.md is the #1 session-start problem
  • Committing on wrong branch — verify you're on the branch where session work was done
  • Running twice — check duplicate detection (Step 8) before re-running

Duplicate Detection (MUST)

Before running, check if session-end already ran this session:

  1. Was SESSION_CONTEXT.md already updated today with a current session summary?
  2. Did the conversation already complete this checklist?

If yes, skip redundant steps. Warn the user: "Session-end already ran this session. Re-running would duplicate the session summary."


Warm-Up (MUST — present at start)

Session-end pipeline: context preservation, compliance review, metrics
capture, and final commit. 4 phases, ~2-3 minutes.

Phase 1: Context Preservation (Steps 1-3) — MUST

Step 1. Review Session Work

Use git log to review what was done. This output feeds Step 2.

git log --oneline -10

Step 2. Update SESSION_CONTEXT.md (MANDATORY — DO NOT SKIP)

Why this matters: If you skip this step, the next session starts with stale context — wrong priorities, wrong metrics, wrong status. This has caused real bugs. Every section below must be updated.

Use the commit summary from Step 1 to update all three sections:

A. Recent Session Summaries (MUST)

Add this session's summary. Must include:

  1. What was accomplished (reference commits)
  2. TDMS metrics delta (if changed)
  3. Any blockers for next session

Keep only the last 3 session summaries — archive older ones to docs/SESSION_HISTORY.md (add new entries at the top of the most recent month section, format: ### Session #N (YYYY-MM-DD) with **Focus**: line).

Format note: Session summary format must match what session-begin expects to parse. See session-begin Step 1 for the canonical format.

B. Quick Status Table (MUST)

Update to reflect current reality — TDMS numbers, sprint progress, plan step status.

C. Next Session Goals (MUST)

Rewrite based on what's actually next — remove completed goals, add new goals unlocked by this session's work, update S0/S1 counts.

Target: SESSION_CONTEXT.md should stay under ~300 lines.

Step 3. Roadmap Check (SHOULD — if feature work done)

If you implemented features or completed tasks, verify ROADMAP.md reflects current status. Mark completed items with [x]. Skip if no feature work done.

Progress: Context preservation complete (1/4 phases).


Phase 2: Compliance Review (Steps 4-6) — SHOULD

Step 4. Agent Compliance Review (SHOULD)

Check if agents suggested during the session were actually invoked:

cat .claude/hooks/.session-agents.json 2>/dev/null
cat .claude/hooks/.agent-trigger-state.json 2>/dev/null

Compare agentsInvoked against suggestions. Report gaps. Also check:

cat .claude/state/pending-reviews.json 2>/dev/null

If pending-reviews.json shows queued: true but no code-reviewer was invoked, flag as a compliance gap.

Step 4b. Agent Invocation Summary (SHOULD — D26 data flow)

Read .claude/state/agent-invocations.jsonl to summarize agent activity:

  1. Filter entries to current session (match session ID or today's date)
  2. Group by agent/skill name
  3. For each group, report:
    • Count of invocations
    • Success/failure breakdown
    • Total duration (if available)
  4. Include in session summary output:
Agent Activity This Session:
  code-reviewer: 3 runs (3 pass, 0 fail)
  security-auditor: 1 run (1 pass)
  Total: 4 invocations, 100% success rate

If the file doesn't exist or has no current-session entries, skip silently.

Step 4c. Planning Data Summary (SHOULD — D26 data flow)

Read .planning/system-wide-standardization/decisions.jsonl and .planning/system-wide-standardization/changelog.jsonl to surface active planning context:

  1. Count total decisions and recent changes (last 7 days)
  2. If either file doesn't exist, skip silently
  3. If no recent changes, note: "Planning data stable (no changes in 7d)"
  4. If recent changes exist, summarize: "N decisions total, M changes in last 7d"

Include in session summary output. This prevents planning data from becoming write-only dead weight.

Step 5. Override Audit Review (SHOULD — if overrides were used)

node scripts/log-override.js --list

If overrides exist: Were they justified? Did the skipped check pass later? Should it be made non-blocking? Flag overrides without reasons as process violations. Skip if no overrides were used this session.

Step 5b. Hook Learning Synthesizer (SHOULD — C3-G1)

Surface the top 3 recurring hook issues from the last 7 days. Read these data sources (best-effort — skip any that don't exist):

  1. Override log: .claude/state/override-log.jsonl — group by check, count occurrences
  2. Hook warnings log: .claude/state/hook-warnings-log.jsonl — group by type, count occurrences
  3. Health score log: .claude/state/health-score-log.jsonl — find categories scoring below 70

Synthesize: Merge the top contributors from each source, deduplicate, rank by frequency, and present the top 3 as a one-liner each:

Hook learnings (7d):
  1. cognitive-complexity: 12 overrides, 8 warnings — consider raising baseline
  2. propagation: 6 warnings — writeFileSync still most common pattern
  3. hook-health score dropped to 50 — check pre-push reliability

If no data or all sources empty: Skip silently (no output).

Step 6. Update Session State (SHOULD)

npm run hooks:health -- --end

Progress: Compliance review complete (2/4 phases).


Phase 3: Metrics & Data Pipeline (Step 7) — MUST

Run these commands sequentially. If any command fails, note the failure and continue with the remaining commands.

#CommandPurposeOutputSkip if
anpm run reviews:sync -- --applyReview sync (v1 bridge)reviews.jsonlNever skip
bnode .claude/skills/ecosystem-health/scripts/run-ecosystem-health.jsHealth score snapshotecosystem-health-log.jsonlNever skip
cnode scripts/debt/consolidate-all.jsTDMS consolidationMASTER_DEBT.jsonlNever skip
dnode scripts/debt/generate-metrics.jsTDMS metricsmetrics.json, METRICS.mdNever skip

Ecosystem health triage check (SHOULD): After 7b, check if .claude/state/task-ecosystem-health-triage.state.json exists. If it does, read it and include in session summary: "N dimensions triaged (M fixed, K deferred)." If the file doesn't exist, skip silently (triage wasn't run this session).

Show to user: Health score dashboard (7b) and ecosystem health triage results (if any). Summarize other output only if errors occurred. If health score degraded since last check, note in session summary (Step 2).

Note: Learning consolidation runs automatically during SessionStart when threshold is reached (10+ reviews). No action needed here.

<!-- -->

v1/v2 Note (INTG-06): Review sync (7b) uses the v1 script which bridges legacy markdown reviews to JSONL. The v2 pipeline writes JSONL directly. Fallback: npm run reviews:sync:v1.

Step 7f. Hook Data Summary (SHOULD — L3)

After running metrics, include a one-liner in the session summary (Step 2A) if any hook data is notable:

  • Overrides this session: count from .claude/state/override-log.jsonl entries with today's date
  • Warnings this session: count from .claude/state/hook-warnings-log.jsonl entries with today's date
  • Health delta: grade change from .claude/state/health-score-log.jsonl (last two entries)

Format (only include if non-zero):

Hook summary: 3 overrides, 2 warnings, health B→B (stable)

If all zero or no data: Skip silently.

Step 7g. Commit Analytics (SHOULD — D26 data flow)

Read .claude/state/commit-log.jsonl for today's entries to provide commit pattern insights:

  • Count of commits this session
  • Average files changed per commit
  • Flag if session had 0 granular commits (only session-end)

Format (only include if notable):

Commit analytics: 5 commits, avg 3.2 files/commit

If no commit data or single commit: Skip silently.

Progress: Metrics & data pipeline complete (3/4 phases).


Phase 4: Cleanup & Closure (Steps 8-10) — MUST

Step 8. Clean Up State Files (MUST)

# Remove ephemeral session tracking files
rm -f .claude/hooks/.session-agents.json
rm -f .claude/hooks/.agent-trigger-state.json
rm -f .claude/state/pending-reviews.json

# Only remove handoff if no tasks are still in progress
if ! grep -q '"status": "in_progress"' .claude/state/task-*.state.json 2>/dev/null; then
  echo "No in-progress tasks found. Cleaning up handoff file."
  rm -f .claude/state/handoff.json
else
  echo "In-progress tasks found. Preserving handoff.json for session recovery."
fi

Orphaned /synthesize state check (v2.0 contract, Session #284): If .claude/state/synthesize.state.json exists with a non-terminal status (i.e., not complete / no_signal / blocked), warn the user — a prior /synthesize run did not reach a terminal state. Do not auto-delete; present options (resume via /synthesize --resume, archive to history/, or acknowledge and defer).

if [ -f .claude/state/synthesize.state.json ]; then
  STATUS=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('.claude/state/synthesize.state.json','utf8')).status||'')}catch{console.log('')}")
  case "$STATUS" in
    complete|no_signal|blocked|"") : ;;
    *) echo "WARN: orphaned synthesize.state.json (status=$STATUS) — see /synthesize --resume" ;;
  esac
fi

Step 9. Pre-Commit Review (MUST)

Before committing, present a summary to the user:

  1. Run git status — show all files that will be committed
  2. Dirty tree check: If files outside session-end's expected output are staged, warn the user before proceeding
  3. List scripts that succeeded/failed from Step 7
  4. Ask: "Ready to commit and push? [Y/n]"

Expected session-end output files: SESSION_CONTEXT.md, SESSION_HISTORY.md, ROADMAP.md, velocity-log.jsonl, reviews.jsonl, ecosystem-health-log.jsonl, MASTER_DEBT.jsonl, metrics.json, METRICS.md.

Step 10. Final Commit & Push (MUST — unless --no-push)

npm run session:end

If --no-push was specified, skip this step. All prior steps still run — context is preserved locally without pushing.

Progress: Cleanup & closure complete (4/4 phases).


Done When

Session-end is complete when ALL of the following are true:

  • SESSION_CONTEXT.md updated (all 3 sections: summary, status, next goals)
  • All metrics scripts ran (or failures noted)
  • Pre-commit summary shown to user
  • Final commit pushed (or --no-push acknowledged)
  • Health score and velocity summary shown to user

Artifact Manifest

FileRead/WriteStepPurpose
SESSION_CONTEXT.mdR/W2Session summary, status, goals
SESSION_HISTORY.mdW2Archived session summaries
ROADMAP.mdR/W3Feature completion status
.session-agents.jsonR/D4, 8Agent compliance check, then delete
.agent-trigger-state.jsonR/D4, 8Agent trigger check, then delete
pending-reviews.jsonR/D4, 8Review queue check, then delete
agent-invocations.jsonlR4bAgent invocation summary
decisions.jsonlR4cPlanning decisions context
changelog.jsonlR4cPlanning change tracking
velocity-log.jsonlW7aVelocity metrics
reviews.jsonlW7bReview sync
ecosystem-health-log.jsonlW7cHealth score trend
task-ecosystem-health-triage.state.jsonR7cTriage results (if exists)
MASTER_DEBT.jsonlW7dConsolidated debt
metrics.jsonW7eMachine-readable metrics
METRICS.mdW7eHuman-readable metrics
commit-log.jsonlR7gCommit pattern analytics

Script Failure Handling

If any script fails during execution:

  1. Note the error message and which script failed
  2. Continue with remaining steps — do not stop the pipeline
  3. Include the failure in the pre-commit summary (Step 9)
  4. If a MUST script fails (7b-7e), warn that metrics may be stale

Integration

  • Neighbors: session-begin (reads what session-end writes), checkpoint (mid-session alternative)
  • Input: Conversation context, SESSION_CONTEXT.md, state files
  • Output: Updated SESSION_CONTEXT.md, metrics files, final commit
  • Handoff: session-begin will verify SESSION_CONTEXT.md freshness, review sync status, and session gaps. Get these right.

session-begin will verify:

  1. SESSION_CONTEXT.md "Last Updated" is current
  2. Review sync (reviews.jsonl matches markdown log)
  3. Session gaps (undocumented sessions between commits)
  4. ROADMAP hygiene (completed items marked)

Learning Loop (MUST — after Step 10)

Auto-learnings (MUST): Generate 2-3 data-driven insights from the session closure (steps skipped, steps that failed, duration patterns). Save to auto-memory (memory/session-end-learnings.md).

Optional user feedback (SHOULD): "Any steps to add, remove, or reorder?" Accept empty / "none" to proceed. If provided, persist to auto-memory.

On next startup (MUST): Surface previous auto-learnings and user feedback so future invocations benefit from accumulated experience.


Version History

VersionDateDescription
2.22026-03-13Add Steps 4c (planning data) and 7g (commit analytics) — D26 Recall fixes
2.12026-03-13Add Step 4b: agent invocation summary (D26 data flow)
2.02026-03-07Full rewrite from skill-audit: 32 decisions applied
1.12026-03-01Add health score snapshot step (INTG-02)
1.02026-02-25Initial implementation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.