Skip to content
Back to skills

Session

ASecurity

Session state that outlives a context reset — `dump` sweeps the live conversation and writes a compact handover doc (goal, decisions + why, lessons, standing instructions, files-touched table, outstanding items, next step), then prints `/clear`; the `session-restore.js` SessionStart hook re-injects it automatically. `status`, the default when no mode is given, prints a plain-English readout (purpose, accomplished, discovered, pending, safe to close) and writes no file; `park` stashes a diverg...

  • 31 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 27, 2026
data-aigoshellbashgit

Works with

  • claude code
  • terminal

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add Borda/AI-Rig --skill session --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Session?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Session
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/borda-session/badge)](https://www.skillsdirectory.com/skills/borda-session)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: session
description: 'Session state that outlives a context reset — `dump` sweeps the live conversation and writes a compact handover doc (goal, decisions + why, lessons, standing instructions, files-touched table, outstanding items, next step), then prints `/clear`; the `session-restore.js` SessionStart hook re-injects it automatically. `status`, the default when no mode is given, prints a plain-English readout (purpose, accomplished, discovered, pending, safe to close) and writes no file; `park` stashes a diverging idea mid-session without derailing; `sweep` audits the conversation for unlanded work. TRIGGER when, by mode: `status` (no args) for "what is this session about", "what did we accomplish", "what is still pending", "anything unfinished before I close", "safe to close this session"; `dump` for "dump the session", "handover before clear", "save state before clearing", "carry this over", "I want to clear but keep the plan"; `park` for "park this for later"; `sweep` for "what did we defer", "audit what never landed"; `list` for "what is parked", "show parked items". Run `sweep` only when the user asks to audit or park unlanded ideas. SKIP: surviving auto-compact (that is the skill contract in `.temp/state/skill-contract.md` per `compaction.md`, written by the running skill); reviving a *finished* conversation (Claude Code native `/resume`).'
argument-hint: '[status] | dump [name] | recall [name] | list | park <idea> | sweep | drop <item>'
allowed-tools: Read, Write, Edit, Glob, Bash, TaskList, TaskUpdate, AskUserQuestion
effort: low
---

<objective>

Carry the *durable* part of a session across `/clear`, hold open loops until they land, answer where the session stands (`status`). `dump` composes a small handover doc from the live conversation, writes it to `.claude/state/session/<slug>.md`, ends by printing `/clear`. The `session-restore.js` hook (SessionStart, matcher `clear`) injects that doc into the fresh session, so restore is free. Implementation detail — diffs, tool output, exploration transcript, abandoned approaches — dropped on purpose; only the decision that settled an approach survives.

Runs **inline, never `context: fork`**. Conversation history *is* the authoritative source for what changed, what was decided, what never landed; a forked run would see none of it.

NOT for: auto-compact survival (`compaction.md` skill contract); reviving a finished conversation (native `/resume`). Boundary table in the notes section below.

</objective>

<inputs>

- **$ARGUMENTS**: optional; empty runs `status`. Seven modes:
  - `status` — plain-English readout for the user: purpose, accomplished, discovered, still pending, safe to close. Writes no file.
  - `dump [name]` — sweep, compose and write handover doc, set `LATEST` pointer, print `/clear` next step. `name` optional; unnamed dumps derive a slug from branch + UTC timestamp.
  - `recall [name]` — print a stored handover into context, mark it consumed. Named, or `LATEST` when omitted. Manual path for dumps the hook skips.
  - `list` — table of stored handovers (slug, age, consumed) plus open parked items.
  - `park <idea>` — append one open-loop item to `.claude/state/session/PARKED.md`. No dump needed; works any time.
  - `sweep` — read conversation for unlanded ideas, unanswered questions, pending tasks; report them, offer to park.
  - `drop <item>` — fuzzy-match a parked item, remove it, log the closure.

</inputs>

<constants>

- Store dir: `.claude/state/session/` (project-local; `.claude/state/` gitignored, same as `session-context.md`)
- Item store: `.claude/state/session/PARKED.md` — one bullet per open item; survives every dump, never auto-deleted
- Pointer file: `.claude/state/session/LATEST` — plain text, slug of most recent unconsumed dump. Blank or missing = nothing pending.
- Closure log: `.claude/state/session/dropped.jsonl` — one JSON line per `drop`
- Doc size cap: ~1.5K tokens (~75 lines). Compress prose, never drop a decision.
- Hook auto-restore window: unconsumed **and** `created` within 30 min. Outside it, `recall` is the manual path.
- Hook truncation threshold: ~8000 chars — above it hook injects `## Goal` + files table + `## Next step` + a `→ /foundry:session recall <slug>` pointer instead of the whole doc.
- Stale threshold: 14 days (`⚠ stale` prefix when listing) — applies to handover docs **and** parked items
- Delete threshold: 30 days — consumed handover docs only, swept during `list`. **Unconsumed handovers and parked items never auto-deleted**; only `drop` removes a parked item.
- Files-table row cap: 25 (over that, group by directory, state elided count)

</constants>

<workflow>

**Task hygiene** — task tools may be deferred; load before first use: `ToolSearch(query="select:TaskList,TaskCreate,TaskUpdate,TaskGet", max_results=4)`. Resolve `MODE` (Step 0) first, then call `TaskList`. In `status` and `sweep`, including `park` with an empty payload (it runs sweep), `TaskList` is read-only: never call `TaskUpdate`, because their readout judges those same tasks; report a task that looks done or orphaned as an item with its suggested action (mark completed, delete). Every other mode triages each task `TaskList` returns: `completed` if work clearly done, `deleted` if orphaned, keep `in_progress` only if genuinely continuing. Never spend a turn on bookkeeping alone — every `TaskCreate`/`TaskUpdate` ships in the same response as the next substantive tool call; one exception, `TaskUpdate(completed)` immediately before a long output block (`rules/task-lifecycle.md`). <!-- policy-sibling: plugins/cc_foundry/CLAUDE.src.md (§Session-start hygiene read-only exception), plugins/cc_foundry/skills/session/SKILL.md (Task hygiene) -->

## Step 0: Validate and dispatch mode

Extract first word of `$ARGUMENTS` as `MODE`.

If `MODE` is empty or matches:

- empty, `status` (aliases: `summary`, `recap`) → **Mode: status**
- `dump` (alias: `save`) → **Mode: dump**
- `recall` (aliases: `restore`, `load`) → **Mode: recall**
- `list` → **Mode: list**
- `park` → **Mode: park**
- `sweep` → **Mode: sweep**
- `drop` (alias: `archive`) → **Mode: drop**

**Unsupported flag check** — after extracting mode token, scan the tokens after it for `--<token>` patterns — except in `park` and `drop`, whose whole remainder is free-text payload (an idea or item may itself contain `--`), never flags. Found: invoke `AskUserQuestion` with question text `` ! Unknown flag(s): `--<token>`. Supported modes: status, dump, recall, list, park, sweep, drop. `` — (a) **Abort** (stop, re-invoke correctly) · (b) **Continue ignoring** (skip unknown flags, proceed with recognized mode).

Otherwise (unrecognized, misspelled): rank the seven modes, aliases counting as spellings of their mode, by spelling closeness to `MODE`: shared leading letters first, then fewest letters added, dropped, swapped or changed (`lst` → `list`, `recll` → `recall`, `sttus` → `status`, `prak` → `park`). Invoke `AskUserQuestion` with the question "Which session mode did you want?" and exactly four options:

- (a) the second-closest mode
- (b) the closest mode — recommended; `status` when no mode is close
- (c) the third-closest mode
- (d) **Abort** — stop and re-invoke correctly

Each mode option's label is the mode name and its description is that mode's one-line effect from the inputs list. The chosen mode takes the rest of `$ARGUMENTS` as its argument.

## Step 1 / Mode: dump

### Substep 1a: Derive slug and timestamp

```bash
git branch --show-current 2>/dev/null; date -u +%Y-%m-%dT%H:%M:%SZ; date -u +%Y-%m-%dT%H-%M-%SZ; echo "--- file evidence (Substep 1c) ---"; git diff --stat HEAD 2>/dev/null; echo "--- candidate commits (last 8 hours) ---"; git log --name-only --pretty=format:'%h %s' --since="8 hours ago" 2>/dev/null | head -60; echo "--- artifact dirs (Substep 1d) ---"; find .temp .reports .experiments .developments -maxdepth 2 -type d -mtime -1 2>/dev/null | head -20  # timeout: 5000
```

> git parses the relative date itself — no BSD/GNU `date` flag split needed.

This one call also gathers the Substep 1c file evidence and the Substep 1d artifact listing (read-only, independent of the slug). First three lines out: branch, ISO `created` stamp, filesystem-safe stamp. Slug: `<name>` from `$ARGUMENTS` when given (lowercase, non-alphanumerics → `-`); otherwise `<branch with / → ->-<filesystem-safe stamp>`. Empty branch (detached HEAD): `detached`. Reject a `name` containing `/` or `..` — re-ask via `AskUserQuestion` rather than writing outside store dir. `LATEST`, `PARKED`, `dropped` are reserved slugs; re-ask on those too.

### Substep 1b: Sweep for unlanded work

Run **Step 5 / Mode: sweep** detection only — collect its rows; skip its `unlanded.md` Write, its `AskUserQuestion` and any parking (the doc's `## Outstanding` carries the items) — plus Read `.claude/state/session/PARKED.md` (skip silently if absent). Union becomes doc's `## Outstanding` section. Nothing found and no parked items: omit section.

### Substep 1c: Gather file evidence

Evidence comes from the Substep 1a call: `git diff --stat HEAD`, then candidate commits under the `--- candidate commits (last 8 hours) ---` marker. The eight-hour window does not establish session start; conversation evidence decides whether each commit belongs to this session.

**Sourcing precedence for files table** — union of four sources, in this order:

1. **Conversation history — authoritative.** Every `Edit`/`Write` of this session is visible to this skill; that's the touched-file list, and the only source that also knows *what* each change was (`Change`) and whether it landed (`State`).
2. `git diff --stat HEAD` → `Ref` column (`+N/-M`). A file with no diff entry and no commit is `Ref: uncommitted-new`, or dropped when it was temp scratch.
3. `git log --name-only --since=…` → candidate committed files no longer appearing in `git diff HEAD`; include only when conversation evidence confirms they belong to this session.
4. `.claude/state/session-context.md` → `## Files Modified This Session` — **fallback only**. `task-log.js` writes that section from its PreCompact branch, firing only when auto-compact triggers (`autoCompactThreshold`, 0.7 in foundry's guidance); a session dumping before any compaction has no such section, or a stale one from a prior session. Read only when sources 1–3 come up empty.

**Column rules**: `Change` ≤6 words, what changed, never why (why belongs in `## Decisions`). `State` ∈ `done` / `wip` / `needs-test` / `reverted`. Cap 25 rows — over that, group by directory, state elided count explicitly, never silently truncate (`quality-gates.md`). Scratchpad and `.temp/` paths are never rows; belong in `## Artifacts`.

### Substep 1d: Gather artifacts and open tasks

Artifact dirs come from the Substep 1a call (`--- artifact dirs (Substep 1d) ---` marker).

Call `TaskList` for tasks still `in_progress` or `pending` — they feed `## Next step` and `## Outstanding`, not a section of their own (task state survives on its own).

### Substep 1e: Compose the doc

Fill this template. Omit any section with nothing real in it — an empty heading is noise next session pays for.

```markdown
---
slug: <slug>
created: <ISO8601-UTC>
consumed: false
branch: <git branch>
---

## Goal
[goal or plan]

## Decisions
- [decision] — why: [reason]

## Lessons / corrections
- [correction received] — rule going forward: [rule]

## Standing instructions
- [standing directive]

## Files touched

| File | Change | State | Ref |
| --- | --- | --- | --- |
| `path/to/a.py` | added retry guard | done | +42/-3 |
| `path/to/b.md` | README sync | wip | +8/-0 |

## Outstanding
- **[slug]** — [summary]. Why: [reason]. Next: [next action].

## Artifacts

| Path | Kind | Note |
| --- | --- | --- |
| `.reports/<skill>/<ts>/report.md` | report | consolidated findings |
| `.temp/<skill>/<ts>/` | run-dir | agent handover files |

## Next step
[next action]

## Dropped deliberately
implementation detail, tool output, exploration transcript
```

> Section rules:
>
> - Keep `## Goal` to 1–3 lines.
> - Under `## Standing instructions`, include only programmatic-level directives that must keep applying.
> - Each `## Outstanding` item has a one-line summary, a one-sentence reason, and the next ask or action.
> - Keep `## Next step` to one concrete action.

**Written in ultra-caveman tier** (`plugins/CLAUDE.md` §Writing Style) — this doc is re-injected into a fresh context on every restore, so every word is a recurring cost. Explicit exclusions: no diffs, no code bodies, no command output, no per-file reasoning, no history of abandoned approaches — only the decision that settled them.

### Substep 1f: Write the doc and the pointer

Use **Write tool** for both (it creates `.claude/state/session/` on demand; no `mkdir` permission gap):

1. `.claude/state/session/<slug>.md` — composed doc. A slug that already exists is overwritten only after `AskUserQuestion` confirms; otherwise append `-2`, `-3`, … .
2. `.claude/state/session/LATEST` — slug alone, one line. Read it first when it exists, before calling Write to replace it.

`PARKED.md` is **not** cleared by a dump — doc copies items, doesn't consume them. An item leaves only via `drop`.

### Substep 1g: Print the next step

Terminal only, short. Confirm path, row count of files table, then:

```text
→ .claude/state/session/<slug>.md (N files, M decisions, K outstanding)
Next: clear the context. I cannot run it for you — Claude Code exposes no programmatic slash invocation, so the line below is yours to send. The SessionStart hook re-injects this doc automatically on the other side.

/clear
```

The literal `/clear` is the **last line of the reply** — nothing after it, so it's one copy away. This is the sole sanctioned `/clear` suggestion — `CLAUDE.md` §7 "Never suggest `/clear`" names `dump` as its one exception, because only the small handover doc is rebuilt. <!-- policy-sibling: plugins/cc_foundry/CLAUDE.src.md (§7 /clear exception), plugins/cc_foundry/skills/session/SKILL.md (Substep 1g) -->

End with a `## Confidence` block per `quality-gates.md` — score on: files table backed by conversation evidence (not guessed), decisions captured with their reasons, sweep run before composing, next step concrete enough to act on cold.

## Step 2 / Mode: recall

### Substep 2a: Resolve the target

Named → `.claude/state/session/<name>.md`. Unnamed → read `.claude/state/session/LATEST` (Read tool), use the slug it holds; blank or missing: print `No pending handover. → /foundry:session list`, stop.

Missing target file: print the miss, fall through to a `list` render so user sees what does exist.

### Substep 2b: Print it into context

Read the doc, print its body verbatim, frontmatter stripped, under a one-line banner naming slug and age. **Terminal only — never route this to a file**: landing it in context *is* the mechanism, output-routing to `.temp/` would defeat it.

### Substep 2c: Mark consumed

1. Edit tool on the doc: `consumed: false` → `consumed: true` (frontmatter only).
2. Read `.claude/state/session/LATEST` (reuse the Substep 2a read when the target was unnamed) and compare its content to the resolved slug. **Only when they match**: Write tool on `.claude/state/session/LATEST` with empty content — hook treats blank and missing alike, so nothing re-injects on next `/clear`. When `LATEST` points to a different, still-unconsumed slug: leave it untouched — recalling an unrelated named doc must never silently drop the pointer to a different pending handover.

End with a `## Confidence` block per `quality-gates.md` — score on: target resolved unambiguously, doc printed intact, consumed marker written.

## Step 3 / Mode: list

### Substep 3a: Sweep expired handover docs (≥ 30 days)

```bash
# age from frontmatter `created`, never mtime — recall's consumed edit rewrites the file and resets mtime
CUTOFF=$(date -u -v-30d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)
find .claude/state/session -maxdepth 1 -name '*.md' ! -name 'PARKED.md' 2>/dev/null | while IFS= read -r f; do
    c=$(sed -n 's/^created: *//p' "$f" | head -1 | sed "s/^['\"]//; s/['\"]$//")
    [[ "$c" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$ ]] || continue
    consumed=$(sed -n 's/^consumed: *//p' "$f" | head -1)
    [ "$consumed" = true ] && [[ "$c" < "$CUTOFF" ]] && find "$f" -maxdepth 0 -delete && echo "expired: $f"
done; echo "sweep done"  # timeout: 5000
```

> `PARKED.md` excluded by name — parked items have no TTL, only `drop` removes them. Unconsumed docs are kept. Strip surrounding quotes from `created` and require the ISO-8601 UTC shape before comparing; missing or malformed timestamps are kept, never guessed old. Normalized ISO-8601 UTC stamps compare correctly as strings.

### Substep 3b: Collect and render

Glob `.claude/state/session/*.md` **excluding `PARKED.md`** (it holds bullets, not frontmatter), Read each one's frontmatter for `slug`, `created`, `consumed`, `branch`. Age comes from `created`, not file mtime — marking a doc consumed rewrites the file, would reset mtime. Read `PARKED.md` separately for items table; its ages come from each bullet's `Raised:` date.

```markdown
## Session store — [date]

### Handovers

| Slug | Age | Branch | Consumed |
| --- | --- | --- | --- |
| `plan-x` | 12 min | main | no |
| `⚠ stale refactor-auth` | 16 d | feat/auth | yes |

### Parked ([open item count])

- [ ] **retry-backoff** — revisit exponential vs linear. Raised: 2026-08-10.
- [ ] ⚠ stale **split-ratio** — 80/20 vs 70/30 never settled. Raised: 2026-07-20.

→ /foundry:session recall <slug> to print a handover back into context
→ /foundry:session drop <item> to close a parked item
```

`⚠ stale` prefix at ≥14 days, both tables. Nothing in either: `No stored handovers, no parked items.`

End with a `## Confidence` block per `quality-gates.md` — score on: glob returned a result (even empty), every frontmatter parsed, ages computed from `created` / `Raised:`.

## Step 4 / Mode: park

Payload is everything after `park ` in `$ARGUMENTS`. Empty payload: run **Mode: sweep** instead, offer its findings as parking candidates, rather than asking for text conversation already holds.

Derive a short kebab slug from payload, then Read `.claude/state/session/PARKED.md` (absent: start a fresh file with `# Parked items` heading), Edit/Write one bullet appended at end:

```markdown
# Parked items

- **[slug]** — [summary]. Raised: [date]. Why: [reason]. Next: [next action].
```

> Keep each summary to one line and each Why to one sentence. Next states what to ask or do when revisiting.

Date from `date -u +%Y-%m-%d` (fold into any bash call this step already makes). Slug already present: update that bullet rather than adding a near-duplicate, say so.

Print one line: `Parked: [slug]` plus current open count. Terminal only.

## Step 5 / Mode: sweep

Read the **conversation**, not the filesystem. Nothing to run — history already in context. Collect, in this order:

| Type | Trigger |
| -- | -- |
| Unanswered question | Claude asked, user sent a new top-level request instead of answering |
| Deferred exploration | "come back to that", "park this", "later" — idea named, not pursued |
| Diverging idea | feature/design idea raised while solving something else |
| Unfinished task | `TaskList` entry still `pending` / `in_progress` |
| Stated-but-unlanded | a change discussed and agreed, with no Edit/Write backing it in this session |

Call `TaskList` read-only for the fourth row, never `TaskUpdate`; a task that looks done or orphaned stays a row, with its suggested action. Detection stays **behavioural** — a new top-level request without an answer to prior question — never semantic-similarity scoring.

Build the Unlanded table and Write it to `.temp/session/unlanded.md` first:

```markdown
## Unlanded — [item count] items

| # | Item | Type | Why it did not land |
| --- | --- | --- | --- |
| 1 | retry backoff shape | deferred | user said "later, after the bench lands" |
```

The saved Unlanded table is printed once, rendered as normal Markdown, as the last reply text before `AskUserQuestion`: (a) park all · (b) park a subset (list the numbers) · (c) skip. The question text carries the Unlanded headline, item count, brief item names/numbers and `→ .temp/session/unlanded.md`. Keep the question text to at most 6 plain lines (target 600 characters, hard cap 1,500), with no table, no pipe layout and no code fence. Options carry labels and one-line action descriptions, no `preview`; place the recommended option second without changing labels or answer mapping. Selecting (a) or (b) runs **Mode: park** for each chosen item in the same turn. Zero items: no question — `## Unlanded — 0 items` opens the final reply instead.

When a `session-restore.js`-injected handover doc is present at the start of this conversation (a freshly restored session), its `## Decisions` and `## Outstanding` sections are part of the candidate set too — an item listed there and not yet re-confirmed as landed in the live turns since restore still counts as stated-but-unlanded. Do not require post-restore Edit/Write evidence for something the restored doc's own `## Files touched` table already marked `done`.

Sweep sees the **current conversation only**. A finished session's unlanded ideas are unreachable — native `/resume` revives the conversation itself; this skill never mines transcript JSONL.

End with a `## Confidence` block per `quality-gates.md` — score on: every row traceable to a concrete conversation turn (not inferred), `TaskList` consulted, no already-landed work listed as outstanding.

## Step 6 / Mode: drop

### Substep 6a: Fuzzy-match the target

Match everything after `drop ` against slugs and summaries in `.claude/state/session/PARKED.md`. Ambiguous (2+ equally close): `AskUserQuestion` to disambiguate, one option per candidate (closest 4; label = slug, description = its summary). No match: render parked list, stop.

### Substep 6b: Remove the bullet and log the closure

Edit tool on `PARKED.md` — remove only matched bullet, leave rest untouched. Then append one audit line:

```bash
ITEM="<matched slug>"
[[ "$ITEM" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]] || { echo "! BLOCKED — resolve the matched slug before logging"; exit 1; }
mkdir -p .claude/state/session || exit 1
TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)
jq -n --arg ts "$TS" --arg item "$ITEM" '{"ts":$ts,"item":$item,"action":"dropped"}' >> .claude/state/session/dropped.jsonl  # timeout: 5000
```

> jq escapes the slug — a bullet holding quotes or braces can never break the log line.

Print `Dropped: [slug]` plus remaining open count. Terminal only.

End with a `## Confidence` block per `quality-gates.md` — score on: match unambiguous, only the matched bullet removed, audit line appended.

## Step 7 / Mode: status

Answer the user's "where are we?" in one readout. Terminal only: no file Write, no `TaskUpdate`, no `AskUserQuestion`, no parking, no `/clear`.

### Substep 7a: Gather evidence

Conversation gives purpose, work done and findings. Disk gives what is still open — one call:

```bash
LIMIT=40
TOP=$(git rev-parse --show-toplevel 2>/dev/null) || TOP=$PWD
REMOTES=$(git remote 2>/dev/null) || REMOTES=unknown
for SECTION in "uncommitted files, this checkout" "stash entries, whole repository" "local branches with commits on no remote: branch | commits" "active plans"; do
    # case exits with its read's status: a failed read prints unknown, never 0
    case $SECTION in
        uncommitted*) OUT=$(git --no-optional-locks status --porcelain --untracked-files=all 2>/dev/null) ;;
        stash*) OUT=$(git stash list 2>/dev/null) ;;
        local*) [ -n "$REMOTES" ] || { echo "--- $SECTION: none pending, no remote configured ---"; continue; }
            REFS=$(git for-each-ref --format='%(refname)' refs/heads 2>/dev/null) && OUT=$(printf '%s\n' "$REFS" | while IFS= read -r REF; do [ -n "$REF" ] || continue; N=$(git rev-list --count "$REF" --not --remotes 2>/dev/null) || N=unknown; [ "$N" = 0 ] || echo "${REF#refs/heads/} | $N"; done) ;;
        # .plans absent counts as 0 only once a listing of it succeeds; an unlistable .plans is unknown
        active*) OUT=; if [ -e "$TOP/.plans" ]; then HAS_ACTIVE=$(find "$TOP/.plans" -mindepth 1 -maxdepth 1 -name active 2>/dev/null) && { [ -z "$HAS_ACTIVE" ] || OUT=$(find "$TOP/.plans/active" -maxdepth 1 -type f 2>/dev/null); }; fi ;;
    esac || { echo "--- $SECTION: unknown, read failed ---"; continue; }
    COUNT=$(printf '%s' "$OUT" | grep -c ''); echo "--- $SECTION: $COUNT ---"
    printf '%s\n' "$OUT" | head -n "$LIMIT" | grep .
    [ "$COUNT" -le "$LIMIT" ] || echo "... $((COUNT - LIMIT)) more not shown"
done
detached_ahead() {
    local ADMIN LOG_DIR LOG POSITIONS=
    ADMIN=$(git -C "$1" rev-parse --absolute-git-dir 2>/dev/null) || return 1
    LOG_DIR="$ADMIN/logs"
    LOG="$LOG_DIR/HEAD"
    if [ -e "$LOG" ]; then
        [ -f "$LOG" ] || return 1
        # An expired reflog can start with one of the tree's own commits.
        POSITIONS=$(awk '/^[0-9a-f]+ [0-9a-f]+ / && (length($1) == 40 || length($1) == 64) && (length($2) == 40 || length($2) == 64) { if (!found++ && $1 ~ /^0+$/) print "^" $2; if (!seen[$2]++) print $2 }' \
            "$LOG" 2>/dev/null) || return 1
    elif [ ! -x "$ADMIN" ] || { [ -e "$LOG_DIR" ] && { [ ! -d "$LOG_DIR" ] || [ ! -x "$LOG_DIR" ]; }; }; then
        return 1
    fi
    # Stdin avoids the command-line size limit on long reflogs.
    { printf '%s\n' HEAD; [ -z "$POSITIONS" ] || printf '%s\n' "$POSITIONS"; } |
        git -C "$1" rev-list --count --stdin --not --branches --remotes --tags 2>/dev/null
}
if WTS=$(git worktree list --porcelain 2>/dev/null); then
    WT_COUNT=$(printf '%s\n' "$WTS" | grep -c '^worktree ')
    # read every tree; cap only the printed rows, so a tree past the cap is still counted
    # if, not case: bash 3.2 cannot parse case inside $( ), and (pattern) form trips the blueprint danger filter
    ROWS=$(printf '%s\n' "$WTS" | sed -n 's/^worktree //p' | while IFS= read -r WT; do
        if CHANGES=$(git --no-optional-locks -C "$WT" status --porcelain --untracked-files=all 2>/dev/null); then DIRTY=$(printf '%s' "$CHANGES" | grep -c ''); else DIRTY=unknown; fi
        BRANCH=$(git -C "$WT" symbolic-ref -q --short HEAD 2>/dev/null); RC=$?
        if [ "$RC" = 1 ]; then BRANCH="detached HEAD"; AHEAD=$(detached_ahead "$WT") || AHEAD=unknown
        elif [ "$RC" != 0 ]; then BRANCH=unknown; AHEAD=unknown
        elif [ -z "$REMOTES" ]; then AHEAD=-
        else AHEAD=$(git -C "$WT" rev-list --count HEAD --not --remotes 2>/dev/null) || AHEAD=unknown; fi
        [ "$DIRTY" = 0 ] && [ "$RC" -le 1 ] && { [ "$AHEAD" = 0 ] || [ "$AHEAD" = - ]; } && continue
        echo "$WT | $BRANCH | $DIRTY | $AHEAD"
    done)
    NOT_CLEAN=$(printf '%s' "$ROWS" | grep -c '')
    echo "--- worktrees: $WT_COUNT, $((WT_COUNT - NOT_CLEAN)) clean and not listed; path | branch | uncommitted files | commits on no remote ---"
    printf '%s\n' "$ROWS" | head -n "$LIMIT" | grep .
    [ "$NOT_CLEAN" -le "$LIMIT" ] || echo "... $((NOT_CLEAN - LIMIT)) more not clean, not shown: state unknown"
else echo "--- worktrees: unknown, git worktree list failed ---"; fi  # timeout: 30000
```

> Every `git status` passes `--no-optional-locks`: another session may own a listed tree; reading it must not take its index lock. It also passes `--porcelain --untracked-files=all`, so display settings such as `status.showUntrackedFiles` or `status.branch` can neither hide a file nor add a line. A failed read prints `unknown`, never `0` or an empty list. A branch counts commits on no remote. A detached tree counts commits reachable from HEAD or its own HEAD reflog, excluding branches, remotes, tags, and the creation commit and its history. The first valid reflog entry identifies the creation commit only if its old ID is all zeros. A missing reflog counts from HEAD alone. With no remote configured, branch commits are not pending: the branch list says so and a worktree row shows `-`. Every worktree is read, but only one with uncommitted files, commits or an unknown is listed; a tree missing from the list is clean, unless a `... N more not clean, not shown` line follows. Each list prints its total and at most 40 lines; `... N more not shown` marks the rest.

Same turn: call `TaskList`; Read `.claude/state/session/PARKED.md` (skip silently if absent).

Pending items: run **Step 5 / Mode: sweep** detection only — collect its rows; skip its `unlanded.md` Write, its `AskUserQuestion` and any parking. Add:

- background shells, agents, monitors or scheduled wake-ups this session started with no completion seen — never poll them;
- this session's uncommitted files, stash entries and commits on no remote (any local branch, checked out or not, and any detached HEAD), in the current checkout and in every worktree it created or worked in; count other dirty or unpushed worktrees and branches in one line;
- active plans and parked items this session touched or raised; count the rest in one line.

Shared tree: attribute every change by conversation evidence. Changes this session did not make are never its pending work — one line with their count, "not from this session". Owner unprovable → say unknown.

### Substep 7b: Decide the close verdict

First match wins:

| Verdict | When |
| -- | -- |
| **No** | Closing would lose or interrupt something: background work still running or its result unread; a question or approval waiting on an answer; a decision or finding that pending work needs and no file holds. |
| **Yes, with loose ends** | Nothing lost, but work is unfinished and safe on disk: uncommitted edits, unpushed commits, open plan or task with its detail written down. |
| **Yes** | Nothing pending from this session, nothing running, its changes committed. |

- Unknown tree, stash, branch or push state in a checkout this session touched never yields plain **Yes**.
- Changes of unknown owner in a checkout this session touched never yield plain **Yes**.
- Earlier history compacted away in this session never yields plain **Yes**; the reason names what the summary could not confirm, such as background work started or questions asked before it.
- A `... N more not clean, not shown` worktree line makes the state of every unlisted tree unknown: a tree this session worked in may be among them.
- An unknown picks one row: an unknown in a tree or stash holding this session's work → **No**, with checking it by hand as the action; any other unknown, with nothing else pending → **Yes, with loose ends**, naming each unknown.
- No remote configured: commits on a local branch are not pending, so a committed local-only repository can reach plain **Yes**.
- Detached commits flagged by the worktree readout that no branch, remote or tag reaches are loose ends. Worktree sweeps keep the tree. Name putting the commits on a new branch as the next action. Removing the tree by hand can orphan them.
- `TaskList` entries die with the session: an open task recorded nowhere else counts as the third **No** case.
- For **No**, name the action for each cause that makes closing safe (wait for a result, answer a question, `/foundry:session dump`).

### Substep 7c: Print the readout

Plain English for a reader who did not follow the session, even when a terse output style is active: whole sentences, no unexplained shorthand, labels or internal IDs. The closing `## Confidence` block keeps its `quality-gates.md` format; this plain-English rule does not apply to it. All headings, in this order; an empty one says `Nothing.`

```markdown
## Session status

### Purpose
[main theme in one or two sentences; side threads as bullets]

### Accomplished
- [what changed or got done] — [verified by what, or "not verified"]

### Discovered
- [finding and why it matters]

### Still pending
- [open item] — next: [action]; [who it waits on, when not this session]

### Safe to close?
**[No / Yes, with loose ends / Yes]** — [reason]. [what survives on disk, what does not]
```

Group related work into one bullet; never drop a pending item to shorten. Earlier history compacted away → say the readout rests on the summary for that part.

End with a `## Confidence` block per `quality-gates.md` — score on: every accomplished row backed by a conversation turn or disk evidence, unverified work labelled, `TaskList` and git consulted, verdict follows the table.

</workflow>

<notes>

**Why not one command.** A skill cannot invoke `/clear` — Claude Code exposes no programmatic slash invocation (that's Agent SDK `query()` only), and neither keybindings, `UserPromptSubmit`, nor `UserPromptExpansion` can trigger one either. So `dump` + `/clear` stays two steps; the mechanism buys its keep by making the *third* step (restore) automatic.

**Why inline, not forked.** `context: fork` skills can't read conversation history. Files table's `Change` and `State` columns, decisions, lessons, and the whole of `sweep` come from that history — a forked run would have nothing to write.

**Two state mechanisms — they do not overlap.**

| Mechanism | Survives | Trigger | Store |
| -- | -- | -- | -- |
| Skill contract (`compaction.md`) | in-flight skill phase state | auto-compact | `.temp/state/skill-contract.md` |
| Session handover (this skill) | plan, decisions, lessons, files table, open loops | explicit `dump` before `/clear` | `.claude/state/session/` |

**Restore is best-effort, dump is not.** Hook injects only when pointer exists, doc unconsumed, and under 30 minutes old — a deliberately narrow window, so an old dump never ambushes an unrelated session. Everything outside it is reachable by `/foundry:session recall <slug>`, which has no age gate. The four cases landing there: dumped and walked away (>30 min); doc over ~8K chars (hook injects head plus a pointer); fresh terminal rather than a `/clear` (matcher is `clear`); wanting the same doc a second time (first restore set `consumed: true`).

**`recall`, not `resume`.** Claude Code's native `/resume` revives a whole past conversation — strictly better recall than any document. This mode name stays clear of it deliberately; the two aren't alternatives.

**Parking is a command, not a behaviour.** The predecessor made parking an automatic behavioural rule documented only inside this file, which loads only on invocation — so it never fired, and store held zero items for four months. `park` is now an explicit mode with an explicit store. Nothing writes to `PARKED.md` unless user asks for it, no TTL deletes from it.

**Scope**: store is project-local — `.claude/state/session/` lives inside working tree, so nothing leaks across projects.

</notes>

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in data-ai →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.