Clean stop

From melodic-software/claude-code-plugins · View interactive version

Clean stop is an AI agent skill from the GitHub repository melodic-software/claude-code-plugins. Clean stop before the machine goes away: sweep every repo and worktree touched for uncommitted, unpushed or PR-less work, push it, and give a free-and-clear verdict. Use when: 'clean stop', 'safe to shut down', or stopping for the day. Gates destructive cleanup.

How to use this skill

Skill file

Clean stop

Purpose

Before a machine may disappear (end of day, a reclaimed spot instance, a torn-down

container, walking away), sweep everything touched this session to a durable,

linked resting state and report whether it is genuinely safe to shut down.

/session-flow:keep-going recovers a session after an interruption; clean-stop

makes the interruption safe beforehand. It supersedes a local

/session-flow:handoff when the machine itself may go away: a handoff file dies

with the disk, so clean-stop leaves the resumable state in the PR and issue

bodies on the remote.

Arguments

--unattended is the only argument: the caller declares that nobody is present. It only gates the

/export step (dropped: an unattended run neither suggests nor runs a user-only built-in); remote artifacts are always created

without prompting, as step 3 states. Take it out wherever it appears; other text is context for the

sweep. The bare word unattended is not this flag: stop and name --unattended.

Steps

  1. Inspect first, never assume. Enumerate every repository and worktree

this session touched and read its real state: uncommitted changes,

stashes, unpushed commits, branches without a PR, which PRs/issues already

carry the resumable context, and any ignored, machine-local state that is

not reproducible, a generated handoff, local config, hand-made

credentials, which git status hides but which dies with the disk just

the same. Act only on the gaps. Running

clean-stop when a branch is already pushed and its PR already describes the

work must not re-push, open a duplicate PR, or re-file issues. The sweep

converges on what is missing, not on redoing what is done.

  1. Durability sweep. Make the gaps durable. Push unpushed commits; for

coherently committable work, including a clean, coherent stash, commit

it with a real message and push. What is not coherently committable,

ambiguous work-in-progress, a half-edit, a stash that will not cleanly

apply, is not force-committed and not silently dropped: surface it in the

verdict as an explicit "not durable, do X before shutdown" item. A bad

commit and a lost stash are both worse than a named dangling item. Ignored,

machine-local state that must not go to the remote, secrets, credentials,

deliberately-ignored files, is never pushed; when it is not reproducible,

surface it as a "preserve off the machine before shutdown" item so it is

not silently lost with the disk.

The conversation itself is another machine-local, non-durable item:

transcripts live only in this machine's ~/.claude tree and are

retention-swept besides (pointer:

All settings § cleanupPeriodDays).

When the session is worth keeping:

If /export is available in your session (gate basis: Verification record: /export below), suggest that the person run it for a durable conversation copy at <memory_dir>/exports/<YYYYMMDDTHHMMSSZ>-<topic>.txt after verifying the memory root's self-ignore guard (a .gitignore containing *; create it and announce it when absent). This skill never invokes /export itself. --unattended: make no suggestion.

That destination is machine-local, so when the machine may go away, also

surface copying the export off the machine as a "preserve off the machine" item.

  1. Linkage + breadcrumbs (redact before any remote write). Before a PR

or issue body is created or updated, sweep everything outbound: remaining

tasks, dependencies, resume context, any pasted terminal output or diffs,

for secrets, API keys, tokens, credentials, connection strings, and PII,

and replace each hit with a shape marker (<REDACTED: API key>), never the

value. This scrub is a hard gate: the breadcrumbs land on a remote shared

with others and pass no human review first, so nothing outbound is written

before it runs. Then link the work: every pushed non-default branch gets

a PR. A branch that is the repo's default (main / master / trunk, or

whatever git symbolic-ref refs/remotes/origin/HEAD resolves to) carries

no PR and needs none once pushed. Every follow-up gets filed as an issue

linked to that PR; dependencies, remaining tasks, and the context needed to

continue live in the PR and issue bodies, never only in a local file. The

acceptance bar is a cold agent: someone who finds the PR or issue with no

memory of this session should have everything needed to offer to continue.

Every remote artifact is created unattended, so the issue-linkage decision

is made up front, never left for an interactive prompt: use the closing

keyword when the branch or context names an issue, otherwise an explicit

no-linkage reason. For an orphan branch, a hotfix, refactor, or drift

sweep with no issue in its name, open the PR with the forge's own tooling,

passing that no-linkage reason, the title, and the body non-interactively:

the guaranteed non-interactive path. Route through

/source-control:pull-request create (if enabled) or a

work-item capability only when it can run unattended with that decision

passed in; if it would stop to ask, use git and the forge's own tooling

carrying the same decision instead.

  1. Local hygiene. Prune only what is provably safe: branches whose work is

fully merged, worktrees with no uncommitted or stashed state and no

irreplaceable ignored files, background work that has genuinely finished.

Before removing a worktree, inspect its ignored content explicitly

(git status --ignored) and preserve or surface anything not

reproducible: a local .env, credentials, generated handoff data, or files

a bootstrap copied in. When checking what plain git status lists and

what git worktree remove refuses or deletes, read

git-status CODE0

and git-worktree CODE0

live. Anything still holding unmerged commits, dirty state,

irreplaceable ignored files, or a running job is not pruned. It becomes a

named item in the verdict.

  1. Free-and-clear verdict. Lead the report with one of two honest

outcomes: "clean to shut down, everything durable and linked", or a named

list of the dangling items that still need a hand, each with the one

action that would clear it; what was pushed, opened, and filed follows.

Never report clean while step 2 or 4 left something surfaced.

Autonomy policy. Make durable freely, gate destructive cleanup

pushed branch, and filing a linked follow-up issue are loss-prevention with

low blast radius and are the whole point of the invocation: do them once

the step 3 redaction gate has scrubbed anything outbound. Idempotency comes

from step 1: act on gaps, never re-fire what already landed.

force operation is irreversible. Do it only when step 1 proved it safe

(fully merged, no uncommitted or stashed state, and, for a worktree, no

irreplaceable ignored files a plain status hides). When safety cannot be

proven, do not prune; name the item in the verdict instead. Losing unmerged

work, or the only copy of an ignored .env, to a tidy-up is the exact

failure this skill exists to prevent.

Nothing-dirty case

If the sweep finds everything already durable and linked, nothing

uncommitted, nothing unpushed, every non-default branch that carries session

work has a PR (work committed straight to the default branch is durable once

pushed and needs none), nothing strandable left only on local disk, including

non-reproducible ignored state a plain status hides, say so and give the

free-and-clear verdict directly. A clean session is a valid, common outcome;

do not manufacture work to look thorough.

Verification record: `/export`

What this skill does not do

worktree work to whatever capabilities are installed and falls back to

git and the forge's or tracker's own tooling; it does not reimplement them.

Related

Gotchas

strand its context if no PR or issue carries the why and the next step. The

durability sweep and the breadcrumb bar are two separate checks; passing the

first does not pass the second.

stashes explicitly; each one is either converted to a durable commit or

named in the verdict, never left to die with the machine.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.