Skip to content
Back to skills

Session Close

ASecurity

Orchestrate session close — Phase 2 issue close + Final Report. Replaces CLAUDE.md WF-CODE-12. Routes by the recorded delivery path (pull_request, direct) and the WF-META deliverable type.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
toolsgoshellbashnodegit

Works with

  • terminal

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 25, 2026

npx -y skills add nirecom/agents --skill session-close --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Session Close?

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

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

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-close
description: Orchestrate session close — Phase 2 issue close + Final Report. Replaces CLAUDE.md WF-CODE-12. Routes by the recorded delivery path (pull_request, direct) and the WF-META deliverable type.
user-invocable: true
---

Session close orchestrator. Drives `issue-close-finalize` (when applicable),
collects the outcome JSON written by its ICF-K, and emits the Final Report by
substituting the skeleton from `hooks/lib/final-report-schema.renderSkeleton`.
Replaces the legacy "Step 7" emit inside `/worktree-end` so the Final Report
reflects every terminal action.

## Pre-flight

- `AGENTS_MAIN_ROOT` must be set.
- Run `node "$AGENTS_MAIN_ROOT/bin/pm-state" show --session "$CLAUDE_CODE_SESSION_ID"`; when it prints a `tag` (archived included), stop: a PM session has no session-close.
- Caller context (pull_request path): `/worktree-end` WE-1..WE-18a have
  already completed (PR merged, worktree removed; `<CONTROL_DIR>/final-report-env.json` exists).
- Caller context (direct: merge_to_main is complete): `/merge-to-main` pushed to the default branch. No worktree-end
  ran; the env file does not yet exist.

## SC-0 — Resolve PLANS_DIR and session id

Run `bash "$AGENTS_MAIN_ROOT/bin/workflow-plans-dir"` once as one bare command — never assigned to a variable and echoed back. Canonical: `skills/_shared/resolve-plans-dir.md`.

Substitute the absolute path it prints for `<PLANS_DIR>` in every subsequent step.
Resolve `<session-id>` from `$CLAUDE_CODE_SESSION_ID` with the fallback chain used by `--from-session`. If unresolvable, abort:
`session id unresolved — cannot render Final Report`. `<CONTROL_DIR>` is the stdout of `node "$AGENTS_MAIN_ROOT/bin/workflow-control-dir" --session <session-id> --for-write` (non-zero → abort).

`<PLANS_DIR>`, `<CONTROL_DIR>` and `<session-id>` are **LLM-substituted literals** — shell variables
do not persist between Bash tool calls.

## SC-1 — Detect the route

Run:
  node "$AGENTS_MAIN_ROOT"/bin/session-close-detect-route.js --session "<session-id>"

- `ROUTE=wf-meta` → WF-META session. Record `IS_WF_META=yes` as an LLM-tracked state literal (not a shell variable — every Bash call is self-contained). Proceed to SC-2C.
- `ROUTE=pull_request` → worktree path (SC-2A).
- `ROUTE=direct` → direct delivery path (SC-2B).

## SC-2A — Worktree path: reuse existing env JSON

```bash
test -f "<CONTROL_DIR>/final-report-env.json" \
  || { echo "ERROR: env JSON missing — /worktree-end must run first" >&2; exit 1; }
```

