cancel
Cancel any active OMC mode (autopilot, ralph, ultragoal, swarm, ultrapilot, pipeline, team) and clean up retired legacy state
By yeachan-heo · 696 installs
npx skills add yeachan-heo/oh-my-claudecode --skill cancel
Source repository · Upstream listing
Cancel Skill
Intelligent cancellation that detects and cancels the active OMC mode.
The cancel skill is the standard way to complete and exit any OMC mode.
When the stop hook detects work is complete, it instructs the LLM to invoke
this skill for proper state cleanup. If cancel fails or is interrupted,
retry with force flag, or wait for the 2 hour staleness timeout as
a last resort.
What It Does
Automatically detects which mode is active and cancels it:
Autopilot : Stops workflow, preserves progress for resume
Ralph : Stops the persistence loop
Legacy Ultrawork state : Cleanup only removal for upgraded installations; it is not an active workflow
UltraQA (retired) : No live workflow remains; clears stale pre 5.0.0 ultraqa state.json if present
Ultragoal : Clears the session scoped ultragoal runtime guard ( .omc/state/.../ultragoal state.json ) so PreToolUse /goal enforcement and Stop reinforcement release. Durable .omc/ultragoal/ plan/ledger artifacts are preserved.
Swarm : Stops coordinated agent swarm, releases claimed tasks
Ultrapilot : Stops parallel autopilot workers
Pipeline : Stops sequential agent pipeline
Team : Requests shutdown from all teammates through the active team/conversation surface, waits for responses/timeouts, clears OMC team state, clears linked ralph if present. Claude Code 2.1.178+ has no TeamDelete.
Team+Ralph (linked) : Cancels team first (graceful shutdown), then clears ralph state. Cancelling ralph when linked also cancels team first.
Usage
Or say: "cancelomc", "stopomc"
Critical: Deferred Tool Handling
The state management tools ( state clear , state read , state write , state list active ,
state get status ) may be registered as deferred tools by Claude Code. Before calling
any state tool, you MUST first load all of them via ToolSearch :
If state clear is unavailable or fails, use this bash fallback as an emergency
escape from the stop hook loop . This is NOT a full replacement for the cancel flow —
it only removes state files to unblock the session. Linked active modes (for example,
autopilot→ralph) must be cleared separately by running the fallback once per mode.
Replace MODE with the specific mode (e.g. ralplan , ralph , ultrawork , ultragoal ).
WARNING: Do NOT use this fallback for autopilot or omc teams . Autopilot requires
state write(active=false) to preserve resume data. omc teams requires tmux session
cleanup that cannot be done via file deletion alone.
Auto Detection
/oh my claudecode:cancel follows the session aware state contract:
By default the command inspects the current session via state list active and state get status , navigating .omc/state/sessions/{sessionId}/… to discover which mode is active.
When a session id is provided or already known, that session scoped path is authoritative. Legacy files in .omc/state/ .json are consulted only as a compatibility fallback if the session id is missing or empty.
Swarm is a shared SQLite/marker mode ( .omc/state/swarm.db / .omc/state/swarm active.marker ) and is not session scoped.
The default cleanup flow calls state clear with the session id to remove only the matching session files; modes stay bound to their originating session.
Active modes are still cancelled in dependency order:
1. Autopilot (includes linked ralph and retired state cleanup)
2. Ralph
3. Legacy Ultrawork/UltraQA state cleanup
4. Ultragoal (standalone runtime guard — state clear(mode="ultragoal") ; preserves durable .omc/ultragoal/ artifacts)
5. Swarm (standalone)
6. Ultrapilot (standalone)
7. Pipeline (standalone)
8. Team (Claude Code native)
9. OMC Teams (tmux CLI workers)
10. Plan Consensus (standalone)
11. Self Improve (standalone — clear state, clean orphaned worktrees, preserve iteration state for resume, set status: "user stopped" in the resolved <self improve root /state/agent settings.json ; new runs use .omc/self improve/topics/<topic slug / , with flat .omc/self improve/ retained only for legacy single track resumes)
Force Clear All
Use force or all when you need to erase every session plus legacy artifacts, e.g., to reset the workspace entirely.
Steps under the hood:
1. state list active enumerates .omc/state/sessions/{sessionId}/… to find every known session.
2. state clear runs once per session to drop that session’s files.
3. A global state clear without session id removes legacy files under .omc/state/ .json , .omc/state/swarm .db , and compatibility artifacts (see list).
4. Team artifacts ( ~/.claude/teams/ / , ~/.claude/tasks/ / , .omc/state/team state.json ) are best effort cleared as part of the legacy fallback.
Cancel for native team does NOT affect omc teams state, and vice versa.
Every state clear command honors the session id argument, so even force mode still uses the session aware paths first before deleting legacy files.
Legacy compatibility list (removed only under force / all ):
.omc/state/autopilot state.json
.omc/state/ralph state.json
.omc/state/ralph plan state.json
.omc/state/ralph verification.json
.omc/state/ultrawork state.json
.omc/state/ultraqa state.json
.omc/state/swarm.db
.omc/state/swarm.db wal
.omc/state/swarm.db shm
.omc/state/swarm active.marker
.omc/state/swarm tasks.db
.omc/state/ultrapilot state.json
.omc/state/ultrapilot ownership.json
.omc/state/pipeline state.json
.omc/state/omc teams state.json
.omc/state/plan consensus.json
.omc/state/ralplan state.json
.omc/state/boulder.json
.omc/state/hud state.json
.omc/state/subagent tracking.json
.omc/state/subagent tracker.lock
.omc/state/rate limit daemon.pid
.omc/state/rate limit daemon.log
.omc/state/checkpoints/ (directory)
.omc/state/sessions/ (empty directory cleanup after clearing sessions)
Implementation Steps
When you invoke this skill:
1. Parse Arguments
2. Detect Active Modes
The skill now relies on the session aware state contract rather than hard coded file paths:
1. Call state list active to enumerate .omc/state/sessions/{sessionId}/… and discover every active session.
2. For each session id, call state get status to learn which active mode is running and whether dependent modes exist; treat any Ultrawork record as retired cleanup input only.
3. If a session id was supplied to /oh my claudecode:cancel , skip legacy fallback entirely and operate solely within that session path; otherwise, consult legacy files in .omc/state/ .json only if the state tools report no active session. Swarm remains a shared SQLite/marker mode outside session scoping.
4. Any cancellation logic in this doc mirrors the dependency order discovered via state tools (autopilot → ralph → …).
3A. Force Mode (if force or all)
Use force mode to clear every session plus legacy artifacts via state clear . Direct file removal is reserved for legacy cleanup when the state tools report no active sessions.
3B. Smart Cancellation (default)
If Team Active (Claude Code implicit team)
Teams are detected through OMC team state, not removed Claude Code ~/.claude/teams config directories:
Two pass cancellation protocol:
Pass 1: Graceful Shutdown
Pass 2: Reconciliation
OMC State Cleanup:
Orphan Detection (Post Cleanup):
For legacy OMC tmux/CLI worker runs, verify no worker processes remain:
The orphan scanner:
1. Checks ps aux (Unix) or tasklist (Windows) for OMC worker processes with team name matching the cleaned up team
2. Sends SIGTERM, waits 5s, sends SIGKILL if still alive
3. Reports cleanup results as JSON
Use dry run to inspect without killing. The scanner is safe to run multiple times.
Structured Cancel Report:
Implementation note: The cancel skill is executed by the LLM, not as a bash script. When you detect an active team:
1. Read state read(mode="team") to find the active OMC team
2. Identify active named teammates from state, handoffs, or task bookkeeping
3. For each teammate, ask or notify the named teammate through the active conversation/team messaging surface
4. Wait briefly for shutdown responses (15s per member timeout)
5. Record unresponsive teammates after a reconciliation wait
6. Clear team state: state clear(mode="team", session id)
7. Report structured summary to user
If Autopilot Active
Autopilot handles its own primary first cleanup: named workflows additionally remove only their session owned nested ralplan enforcement state before linked ralph and retired ultraqa cleanup.
1. Read autopilot state via state read(mode="autopilot", session id) to capture the exact current run, including workflowRunId when present.
2. Pause that exact run with the narrow mutation state write(mode="autopilot", session id, active=false, state={workflowRunId: "<exact run id "}) . Do not replay or copy the state readback. On Linux with flock , the tool revalidates the held run and workflow integrity under its mutation lock before changing only active to false ; it preserves workflow, pipeline tracking, and task identity. target state sha256 may be included only when it is the exact SHA 256 of the current serialized state.
If this write fails, stop immediately. Do not clear nested ralplan, linked state, cancel signals, or runtime artifacts.
3. For a named workflow, clear only ralplan state owned by the same session id ; never clear another session's standalone ralplan state. Record a failure but keep the paused primary resumable.
4. Only after the primary pause commits, check linked ralph via state read(mode="ralph", session id) :
Clear ralph and require success.
5. Check for retired ultraqa state via state read(mode="ultraqa", session id) and clear it if present.
6. Report every dependent clear failure explicitly; the already paused autopilot state remains resumable and cleanup may be retried.
Force cancellation follows the same primary first rule for every autopilot group: clear the exact autopilot primary first, abort its dependent cleanup if the primary clear fails, and never continue as though that group succeeded.
If Ralph Active (but not Autopilot)
1. Clear ralph: state clear(mode="ralph", session id)
If Legacy Ultrawork State Exists
1. Read Ultrawork state only to identify a stale upgraded installation record.
2. Clear it with state clear(mode="ultrawork", session id) ; never reactivate or route it.
If UltraQA State Present (retired)
UltraQA was retired in 5.0.0. No live workflow exists; if a stale
ultraqa state.json remains from a pre 5.0.0 run, clear it directly:
state clear(mode="ultraqa", session id)
If Ultragoal Active (standalone)
Clear the runtime guard only: state clear(mode="ultragoal", session id) .
Durable .omc/ultragoal/{brief.md,goals.json,ledger.jsonl} artifacts are preserved.
No Active Modes
Report: "No active OMC modes detected. Use force to clear all state files anyway."
Implementation Notes
The cancel skill runs as follows:
1. Parse the force / all flags, tracking whether cleanup should span every session or stay scoped to the current session id.
2. Use state list active to enumerate known session ids and state get status to learn each active mode; treat any Ultrawork record as cleanup only legacy state.
3. When operating in default mode, call state clear with that session id to remove only the session’s files, then run mode specific cleanup (autopilot → ralph → …) based on the state tool signals.
4. In force mode, iterate every active session, call state clear per session, then run a global state clear without session id to drop legacy files ( .omc/state/ .json , compatibility artifacts) and report success. Swarm remains a shared SQLite/marker mode outside session scoping.
5. Team artifacts ( ~/.claude/teams/ / , ~/.claude/tasks/ / , .omc/state/team state.json ) remain best effort cleanup