
bail
Reflects, updates GitHub Issue, closes PR if open, cleans up worktree/branch.
- Installs
- 684
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/camacho/ai-skills --skill bail- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads bail automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
-
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) -
Prompt for reason if not provided.
-
Write learnings to .branch-context.md in the worktree:
# 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" -
Consolidate learnings to MEMORY.md via disposable clone (never checkout main in a worktree):
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: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" pushOn non-fast-forward:
git -C "$BAIL_DIR" pull --rebasethen push. Max 3 retries. Clean up:rm -rf "$BAIL_DIR" -
Update GitHub Issue (if accessible):
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" -
Close PR if open:
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 -
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:
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 -dfails (unmerged work), warn the user and stop. Do NOT usebranch -D. -
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_DIRunset → fall back to$TMPDIRfor clone
Output: Summary of what was cleaned up and where learnings were saved.
FAQ
What does the bail skill do?
Reflects, updates GitHub Issue, closes PR if open, cleans up worktree/branch.
How do I install bail?
Run npx skills add https://github.com/camacho/ai-skills --skill bail in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/bail/ (personal) or .claude/skills/bail/ (project).
Which AI agents can use bail?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is bail safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains bail?
It is published by camacho in camacho/ai-skills. It has 684 recorded installs.
More from camacho/ai-skills
archive
camacho/ai-skills
Fills Outcomes & Learnings in a plan file and renames it to .done.md.
capture
camacho/ai-skills
Creates a draft GitHub Issue with triage label from natural language description.
plan-review
camacho/ai-skills
Auto-assembles review panel using deterministic rules, dispatches agents against plan file, collects verdicts.
orient
camacho/ai-skills
Fetches issue context, auto-detects task type, maps to branch prefix, presents brief.
reflect
camacho/ai-skills
Use after merging a branch or completing a task to consolidate learnings into memory layers, close out issues, and verify the phase gate.
status
camacho/ai-skills
Project status dashboard — open issues, recent commits, active branches/worktrees, memory state, and scratchpad. Use when the user asks for a status report, project overview, "what's going on", "where are we", or wants to catch up on project state without the full /catchup reconstruction.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.