Then write the late-finding alert eligibility flag (#997):
  node "$AGENTS_MAIN_ROOT/bin/supervisor-write-alert" --session-id "<session-id>" --set-alert-eligible-phase post_final_report_window
Proceed to SC-3.

## SC-2B — Direct path: build minimal env JSON

Run: `node "$AGENTS_MAIN_ROOT/bin/session-close-build-env.js" --direct --session "<session-id>"` — a missing PR is expected on this path.

Exit 0 → write the late-finding alert eligibility flag (#997):
  node "$AGENTS_MAIN_ROOT/bin/supervisor-write-alert" --session-id "<session-id>" --set-alert-eligible-phase post_final_report_window
Then proceed to SC-3. Non-zero → surface stderr and abort.

## SC-2C — WF-META path: write PR-less env JSON

  node "$AGENTS_MAIN_ROOT"/bin/session-close-build-env.js --wf-meta --session "<session-id>"

Exit 0 → write the late-finding alert eligibility flag:
  node "$AGENTS_MAIN_ROOT/bin/supervisor-write-alert" --session-id "<session-id>" --set-alert-eligible-phase post_final_report_window

Record supervisor notice:
  node "$AGENTS_MAIN_ROOT/bin/supervisor-report" --categories workflow --severity notice --detail "WF-META session: SC-2C path taken — env JSON written with empty PR fields" --reporter session-close

Retain `IS_WF_META=yes` and proceed to SC-3.

## SC-3 — Non-GitHub pre-flight + issue close dispatch

If `IS_WF_META=yes` (set in SC-2C): write `skipped_wf_meta` outcomes directly:

  node "$AGENTS_MAIN_ROOT"/bin/issue-close-write-outcome.js --wf-meta '<ISSUES_JSON_ARRAY>' "<CONTROL_DIR>/issue-close-outcome.json"

`<ISSUES_JSON_ARRAY>` is the JSON number array the LLM parses from intent.md via `hooks/lib/parse-closes-issues.js`, inlined as a literal. When intent.md is absent, use `'[]'`.

Then skip directly to SC-6. WF-META skips `is-github-dotcom-remote` and never invokes `/issue-close-finalize` — `skipped_wf_meta` is written regardless of remote type.

If `IS_WF_META` is unset or `no`: proceed with the `is-github-dotcom-remote` check below.

```bash
bash "$AGENTS_MAIN_ROOT/bin/is-github-dotcom-remote"; echo "NON_GITHUB_RC=$?"
```

- Non-zero → non-GitHub remote. Write skipped outcomes (pass `'[]'` when
  `closes_issues` is empty), then skip to SC-6:

```bash
node "$AGENTS_MAIN_ROOT/bin/issue-close-write-outcome.js" \
  --non-github '<ISSUES_JSON_ARRAY>' \
  "<CONTROL_DIR>/issue-close-outcome.json"
```

`<ISSUES_JSON_ARRAY>` is the JSON number array printed by
`node "$AGENTS_MAIN_ROOT/bin/parse-closes-issues" --session <session-id>`, inlined as a literal at substitution time.

- Zero → GitHub remote. Read `closes_issues` from
  `node "$AGENTS_MAIN_ROOT/bin/parse-closes-issues" --session <session-id>`.
  - `[]` → write empty outcome, skip to SC-6:

```bash
node "$AGENTS_MAIN_ROOT/bin/issue-close-write-outcome.js" --session "<session-id>" --empty
```

  - non-empty → SC-3a.

## SC-3a — Invoke /issue-close-finalize via the Skill tool

Invoke `/issue-close-finalize --from-session`. The sub-skill writes
`<CONTROL_DIR>/issue-close-outcome.json` in its ICF-K.

If it terminates without writing that file, write a synthetic fallback; `<INTENT_MD>` is the output of `node "$AGENTS_MAIN_ROOT/bin/plan-artifact-path" --step clarify_intent --session "<session-id>"`:

```bash
node "$AGENTS_MAIN_ROOT/bin/issue-close-write-outcome.js" \
  --fallback "<INTENT_MD>" \
  "<CONTROL_DIR>/issue-close-outcome.json"
```

## SC-4+SC-5 — Retrospective scan + Pre-Final-Report gate

Dispatch the `session-close-gate` worker per `skills/_shared/worker-dispatch.md`. Payload:
- `session_id`: current session ID (resolved per SC-0)
- `plans_dir`: the `PLANS_DIR` from WD-1 — do NOT reuse the `<PLANS_DIR>` literal from SC-0, which was resolved with a fallback
- `artifact_dir`: same value as `plans_dir`
- omit `outcome_json_path` — the dispatcher derives it in the session control directory

On `status: failed`: emit `supervisor-report` warning and **STOP**. Do NOT proceed to SC-6. User must manually re-run `/session-close`. This path is fail-closed — SC-6 never runs on worker failure.

On `status: complete`:
1. Read `gate_action` from `artifact_path` (gate JSON).
2. **Always** emit `echo "<<WORKFLOW_MARK_STEP_pre_final_report_gate_complete>>"`.
3. `gate_action: yield` → **STOP** after sentinel. SC-6 does not run. Supervisor review runs later.
4. `gate_action: proceed` → continue to SC-6.

## SC-6 — Emit Final Report directly into assistant text

Run: node "$AGENTS_MAIN_ROOT/bin/render-final-report.js" --session "<session-id>"
Write the stdout into your next assistant text per `skills/_shared/final-report-emission.md` — emission, verbatim scope, and CONV_LANG scope are defined there.

After emitting, mark completion with two separate Bash calls:
  bash "$AGENTS_MAIN_ROOT/skills/session-close/scripts/close-alert-phase.sh" "<session-id>" "<NOTES_BACKUP_PATH>"
  echo "<<WORKFLOW_MARK_STEP_final_report_complete>>"

`stop-final-report-guard.js` blocks (exit 2) when any of the 13 headings or any unsubstituted `<TOKEN>` is missing/present after `## Final Report — <session-id>`.

## SC-6a — Notify the issues' PM (#2942; fail-open)

1. Run `node "$AGENTS_MAIN_ROOT"/bin/pm-notify record --point session-close --issue <ref>` once per `closes_issues` ref (empty → the workflow state's issue).
2. Send it and every pending notification per `skills/_shared/pm-notify.md`.
3. Run `node "$AGENTS_MAIN_ROOT"/bin/pm-notify close`; show its lines to the user as-is.

## SC-7 — Surface alert findings (post-Final-Report)

Read `<CONTROL_DIR>/supervisor-state.json` (Read tool). If absent, or `alert.findings` is empty, or `alert.findings_surfaced_at` is already set, skip to SC-7a.

Run:
  node "$AGENTS_MAIN_ROOT/bin/session-close-render-sc7.js" --session "<session-id>"

When the render is non-empty: emit the text verbatim into the assistant reply (no preamble, no wrapping).

Mark surfaced:
  node "$AGENTS_MAIN_ROOT/bin/supervisor-write-alert" --session-id "<session-id>" --mark-findings-surfaced

## SC-7a — PM completion report (post-Final-Report)

Run `node "$AGENTS_MAIN_ROOT/bin/pm-instructions" --timing after-final-report` and follow non-empty stdout; on a non-zero exit show its stderr line and continue.

## SC-8 — Promote residual WORKTREE_NOTES entries (post-Final-Report)

- Runs after the Final Report is emitted, only when unpromoted entries remain (`/worktree-end` WE-7 normally clears them): resolve the notes path via `node "$AGENTS_MAIN_ROOT/bin/worktree-notes-triage.js" resolve --caller session-close --session-id "<session-id>"`; on `action: skip` return, otherwise run `skills/_shared/notes-promotion.md` (NP-1..NP-11) against the returned `notesPath`.

## SC-9 — Relocate legacy session state (temporary, #2511)

Run last, once: `bash "$AGENTS_MAIN_ROOT/skills/session-close/scripts/relocate-session-state.sh" "<session-id>"` (always exits 0; the script reports a failure itself).

## SC-10 — Migrate every orphan progress file of this session chain (temporary, #2748)

Run once after SC-9: `bash "$AGENTS_MAIN_ROOT/skills/session-close/scripts/migrate-own-session-chain.sh" "<session-id>"` (always exits 0; the script reports a failure itself).

## Rules

- Orchestrates only — never modifies workflow state directly.
- `/issue-close-finalize` is invoked via the Skill tool only (never `bash`/`spawnSync`).
- Non-GitHub remotes never invoke `/issue-close-finalize`; outcomes written by SC-3.
- Empty `closes_issues` → skip `/issue-close-finalize`, write `{"issues":[]}`, emit Final Report.
- `/issue-close-finalize` failures surface in outcome JSON; renderer still runs (non-blocking).
- Every Bash call is self-contained — no shell variable crosses call boundaries.
- On fallback or step degradation (synthetic outcome fallback, non-GitHub skip path): run `node "$AGENTS_MAIN_ROOT/bin/supervisor-report" --categories workflow --severity warning --detail "<describe fallback>" --reporter session-close` (session-id auto-resolves).
- Report observations via /supervisor-report (trigger conditions: rules/supervisor-reporting.md).
- WF-META session (`deliverable_type: wf-meta`) → never invoke `/issue-close-finalize`; SC-3 writes `skipped_wf_meta` outcome directly and skips to SC-6.

Files in this skill

  • SKILL.md9.7 KB
  • scripts/close-alert-phase.sh1.9 KB
  • scripts/migrate-own-session-chain.sh1.5 KB
  • scripts/relocate-session-state.sh1.5 KB

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 tools →

Comments

Loading comments…

Newsletter

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