From session-flow
Write a mid-session save-point for /clear-and-resume — a durable handoff file (default) or a copy-paste resume prompt when follow-ups are small. Pass --bg to hand the resume prompt to a fresh background agent instead of pasting it yourself. Use when: 'handoff', 'save state', 'checkpoint this', 'pause', 'come back later', 'continue in the background', context is heavy, or quality is degrading.
How this skill is triggered — by the user, by Claude, or both
Slash command
/session-flow:handoff [file|prompt] [topic] [--bg] (e.g., /handoff, /handoff prompt, /handoff file phase-3, /handoff --bg)[file|prompt] [topic] [--bg] (e.g., /handoff, /handoff prompt, /handoff file phase-3, /handoff --bg)The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Current branch: !`git branch --show-current 2>/dev/null || echo "unknown"`
Current branch: !git branch --show-current 2>/dev/null || echo "unknown"
Claude session: !echo "${CLAUDE_CODE_SESSION_ID:-unknown}"
Uncommitted changes: !git status --porcelain 2>/dev/null | head -20 || echo "clean"
Recent commits: !git log --oneline -5 2>/dev/null || echo "no commits"
Context bloat is expensive and quality degrades as context rots. When a task has room left but
context is heavy, capture a save-point — a handoff document, or just a copy-paste resume prompt when
follow-ups are small — and /clear.
Based on the canonical pattern Anthropic recommends for the /clear workflow: put the rest of the
plan in a handoff file; explain what you tried, what worked, and what didn't, so the next agent with
fresh context can load that file and nothing else. The save-point captures a snapshot of in-flight
state — including what was tried and ruled out — so the next session doesn't waste effort
rediscovering dead ends.
Handoffs are memory-tier save-points, concern-scoped by session — resolve the destination through
the plugin binding (${CLAUDE_PLUGIN_ROOT}/reference/topic-docs.md).
A consumer-declared convention (the .claude/topic-docs.yaml concern file, or a save-point
convention in CLAUDE.md / .claude/rules/) wins; otherwise default to
<memory_dir>/handoffs/ (default .work/handoffs/) — files named <TS>-handoff-<topic>.md
with TS = date -u +%Y%m%dT%H%M%SZ (ISO basic, Windows-safe, sortable). On the session's first
memory-tier write, verify the resolved memory root's .gitignore exists and contains * — create
it (announced) when absent; never edit the consumer's root .gitignore.
$ARGUMENTS carries [file|prompt] [topic] [--bg] — all optional; method and topic positional:
file | prompt) — recognized ONLY as the first token. file forces the full
durable handoff; prompt forces prompt-only. Omitted → auto-detect (see "Choosing the path")./handoff phase-3); with a method present it is the second token. Omitted → inferred
from context.--bg — flag, recognized anywhere in the argument string; strip it before reading the
positionals. After the save-point is produced, launch a fresh background agent seeded with the
resume prompt instead of relying on the user to /clear-and-paste. See "Background-agent launch
(--bg)".The whole point of /handoff is /clear + fresh-session resume. The skill produces the
save-point, THEN STOPS. It does NOT keep executing the underlying task in the current session; that
defeats the purpose. STOP is the default and near-universal outcome — NEVER unlocked by the user
having listed multiple steps, nor by the remaining work being "small".
Mandatory STOP gate (walk every box):
/clear-then-paste instruction surfaced to the user — with --bg, replaced by the launch
report per "Background-agent launch (--bg)"--bg does not relax this: the background agent
is the continuation, and this session neither monitors nor babysits itNOT authorization to continue (these all STOP):
/handoff (e.g. "handoff, then verify, then PR") → the listed steps
run in the FRESH session AFTER /clear. Naming /handoff names a /clear boundary, not a waiver/handoff
between them still enforces its /clear boundary (that is WHY the handoffs get written)/handoff → always STOP, regardless of surrounding instructionsThe only exception: the user's prior turn used explicit stay-in-session language about handoffs
specifically (e.g. "don't /clear between phases, keep going").
/context output or user report)--bg so a background agent resumes itTwo ways to keep going past a heavy context: fork (handoff file + /clear + fresh session) or
continue in place over a compacted history. Compaction suits an intentional break between phases
while the window is still mostly fresh — the summarized turns were genuinely disposable. Once the
session has consumed enough of its context window that reasoning quality degrades — roughly beyond
the final third of the window — fork instead: a handoff file carries forward exactly the state that
matters, chosen deliberately, while a compaction summary carries forward whatever the summarizer
happened to keep, and the degradation that prompted the move rides along into the continued
session. Judge the threshold by window position and response quality, never by a fixed token count
— it shifts with model and configuration.
Before emitting anything, establish where the work stands: if a plan or checklist artifact backs
the work (see the sibling workflow skill), read it THIS turn and name the next unfinished stage —
the resume prompt points at the next stage, not just "continue here". Ground every status claim in
a fresh read, never a prior session's assertion. With no plan artifact, name the next concrete
action from the conversation.
A resume prompt is ALWAYS emitted. The only decision is whether to ALSO write a durable handoff
file. Full handoff = prompt + file (prompt @-references the file); prompt-only = the same prompt
carrying its detail inline, no file.
Default: write the file. Skip it only when NO plan artifact backs the work AND all of these clearly hold:
ANY doubt → full handoff. A wrongly-skipped file loses state the fresh session must rediscover; a
wrongly-written one costs nothing. The explicit method argument overrides auto-detect — but note
prompt leaves a gap in the session-id chain that /retro walks (no file, no chain pointer).
Before writing the handoff file or emitting the resume prompt, sweep everything outbound — body
sections, TaskList snapshot, frontmatter, and the prompt between the rails — for secrets, API keys,
tokens, credentials, connection strings, and PII, and redact each hit with a shape marker
(<REDACTED: API key>), never the value. Handoff output outlives the session: it sits on disk
uncommitted-but-readable, travels to other sessions and machines, and gets read in contexts the
current conversation never anticipated. A value acceptable to see in-session is not acceptable to
persist. This pass gates the write — no artifact or prompt is emitted before it runs.
The document structure (eight body sections — Task / Progress / Decisions made / Files modified /
Tried and ruled out / Open questions / Suggested skills / Files to review), the TaskList snapshot +
reconstitute format, and the frontmatter shape (including the session_id / previous_handoff /
previous_session_id chain fields that /retro walks) live in context/structure.md — walk it
while writing the file.
When the target file already exists on disk (extending an earlier turn's write), re-read it from disk immediately before writing and append to it — never rewrite the whole file from the in-context copy, which goes stale the moment disk moved on without this conversation seeing it.
Copy-region clarity (both paths) — two dashed rails, no fence:
─ (U+2500) rails — top rail, prompt, bottom rail. Use
literal ─, NOT markdown --- (turns the adjacent line into a heading) and NOT a code fence
(the user copies the text between the rails, not fence markers)./clear, then copy everything
between the dashed lines."/goal is active this session (infer from conversation), the FIRST
line between the rails starts with literal /goal — /clear destroys an active goal, so the
pasted block must re-arm it. When unsure, omit it and note below the bottom rail: "if a goal was
active, prepend /goal <condition>."Full-path shape (minimum form — live: bare ─ rails, no fence; shown inside a fence here for
display):
`/clear`, then copy everything between the dashed lines:
──────────────────────────────────────────────────────────
Read @<handoffs-dir>/<TS>-handoff-<topic>.md and continue per its "Open questions / next steps".
Prior session: <UUID>.
──────────────────────────────────────────────────────────
<handoffs-dir> is the path the write step actually used — the resolved
<memory_dir>/handoffs/ (default .work/handoffs/). Never emit a
default the file was not written to.
When the next stage is a specific skill in the consuming repo, swap the directive to
Read @… and execute /<skill>. The @-reference is mandatory on the full path — the fresh session
loads it; do NOT inline the file's detail in the prompt. Prompt-only carries its remaining-work
bullets inline between the rails instead.
<UUID> = this session's $CLAUDE_CODE_SESSION_ID (the frontmatter session_id) — it lets a
fresh session or /retro chain-walker locate the transcript later.
--bg)Honored ONLY when the user explicitly passed --bg — never self-elected, including when this
skill is model-invoked. Composes with BOTH paths: the launched agent receives exactly the resume
prompt that sits between the rails (full path: it follows the prompt's Read directive to the
handoff file; prompt-only: the remaining-work bullets travel inline).
Sequence — the rails prompt from "Final step" is still emitted FIRST (transparency + manual fallback), then:
Dirty-tree gate. Run git status --porcelain -uall in the consuming project (-uall
lists files inside untracked directories individually; the default collapses a brand-new
handoff directory into one directory entry, which both defeats the exemption below and can
hide other dirt behind it) and IGNORE save-point files under the handoff location — the
just-written one AND any prior sessions' (this skill never commits them; they are
session-chain artifacts, part of the launch rather than disqualifying dirty state; the
background session starts in this working directory, so it reads the handoff file before any
edit moves it into a worktree). Background sessions move into an isolated git worktree (a
fresh checkout) before editing files (https://code.claude.com/docs/en/agent-view), so OTHER
uncommitted changes in this checkout would NOT carry into the launched agent's edits. Any
such changes → do NOT launch: report why and fall back to the standard /clear-then-paste
instruction (same checkout, dirty state intact), noting the user can commit or stash and
re-run /handoff --bg. Exception: launch anyway when the current session already runs inside
a linked git worktree — isolation is skipped there per the same page.
Launch from the consuming project's root, passing the rails prompt verbatim as one argument.
<topic> = the resolved topic slug (argument or inferred); when none resolves, use resume:
cd "${CLAUDE_PROJECT_DIR}" && CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1 claude --bg --name "handoff-<topic>" "$(cat <<'HANDOFF_RESUME_PROMPT_END'
<resume prompt exactly as emitted between the rails>
HANDOFF_RESUME_PROMPT_END
)"
claude --bg starts the session as a background agent and returns immediately; the user
manages it with claude agents. The launched agent is a NEW session: it inherits none of the
current session's CLI configuration (e.g. --mcp-config, --settings, --add-dir,
--plugin-dir) — mirror onto the launch command any such flags the resumed work depends on,
and say so in the launch report. CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1 is required
because this launch runs from a Bash-tool subprocess, which carries
CLAUDE_CODE_CHILD_SESSION=1 — nested sessions are otherwise excluded from the
claude agents list (https://code.claude.com/docs/en/env-vars). The heredoc sentinel is
deliberately unique — a bare EOF line inside a freeform resume prompt would terminate a
plain <<'EOF' heredoc early and silently truncate the prompt. Awareness note: the prompt
travels in the process argument list, so it is briefly visible to other local processes
(ps) — inherent to claude --bg "<prompt>". The mandatory redaction pass has already
scrubbed the prompt by this point; this exposure is one more reason secrets never belong in
handoff output on ANY path.
Report the launch result: the command's output, the agent name, and the claude agents
management hint. Swap the /clear-then-paste instruction for this report — the user no longer
needs to paste anything.
Launch failure → fall back, never block. Non-zero exit (e.g. the installed Claude Code
predates --bg) → report the error and fall back to the standard /clear-then-paste
instruction. The save-point already exists; nothing is lost.
STOP is unchanged. The background agent is the continuation; this session still terminates the task per the hard rule. Do not monitor, poll, or babysit the launched agent.
Tick each item in the response so the user can verify the exit shape. Missing any tick = handoff
incomplete. Known failure patterns live in context/gotchas.md — load on demand when a step feels
ambiguous.
Full path:
context/structure.mdprevious_handoff + previous_session_id present IF this session continued a prior
handoff's task (chain continuity per context/structure.md); omitted otherwise — including when
the directory holds only unrelated-task handoffs@-referencing the file; copy instruction above
the top rail; /goal first line if a goal is activePrompt-only path:
prompt explicitly passed)/goal first line if a goal is active/clear and finish in-session"Either path with --bg (additional):
git status --porcelain -uall this turn, ignoring save-point
files under the handoff location); other uncommitted changes without the linked-worktree
exception → no launch, reason reported, fallback to /clear-then-pasteclaude --bg --name …) and the launch
result reported — OR the non-zero exit reported with fallback to /clear-then-paste/clear — the user types /clear. The skill produces the save-point, emits
the resume prompt, and stops--bg launch happens only when the user
passed the flag; the default exit is always the copy/paste promptnpx claudepluginhub melodic-software/claude-code-plugins --plugin session-flowCreates, edits, and verifies skills using a test-driven development approach with pressure scenarios and subagents.