bail
Reflects, updates GitHub Issue, closes PR if open, cleans up worktree/branch.
What this skill does
Bail-out protocol: always reflect FIRST, then clean up. All commands use absolute paths and `git -C`.
## Inputs
- `WORKTREE`: absolute path to current worktree (or primary if no worktree)
- Optional reason string (if not provided, ask for one)
## Steps
1. **Detect current step** by examining what exists:
| What exists | Estimated step |
|------------|---------------|
| Just an issue, no branch | Step 0 (Capture) |
| .branch-context.md, no worktree | Step 1 (Orient) |
| Worktree exists, no code changes | Step 2 (Isolate) |
| Plan file on branch | Step 3-4 (Design/Review) |
| Code changes committed | Step 5-7 (Build/Verify/Archive) |
| PR open on GitHub | Step 8 (Ship) |
2. **Prompt for reason** if not provided.
3. **Write learnings to .branch-context.md** in the worktree:
```bash
# Write bail context — use absolute path
cat >> "$WORKTREE/.branch-context.md" <<EOF
## Bail
- Reason: <reason>
- What was attempted: <summary>
- What was learned: <learnings>
EOF
git -C "$WORKTREE" add .branch-context.md
git -C "$WORKTREE" commit -m "docs: capture bail context"
```
4. **Consolidate learnings to MEMORY.md** via disposable clone (never checkout main in a worktree):
```bash
BAIL_DIR="${CLAUDE_SESSION_DIR:-$TMPDIR}/bail-reflect"
[ -d "$BAIL_DIR" ] && rm -rf "$BAIL_DIR"
git clone --depth 50 "$(git -C "$WORKTREE" remote get-url origin)" "$BAIL_DIR"
```
Read `$BAIL_DIR/ai-workspace/MEMORY.md`, append relevant learnings from `.branch-context.md`, then:
```bash
git -C "$BAIL_DIR" add ai-workspace/MEMORY.md
git -C "$BAIL_DIR" commit -m "docs: consolidate learnings from abandoned <branch>
Co-Authored-By: Claude <model>"
git -C "$BAIL_DIR" push
```
On non-fast-forward: `git -C "$BAIL_DIR" pull --rebase` then push. Max 3 retries.
Clean up: `rm -rf "$BAIL_DIR"`
5. **Update GitHub Issue** (if accessible):
```bash
GH_REPO=<owner/repo> gh issue comment <number> --body "Bailing: <reason>. Learnings captured in MEMORY.md."
GH_REPO=<owner/repo> gh issue edit <number> --add-label "deferred" --remove-label "triage"
```
6. **Close PR if open**:
```bash
PR_NUM=$(GH_REPO=<owner/repo> gh pr list --head "<branch>" --json number -q '.[0].number')
if [ -n "$PR_NUM" ]; then
GH_REPO=<owner/repo> gh pr close "$PR_NUM"
fi
```
7. **Ask about branch preservation**:
Default: preserve the branch (user can resume later).
If user explicitly says delete — confirm by showing what will be destroyed:
```
This will delete:
- Branch: <name>
- Worktree: <path>
- Remote branch (if pushed)
Type 'delete' to confirm.
```
Only after typed confirmation:
```bash
PRIMARY="$(git -C "$WORKTREE" worktree list --porcelain | grep -m1 '^worktree ' | sed 's/^worktree //')"
# Verify branch is merged before deleting (-d fails if unmerged, -D would force)
git -C "$PRIMARY" worktree remove "$WORKTREE"
git -C "$PRIMARY" branch -d <branch>
```
If `branch -d` fails (unmerged work), warn the user and stop. Do NOT use `branch -D`.
8. **Done.** Do not checkout main — stay in whatever CWD the session has.
## Edge Cases
- No worktree exists (bailing at Step 0-1) → skip worktree cleanup, just update issue
- No GitHub access → skip issue update, still do local cleanup + memory consolidation
- PR already merged → don't close, just note it in the output
- No .branch-context.md → create one with just the bail reason before consolidating
- `CLAUDE_SESSION_DIR` unset → fall back to `$TMPDIR` for clone
Output: Summary of what was cleaned up and where learnings were saved.
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.