deepwork-teardown
Tear down an active deepwork session — deletes the team, archives state, and restores settings. Works for both mid-flight abort and post-HALT cleanup.
What this skill does
# Teardown Deepwork
Tear down a deepwork session — delete the team, archive state, and restore settings. Applies to both mid-flight abort and post-HALT cleanup; the `phase` field in the archived state distinguishes the two.
1. Use Glob to find all active instances:
```
Glob: ${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/*/state.json
```
2. If no files are found, report that no deepwork session is running and stop.
3. Read each state file to extract: `session_id`, `goal`, `phase`, `team_name`.
4. If exactly one instance exists, proceed to tear it down. If multiple instances exist, show a summary:
| Instance ID | Goal | Phase | Team |
|---|---|---|---|
| `<id>` | `<goal>` | `<phase>` | `<team>` |
Then use `AskUserQuestion` to ask the user which instance to tear down.
5. Once the target instance is selected, note its directory path: `${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<id>/`.
6. Read the state file to get team_name. Then call `TaskList` to get current task status for the summary report.
7. If the state file has a non-null `team_name` field:
- Broadcast a shutdown_request to all teammates: `SendMessage(to: "*", summary: "ending deepwork", message: "The user has ended the deepwork session. Please stop any in-progress work.")`
- Call `TeamDelete` to clean up the team and task records.
- **This is the ONLY place TeamDelete is called.** `hooks/approve-archive.sh` archives state + restores settings on APPROVE but leaves the team intact for inspection; a full teardown (team deletion) only happens when this skill runs.
- If TeamDelete fails (team already gone), continue anyway.
8. Archive runtime state via the canonical writer, then clean up transient files:
```bash
bash "${CLAUDE_PLUGIN_ROOT}/scripts/state-transition.sh" \
--state-file "${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<id>/state.json" archive_state
rm -f "${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<id>/pending-change.json"
rm -f "${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<id>/.idle-retry.*"
```
`archive_state` emits a `state_archived` event, renames `state.json` → `state.archived.json`, and renames `events.jsonl` → `events.archived.jsonl`. The rename (not delete) of `state.json` stops all active-session globs (`${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/*/state.json`) from picking up this instance — so `setup-deepwork.sh`, `session-context.sh`, `deepwork-status`, `deepwork-bar`, `deepwork-guardrail`, and this skill all correctly skip it — while preserving the full structured record (bar verdicts, empirical_unknowns, user_feedback, guardrails, role_definitions, anchors) for programmatic query across past deepwork sessions. The archived filename is neutral because this skill runs on mid-flight abort, post-APPROVE cleanup, and post-HALT cleanup; the `phase` field inside the archived state distinguishes them.
Do NOT delete the artifacts — they capture the *why* behind the session (what was explored, what failed, what was rejected) and remain useful after teardown for historical analysis and future decisions:
- `log.md` — narrative history
- `proposals/` — all versions of the proposal (audit trail)
- `prompt.md` — original user prompt
- `findings.*.md`, `coverage.*.md`, `mechanism.*.md`, `reframe.*.md`, `empirical_results.*.md`, `critique.*.md` — teammate outputs
- `gate-list-*.md`, `anchors.md` — bar/scope artifacts
- `incidents.jsonl` — structured record of runtime failures (SubagentStop non-zero, PermissionDenied)
9. Check if any other instances remain (informational only — the teardown script in step 10 performs the same check internally):
```bash
ls "${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork"/*/state.json 2>/dev/null
```
10. Restore settings via the centralized teardown script. Pass the instance ID so only this instance's hooks are removed (sibling-instance hooks are preserved). Falls back to `.deepwork-backup` if jq fails. No-ops if other active instances remain:
```bash
bash "${CLAUDE_PLUGIN_ROOT}/scripts/settings-teardown.sh" "${CLAUDE_PROJECT_DIR:-$PWD}" "${INSTANCE_ID}"
```
`INSTANCE_ID` is the 8-hex identifier read from the archived state.json (`.instance_id` field) in a prior step. The same script is invoked by `hooks/approve-archive.sh` on APPROVE, so both teardown paths use identical restore semantics.
11. Report to the user:
- Goal that was being worked on
- Phase at time of teardown (the phase field in archived state is preserved as-is — `done` for post-APPROVE plan-mode cleanup, `halt` for post-HALT execute-mode cleanup, or whichever phase was live for mid-flight abort)
- Task status summary from TaskList (completed / in_progress / pending)
- Confirm teardown; note that the full instance is preserved at `${CLAUDE_PROJECT_DIR:-$(pwd -P)}/.claude/deepwork/<id>/` including `state.archived.json` (structured record), `log.md`, `proposals/`, and all teammate artifacts — queryable via `jq` across past sessions
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.