Course correction. Revisit any planning artefact, surgically amend it, and cascade changes through downstream documents. Triggers on "/cpm:pivot".
Revisit any planning artefact (problem brief, product brief, ADR, spec, or epic), make surgical edits, and walk downstream documents through guided updates. Pivot is lighter than re-running the original skill — amend what exists rather than starting over.
Check for input in this order:
$ARGUMENTS is a file path (e.g. docs/plans/01-plan-auth.md), use that as the target document. Skip artefact chain discovery — go straight to the amendment workflow.State tracking: Before starting Step 1, create the progress file (see State Management below). Each step below ends with a mandatory progress file update — do not skip it. After completing the workflow (or exiting early), delete the file.
Discover existing planning artefacts and their relationships. Skip this step if $ARGUMENTS provided a direct file path.
Glob all five planning directories:
docs/plans/[0-9]*-plan-*.md (problem briefs from cpm:discover)docs/briefs/[0-9]*-brief-*.md (product briefs from cpm:brief)docs/architecture/[0-9]*-adr-*.md (ADRs from cpm:architect)docs/specifications/[0-9]*-spec-*.md (specs from cpm:spec)docs/epics/[0-9]*-epic-*.md (epics from cpm:epics)Build dependency chains: For each document found, read the first 10 lines and look for back-reference fields:
**Source**: — may contain a path to a problem brief.**Source**: — may contain a path to a product brief or problem brief.**Brief**: — may contain a file path to a problem brief or product brief, or a description. Only treat it as a chain link if the value is a valid file path that exists on disk.**Source spec**: — a file path to the source spec. Verify the file exists before treating it as a chain link. Multiple epic docs may share the same source spec (1:many).The full cascade chain is: problem brief → product brief → ADRs → spec → epics. Not every chain will have all levels. Use verified file-path references to group documents into chains.
Fall back to slug matching: When back-references are missing, contain descriptions instead of file paths, or don't resolve to existing files, match documents by slug. Extract the slug from the filename (the part after the number-prefix and type — e.g. auth from 01-plan-auth.md, pivot from 05-spec-pivot.md) and group documents with the same slug into a chain.
Handle partial chains: Not every chain will be complete. A spec without a brief, or epics without a spec, are valid — present what exists.
Present to user: Show the discovered chains and individual documents. Use AskUserQuestion to let the user select which document to amend. Group by chain where possible, list orphan documents separately.
Update progress file now — write the full .cpm-progress-{session_id}.md with Step 1 summary before continuing.
Read and amend the selected document.
Read the document: Read the selected file with the Read tool. Present a brief summary of its contents to the user — key sections, overall structure, what it covers.
Gather changes: Ask the user what they want to change. They describe modifications in natural language — additions, removals, rewording, structural changes. Use AskUserQuestion or direct conversation.
Apply edits: Use the Edit tool to make surgical changes to the document. Multiple edits are fine — apply them one at a time. Do NOT use the Write tool for amendments — Edit only, to minimise risk of accidental content loss.
Save immediately: Each Edit call saves to disk immediately. No content is held only in memory.
Present change summary: After all edits are applied, present a clear summary:
Update progress file now — write the full .cpm-progress-{session_id}.md with Step 2 summary before continuing.
Walk downstream documents and facilitate updates. Skip this step if no downstream documents exist.
Before walking the cascade, check whether all downstream epic documents are fully complete:
Detect completion: For each downstream epic doc, scan for completion markers — [x] checkboxes on all story tasks, or **Status**: fields containing "done" or "complete" (case-insensitive). An epic is fully complete when every story within it is marked complete.
All epics complete — ask intent: If every downstream epic is fully complete, the user is pivoting a spec whose work has already been delivered. Use AskUserQuestion to determine intent:
cpm:epics with the amended spec as input, generating fresh epic docs for the new work.cpm:spec with the amended spec as input context. Only offer this option when the amended document is a spec (not a brief or ADR).If the user chooses "Pivot forward", save the progress file, then tell the user to run /cpm:epics {amended-spec-path} to generate new epics. If the user chooses "Raise a new spec", save the progress file, then tell the user to run /cpm:spec {amended-spec-path} to create a new specification. In both cases, proceed directly to Step 4 (skip the cascade walk below).
Partial or no completion: If some epics are incomplete, or completion markers are absent, proceed with the normal cascade below. Individual story completion is handled per-story during the walk.
Identify downstream documents: Using the chain discovered in Step 1 (or built from the direct file path), find documents that depend on the one just amended:
Walk in dependency order: Process downstream documents one at a time, starting with the closest dependency (spec before epics).
For each downstream document:
a. Read the document with the Read tool.
b. Detect per-story completion: For epic documents, check each story for completion markers — [x] on all task checkboxes, or a **Status**: field containing "done" or "complete" (case-insensitive). If neither marker is present, treat the story as in-progress.
c. Compare against the upstream changes made in Step 2. Identify sections that are affected — requirements that reference changed scope, epic stories that implement changed requirements, etc.
d. Flag completed stories: When proposing a change to a story that is marked complete, prepend a visible warning: "⚠️ This story is marked complete — editing it changes the record of delivered work." This gives the user clear context for their apply/skip decision.
e. Propose specific updates with clear rationale for each. Explain what changed upstream and how it affects this section.
f. Gate each proposed change with AskUserQuestion:
Preserve upstream work: If the cascade fails midway (user exits, error occurs), all already-saved upstream edits are preserved — they were written to disk immediately in Step 2.
Graceful skip: If no downstream documents exist, skip this step entirely and proceed to Step 4.
Coverage matrix invalidation: After applying changes to an epic doc, check for a companion coverage matrix at docs/epics/{nn}-coverage-{slug}.md (same number and slug as the epic). If it exists and the cascade modified any story acceptance criteria in the epic doc, read the coverage matrix and clear the ✓ from the Verified column for rows whose "Story Criterion (verbatim)" text was changed by the cascade. Rows whose criteria were not modified retain their ✓ status. Use the Edit tool to replace | ✓ | with | | for affected rows. If no coverage matrix exists, skip this step.
Update progress file now — write the full .cpm-progress-{session_id}.md with Step 3 summary before continuing.
Identify tasks that may be affected by the changes. Skip this step if no tasks exist or if no epic doc was changed.
Check preconditions: Call TaskList to see if any tasks exist. If none, skip this step. Also skip if the cascade in Step 3 didn't touch any epic doc (changes to briefs/specs that didn't cascade to epics won't affect tasks).
Match affected stories to tasks: For stories that were changed in Step 2 or Step 3:
**Task ID**: {id} fields in the epic doc and match against task IDs from TaskList.### {subject}) against task subjects.Present the list: Show the user which tasks may be affected by the pivot, with a brief note on what changed in the corresponding story. Do NOT automatically modify any tasks — present the information and let the user decide what action to take.
Graceful skip: If no tasks are matched, or if no epic stories were modified, skip this step silently.
Update progress file now — write the full .cpm-progress-{session_id}.md with Step 4 summary, then delete the progress file.
Maintain docs/plans/.cpm-progress-{session_id}.md throughout the session for compaction resilience. This allows seamless continuation if context compaction fires mid-conversation.
Path resolution: All paths in this skill are relative to the current Claude Code session's working directory. When calling Write, Glob, Read, or any file tool, construct the absolute path by prepending the session's primary working directory. Never write to a different project's directory or reuse paths from other sessions.
Session ID: The {session_id} in the filename comes from CPM_SESSION_ID — a unique identifier for the current Claude Code session, injected into context by the CPM hooks on startup and after compaction. Use this value verbatim when constructing the progress file path. If CPM_SESSION_ID is not present in context (e.g. hooks not installed), fall back to .cpm-progress.md (no session suffix) for backwards compatibility.
Resume adoption: When a session is resumed (--resume) or context is cleared (/clear), CPM_SESSION_ID changes to a new value while the old progress file remains on disk. The hooks inject all existing progress files into context — if one matches this skill's **Skill**: field but has a different session ID in its filename, adopt it:
docs/plans/.cpm-progress-{current_session_id}.md with the same contents.rm docs/plans/.cpm-progress-{old_session_id}.md.
Do not attempt adoption if CPM_SESSION_ID is absent from context — the fallback path handles that case.Create the file before starting Step 1 (ensure docs/plans/ exists). Update it after each step completes. Delete it only after all amended artifacts have been confirmed written — never before. If compaction fires between deletion and a pending write, all session state is lost.
Also delete docs/plans/.cpm-compact-summary-{session_id}.md if it exists — this companion file is written by the PostCompact hook and should be cleaned up alongside the progress file.
Use the Write tool to write the full file each time (not Edit — the file is replaced wholesale). Format:
# CPM Session State
**Skill**: cpm:pivot
**Step**: {N} of 4 — {Step Name}
**Target document**: {path to document being amended}
**Chain**: {brief → spec → epics paths, or "single document"}
## Completed Steps
### Step 1: Artefact Chain Discovery
{Summary — chains found, document selected for amendment}
### Step 2: Surgical Amendment
{Summary — what was changed, downstream implications identified}
### Step 3: Cascading Update Facilitation
{Summary — which downstream docs were updated, which changes were applied/skipped}
### Step 4: Task Impact Flagging
{Summary — affected tasks identified, user decisions}
{...include only completed steps...}
## Next Action
{What to do next}