Help us improve
Share bugs, ideas, or general feedback.
From pepcode
Cancel any active PEP mode (autopilot, ralph, ultrawork, ecomode, ultraqa, swarm, ultrapilot, pipeline, team)
npx claudepluginhub leejaedus/pepcode --plugin pepcodeHow this skill is triggered — by the user, by Claude, or both
Slash command
/pepcode:cancelThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Intelligent cancellation that detects and cancels the active PEP mode.
Cancel stuck or orphaned executions by session ID or interactively using the Ouroboros CLI. Works with the event store to emit cancellation events.
Guides technical evaluation of code review feedback: read fully, restate for understanding, verify against codebase, respond with reasoning or pushback before implementing.
Share bugs, ideas, or general feedback.
Intelligent cancellation that detects and cancels the active PEP mode.
The cancel skill is the standard way to complete and exit any PEP 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.
Automatically detects which mode is active and cancels it:
/pepcode:cancel
Or say: "cancelomc", "stopomc"
/pepcode:cancel follows the session-aware state contract:
state_list_active and state_get_status, navigating .pep/state/sessions/{sessionId}/… to discover which mode is active..pep/state/*.json are consulted only as a compatibility fallback if the session id is missing or empty..pep/state/swarm.db / .pep/state/swarm-active.marker) and is not session-scoped.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:
Use --force or --all when you need to erase every session plus legacy artifacts, e.g., to reset the workspace entirely.
/pepcode:cancel --force
/pepcode:cancel --all
Steps under the hood:
state_list_active enumerates .pep/state/sessions/{sessionId}/… to find every known session.state_clear runs once per session to drop that session’s files.state_clear without session_id removes legacy files under .pep/state/*.json, .pep/state/swarm*.db, and compatibility artifacts (see list).~/.claude/teams/*/, ~/.claude/tasks/*/, .pep/state/team-state.json) are best-effort cleared as part of the legacy fallback.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):
.pep/state/autopilot-state.json.pep/state/ralph-state.json.pep/state/ralph-plan-state.json.pep/state/ralph-verification.json.pep/state/ultrawork-state.json.pep/state/ecomode-state.json.pep/state/ultraqa-state.json.pep/state/swarm.db.pep/state/swarm.db-wal.pep/state/swarm.db-shm.pep/state/swarm-active.marker.pep/state/swarm-tasks.db.pep/state/ultrapilot-state.json.pep/state/ultrapilot-ownership.json.pep/state/pipeline-state.json.pep/state/plan-consensus.json.pep/state/ralplan-state.json.pep/state/boulder.json.pep/state/hud-state.json.pep/state/subagent-tracking.json.pep/state/subagent-tracker.lock.pep/state/rate-limit-daemon.pid.pep/state/rate-limit-daemon.log.pep/state/checkpoints/ (directory).pep/state/sessions/ (empty directory cleanup after clearing sessions)When you invoke this skill:
# Check for --force or --all flags
FORCE_MODE=false
if [[ "$*" == *"--force"* ]] || [[ "$*" == *"--all"* ]]; then
FORCE_MODE=true
fi
The skill now relies on the session-aware state contract rather than hard-coded file paths:
state_list_active to enumerate .pep/state/sessions/{sessionId}/… and discover every active session.state_get_status to learn which mode is running (autopilot, ralph, ultrawork, etc.) and whether dependent modes exist.session_id was supplied to /pepcode:cancel, skip legacy fallback entirely and operate solely within that session path; otherwise, consult legacy files in .pep/state/*.json only if the state tools report no active session. Swarm remains a shared SQLite/marker mode outside session scoping.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.
Teams are detected by checking for config files in ~/.claude/teams/:
# Check for active teams
TEAM_CONFIGS=$(find ~/.claude/teams -name config.json -maxdepth 2 2>/dev/null)
Two-pass cancellation protocol:
Pass 1: Graceful Shutdown
For each team found in ~/.claude/teams/:
1. Read config.json to get team_name and members list
2. For each non-lead member:
a. Send shutdown_request via SendMessage
b. Wait up to 15 seconds for shutdown_response
c. If response received: member terminates and is auto-removed
d. If timeout: mark member as unresponsive, continue to next
3. Log: "Graceful pass: X/Y members responded"
Pass 2: Reconciliation
After graceful pass:
1. Re-read config.json to check remaining members
2. If only lead remains (or config is empty): proceed to TeamDelete
3. If unresponsive members remain:
a. Wait 5 more seconds (they may still be processing)
b. Re-read config.json again
c. If still stuck: attempt TeamDelete anyway
d. If TeamDelete fails: report manual cleanup path
TeamDelete + Cleanup:
1. Call TeamDelete() — removes ~/.claude/teams/{name}/ and ~/.claude/tasks/{name}/
2. Clear team state: state_clear(mode="team")
3. Check for linked ralph: state_read(mode="ralph") — if linked_team is true:
a. Clear ralph state: state_clear(mode="ralph")
b. Clear linked ultrawork if present: state_clear(mode="ultrawork")
4. Emit structured cancel report
Structured Cancel Report:
Team "{team_name}" cancelled:
- Members signaled: N
- Responses received: M
- Unresponsive: K (list names if any)
- TeamDelete: success/failed
- Manual cleanup needed: yes/no
Path: ~/.claude/teams/{name}/ and ~/.claude/tasks/{name}/
Implementation note: The cancel skill is executed by the LLM, not as a bash script. When you detect an active team:
~/.claude/teams/*/config.json to find active teamscreatedAt)SendMessage(type: "shutdown_request", recipient: member-name, content: "Cancelling")TeamDelete() to clean uprm -f .pep/state/team-state.jsonCall cancelAutopilot() from src/hooks/autopilot/cancel.ts:27-78:
# Autopilot handles its own cleanup + ralph + ultraqa
# Just mark autopilot as inactive (preserves state for resume)
if [[ -f .pep/state/autopilot-state.json ]]; then
# Clean up ralph if active
if [[ -f .pep/state/ralph-state.json ]]; then
RALPH_STATE=$(cat .pep/state/ralph-state.json)
LINKED_UW=$(echo "$RALPH_STATE" | jq -r '.linked_ultrawork // false')
# Clean linked ultrawork first
if [[ "$LINKED_UW" == "true" ]] && [[ -f .pep/state/ultrawork-state.json ]]; then
rm -f .pep/state/ultrawork-state.json
echo "Cleaned up: ultrawork (linked to ralph)"
fi
# Clean ralph
rm -f .pep/state/ralph-state.json
rm -f .pep/state/ralph-verification.json
echo "Cleaned up: ralph"
fi
# Clean up ultraqa if active
if [[ -f .pep/state/ultraqa-state.json ]]; then
rm -f .pep/state/ultraqa-state.json
echo "Cleaned up: ultraqa"
fi
# Mark autopilot inactive but preserve state
CURRENT_STATE=$(cat .pep/state/autopilot-state.json)
CURRENT_PHASE=$(echo "$CURRENT_STATE" | jq -r '.phase // "unknown"')
echo "$CURRENT_STATE" | jq '.active = false' > .pep/state/autopilot-state.json
echo "Autopilot cancelled at phase: $CURRENT_PHASE. Progress preserved for resume."
echo "Run /pepcode:autopilot to resume."
fi
Call clearRalphState() + clearLinkedUltraworkState() from src/hooks/ralph-loop/index.ts:147-182:
if [[ -f .pep/state/ralph-state.json ]]; then
# Check if ultrawork is linked
RALPH_STATE=$(cat .pep/state/ralph-state.json)
LINKED_UW=$(echo "$RALPH_STATE" | jq -r '.linked_ultrawork // false')
# Clean linked ultrawork first
if [[ "$LINKED_UW" == "true" ]] && [[ -f .pep/state/ultrawork-state.json ]]; then
UW_STATE=$(cat .pep/state/ultrawork-state.json)
UW_LINKED=$(echo "$UW_STATE" | jq -r '.linked_to_ralph // false')
# Only clear if it was linked to ralph
if [[ "$UW_LINKED" == "true" ]]; then
rm -f .pep/state/ultrawork-state.json
echo "Cleaned up: ultrawork (linked to ralph)"
fi
fi
# Clean ralph state
rm -f .pep/state/ralph-state.json
rm -f .pep/state/ralph-plan-state.json
rm -f .pep/state/ralph-verification.json
echo "Ralph cancelled. Persistent mode deactivated."
fi
Call deactivateUltrawork() from src/hooks/ultrawork/index.ts:150-173:
if [[ -f .pep/state/ultrawork-state.json ]]; then
# Check if linked to ralph
UW_STATE=$(cat .pep/state/ultrawork-state.json)
LINKED=$(echo "$UW_STATE" | jq -r '.linked_to_ralph // false')
if [[ "$LINKED" == "true" ]]; then
echo "Ultrawork is linked to Ralph. Use /pepcode:cancel to cancel both."
exit 1
fi
# Remove local state
rm -f .pep/state/ultrawork-state.json
echo "Ultrawork cancelled. Parallel execution mode deactivated."
fi
Call clearUltraQAState() from src/hooks/ultraqa/index.ts:107-120:
if [[ -f .pep/state/ultraqa-state.json ]]; then
rm -f .pep/state/ultraqa-state.json
echo "UltraQA cancelled. QA cycling workflow stopped."
fi
echo "No active PEP modes detected."
echo ""
echo "Checked for:"
echo " - Autopilot (.pep/state/autopilot-state.json)"
echo " - Ralph (.pep/state/ralph-state.json)"
echo " - Ultrawork (.pep/state/ultrawork-state.json)"
echo " - UltraQA (.pep/state/ultraqa-state.json)"
echo ""
echo "Use --force to clear all state files anyway."
The cancel skill runs as follows:
--force / --all flags, tracking whether cleanup should span every session or stay scoped to the current session id.state_list_active to enumerate known session ids and state_get_status to learn the active mode (autopilot, ralph, ultrawork, etc.) for each session.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.state_clear per session, then run a global state_clear without session_id to drop legacy files (.pep/state/*.json, compatibility artifacts) and report success. Swarm remains a shared SQLite/marker mode outside session scoping.~/.claude/teams/*/, ~/.claude/tasks/*/, .pep/state/team-state.json) remain best-effort cleanup items invoked during the legacy/global pass.State tools always honor the session_id argument, so even force mode still clears the session-scoped paths before deleting compatibility-only legacy state.
Mode-specific subsections below describe what extra cleanup each handler performs after the state-wide operations finish.
| Mode | Success Message |
|---|---|
| Autopilot | "Autopilot cancelled at phase: {phase}. Progress preserved for resume." |
| Ralph | "Ralph cancelled. Persistent mode deactivated." |
| Ultrawork | "Ultrawork cancelled. Parallel execution mode deactivated." |
| Ecomode | "Ecomode cancelled. Token-efficient execution mode deactivated." |
| UltraQA | "UltraQA cancelled. QA cycling workflow stopped." |
| Swarm | "Swarm cancelled. Coordinated agents stopped." |
| Ultrapilot | "Ultrapilot cancelled. Parallel autopilot workers stopped." |
| Pipeline | "Pipeline cancelled. Sequential agent chain stopped." |
| Team | "Team cancelled. Teammates shut down and cleaned up." |
| Plan Consensus | "Plan Consensus cancelled. Planning session ended." |
| Force | "All PEP modes cleared. You are free to start fresh." |
| None | "No active PEP modes detected." |
| Mode | State Preserved | Resume Command |
|---|---|---|
| Autopilot | Yes (phase, files, spec, plan, verdicts) | /pepcode:autopilot |
| Ralph | No | N/A |
| Ultrawork | No | N/A |
| UltraQA | No | N/A |
| Swarm | No | N/A |
| Ultrapilot | No | N/A |
| Pipeline | No | N/A |
| Plan Consensus | Yes (plan file path preserved) | N/A |
.pep/state/ directoryWhen cancelling modes that may have spawned MCP workers (team bridge daemons), the cancel skill should also:
.pep/state/team-bridge/{team}/*.heartbeat.jsontmux kill-session -t pep-team-{team}-{worker} for each worker.pep/state/team-mcp-workers.jsonWhen --force is used, also clean up:
rm -rf .pep/state/team-bridge/ # Heartbeat files
rm -f .pep/state/team-mcp-workers.json # Shadow registry
# Kill all pep-team-* tmux sessions
tmux list-sessions -F '#{session_name}' 2>/dev/null | grep '^pep-team-' | while read s; do tmux kill-session -t "$s" 2>/dev/null; done