/octo:skill-finish-branchfrom octo
Automates branch completion: runs tests, performs multi-provider diff review, bumps version, updates changelog, commits, pushes, and creates a PR.
Ships in octo. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Your first output line MUST be: 🐙 **CLAUDE OCTOPUS ACTIVATED** - Branch Completion
Full ship pipeline: tests → multi-provider review → version bump → changelog → commit → push → PR.
Core principle: Verify tests → Review diff → Bump version → Update changelog → Present options → Execute choice → Clean up.
Before anything else, verify tests pass:
# Detect and run project's test suite
if [[ -f "package.json" ]]; then npm test
elif [[ -f "pytest.ini" ]] || [[ -f "pyproject.toml" ]]; then pytest
elif [[ -f "Cargo.toml" ]]; then cargo test
elif [[ -f "go.mod" ]]; then go test ./...
elif [[ -f "Makefile" ]] && grep -q '^test:' Makefile; then make test
fi
If tests fail: STOP. Show failures. Do not proceed.
If tests pass: Continue to Step 2.
Run a quick multi-provider review of the changes before shipping. This catches issues before they reach PR reviewers.
# Get the diff summary
DIFF_STAT=$(git diff --stat $(git merge-base HEAD main)..HEAD)
DIFF_FILES=$(git diff --name-only $(git merge-base HEAD main)..HEAD)
Always run a quick review — this is automatic, not optional:
# Runs under bash even when the host shell is zsh.
if [ -n "${BASH_VERSION:-}" ]; then eval "$(cat)"; else env "OCTO_ALLOWED_PROVIDERS=${OCTO_ALLOWED_PROVIDERS:-}" bash -c "$(cat)"; fi <<'OCTO_BASH'
# Review the complete committed range. A text diff cannot review binary content
# or nested submodule source, and a partial prompt cannot establish coverage.
REVIEW_HEAD=$(git rev-parse --verify 'HEAD^{commit}') || exit 1
REVIEW_BASE=$(git merge-base "$REVIEW_HEAD" main) || exit 1
REVIEW_NUMSTAT=$(git diff --no-ext-diff --no-textconv --no-renames --no-relative \
--ignore-submodules=none --no-color --numstat "$REVIEW_BASE" "$REVIEW_HEAD" --) || exit 1
if awk -F '\t' '$(1) == "-" || $(2) == "-" {found=1} END {exit !found}' <<< "$REVIEW_NUMSTAT"; then
echo "Review incomplete: changed binary content needs a separate complete review." >&2
exit 1
fi
REVIEW_RAW=$(git diff --no-ext-diff --no-textconv --no-renames --no-relative \
--ignore-submodules=none --no-color --raw "$REVIEW_BASE" "$REVIEW_HEAD" --) || exit 1
if awk '$(1) == ":160000" || $(2) == "160000" {found=1} END {exit !found}' <<< "$REVIEW_RAW"; then
echo "Review incomplete: changed submodules need a separate complete source review." >&2
exit 1
fi
# Inspect bytes before Bash command substitution, which discards NUL bytes.
REVIEW_DIFF=$(python3 -I - "$REVIEW_BASE" "$REVIEW_HEAD" <<'PY_REVIEW_DIFF'
import subprocess
import sys
import re
diff = subprocess.check_output([
'git', 'diff', '--no-ext-diff', '--no-textconv', '--no-renames',
'--no-relative', '--ignore-submodules=none', '--no-color', '--binary',
sys.argv[1], sys.argv[2], '--',
])
if re.search(rb'(?m)^GIT binary patch$', diff):
sys.exit('Review incomplete: the final patch omits binary content and needs a separate complete review.')
if b'\0' in diff:
sys.exit('Review incomplete: NUL-containing content needs a separate complete review.')
if re.search(rb'\[\[OCTOPUS_TRUSTED_JSON_CONTRACT_(?:BEGIN|END):[0-9a-fA-F]{32}\]\]', diff):
sys.exit('Review incomplete: transport markers need a separate lossless review.')
if len(diff) > 60000:
sys.exit('Review incomplete: the full diff exceeds the 60000-byte quick-review limit. Split it into fully reviewed ranges before continuing.')
sys.stdout.buffer.write(diff)
PY_REVIEW_DIFF
) || exit 1
# Collect the completed answer, rather than accepting a launch PID as a review.
REVIEW_ROOT="${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${HOME}/.claude-octopus/plugin}}"
source "$REVIEW_ROOT/scripts/lib/consultative-advisors.sh" || exit 1
REVIEW_OUTPUT_DIR=$(mktemp -d "${TMPDIR:-/tmp}/octopus-review-results.XXXXXX") || exit 1
printf 'REVIEW_OUTPUT_DIR=%s\n' "$REVIEW_OUTPUT_DIR"
REVIEW_EVENT_LOG="$REVIEW_OUTPUT_DIR/events"
: > "$REVIEW_EVENT_LOG" || exit 1
cat > "$REVIEW_OUTPUT_DIR/lifecycle.sh" <<'REVIEW_HOOK'
#!/usr/bin/env bash
printf '%s\t%s\t%s\t%s\n' "${1:-}" "${OCTOPUS_AGENT_PID:-}" \
"${OCTOPUS_AGENT_STATUS:-}" "${OCTOPUS_AGENT_RESULT_FILE:-}" >> "$OCTO_BRANCH_REVIEW_EVENTS" || exit 1
if [[ -n "${OCTO_BRANCH_REVIEW_PREV_HOOK:-}" && -x "$OCTO_BRANCH_REVIEW_PREV_HOOK" ]]; then
exec "$OCTO_BRANCH_REVIEW_PREV_HOOK" "$@"
fi
REVIEW_HOOK
chmod +x "$REVIEW_OUTPUT_DIR/lifecycle.sh" || exit 1
REVIEW_PREV_HOOK="${OCTOPUS_AGENT_LIFECYCLE_HOOK:-}"
OCTOPUS_AGENT_LIFECYCLE_HOOK="$REVIEW_OUTPUT_DIR/lifecycle.sh" \
OCTO_BRANCH_REVIEW_EVENTS="$REVIEW_EVENT_LOG" \
OCTO_BRANCH_REVIEW_PREV_HOOK="$REVIEW_PREV_HOOK" \
OCTOPUS_OVERSIZE_STRATEGY=fail \
"$REVIEW_ROOT/scripts/orchestrate.sh" spawn code-reviewer "Review this diff for bugs, security issues, and code quality problems. Be concise — only flag real issues, not style preferences.
$REVIEW_DIFF" > "$REVIEW_OUTPUT_DIR/spawn.txt" || exit 1
# Native Agent Teams emits a dispatch receipt without a collectable answer.
if grep -q '^AGENT_TEAMS_DISPATCH:' "$REVIEW_OUTPUT_DIR/spawn.txt"; then
echo "Review incomplete: native dispatch produced no answer. Use a supervised subprocess review." >&2
exit 1
fi
if ! _octo_advisor_collect "$REVIEW_EVENT_LOG" "$REVIEW_OUTPUT_DIR/spawn.txt" \
"$REVIEW_OUTPUT_DIR/answer.md" "$(( $(date +%s) + 600 ))"; then
echo "Review incomplete; inspect $REVIEW_OUTPUT_DIR before retrying." >&2
exit 1
fi
cat "$REVIEW_OUTPUT_DIR/answer.md" || exit 1
if [[ "$(git rev-parse --verify 'HEAD^{commit}')" != "$REVIEW_HEAD" ]]; then
echo "Review incomplete: HEAD changed during review. Review the current committed range again." >&2
exit 1
fi
printf 'REVIEW_HEAD=%s\n' "$REVIEW_HEAD"
OCTO_BASH
Binary, submodule and oversized ranges leave the review incomplete. Obtain and record a complete review of those changes before proceeding to Step 3.
If critical issues found: Present them and ask whether to fix or ship anyway.
If clean: Continue to Step 3. Show a brief ✓ Review clean — no issues found.
# Identify the base branch
BASE_BRANCH=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}')
[[ -z "$BASE_BRANCH" ]] && BASE_BRANCH="main"
# Check for VERSION file
VERSION_FILE=""
for f in VERSION version.txt package.json; do
[[ -f "$f" ]] && VERSION_FILE="$f" && break
done
If a VERSION file or package.json exists, offer to bump:
AskUserQuestion({
questions: [{
question: "Version bump?",
header: "Version",
multiSelect: false,
options: [
{label: "Patch (Recommended)", description: "Bug fixes, minor changes (1.2.3 → 1.2.4)"},
{label: "Minor", description: "New features, backward compatible (1.2.3 → 1.3.0)"},
{label: "Major", description: "Breaking changes (1.2.3 → 2.0.0)"},
{label: "Skip", description: "Don't bump version"}
]
}]
})
If bumping: Update the version file and prepend a changelog entry summarizing the diff:
# Generate changelog entry from commits
COMMITS=$(git log --oneline $(git merge-base HEAD $BASE_BRANCH)..HEAD)
# Prepend to CHANGELOG.md if it exists
Present exactly these 4 options:
✅ Ship ready. Tests passing. Review clean. What would you like to do?
1. **Create PR** (Recommended) - Push and create a Pull Request for review
2. **Merge locally** - Merge back to <base-branch> on this machine
3. **Keep as-is** - Leave the branch, I'll handle it later
4. **Discard** - Delete this work permanently
Which option? (1-4)
Keep options concise. Don't add explanations unless asked.
# Get branch info
FEATURE_BRANCH=$(git branch --show-current) || {
echo "PR creation stopped: cannot determine the current branch." >&2
return 1 2>/dev/null || exit 1
}
if [[ -z "$FEATURE_BRANCH" ]]; then
echo "PR creation stopped: check out the reviewed feature branch first." >&2
return 1 2>/dev/null || exit 1
fi
# Validate repository and description before publishing the branch
REPO_SLUG=$(gh repo view --json nameWithOwner --jq .nameWithOwner) || {
echo "PR creation stopped: cannot determine the GitHub repository." >&2
return 1 2>/dev/null || exit 1
}
if [[ -z "$REPO_SLUG" ]]; then
echo "PR creation stopped: the GitHub repository is empty." >&2
return 1 2>/dev/null || exit 1
fi
PR_TITLE=${PR_TITLE:?Complete PR_TITLE before creating the pull request}
CHANGE_SUMMARY=${CHANGE_SUMMARY:?Complete CHANGE_SUMMARY before creating the pull request}
CHANGE_REASON=${CHANGE_REASON:?Complete CHANGE_REASON before creating the pull request}
PR_BODY=$(cat <<EOF
## Summary
- ${CHANGE_SUMMARY}
- ${CHANGE_REASON}
## Test Plan
- [x] Unit tests pass
- [x] Manual verification done
- [ ] Code review needed
EOF
)
if ! git push -u origin "$FEATURE_BRANCH"; then
echo "PR creation stopped: branch push failed. Preserve the branch and repair publication before retrying." >&2
return 1 2>/dev/null || exit 1
fi
# Create PR with a validated description file
if ! "${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${HOME}/.claude-octopus/plugin}}/scripts/safe-gh-comment.sh" \
--repo "$REPO_SLUG" pr-create "$PR_TITLE" "$FEATURE_BRANCH" - <<< "$PR_BODY"; then
echo "GitHub write state is unknown; check for an existing pull request before retrying:" >&2
gh pr list --repo "$REPO_SLUG" --head "$FEATURE_BRANCH" --state all --json number,state,url || true
return 1 2>/dev/null || exit 1
fi
Stop after any failed admission or push. Keep the feature branch and report the failure. A failed PR write requires checking its recorded recovery state before retrying.
Report only after both the branch push and PR creation succeed:
✅ Branch pushed to origin/$FEATURE_BRANCH
✅ PR created: https://github.com/owner/repo/pull/123
Branch preserved for review process.
Use the base branch selected in Step 3 and the project test command from Step 1.
In a fresh shell, restore BASE_BRANCH and the exact REVIEW_HEAD printed
by Step 2. If the feature branch has moved, review it again before merging.
BASE_BRANCH=${BASE_BRANCH:-main}
FEATURE_BRANCH=$(git branch --show-current) || {
echo "Local merge stopped: cannot determine the current branch." >&2
return 1 2>/dev/null || exit 1
}
if [[ -z "$FEATURE_BRANCH" || "$FEATURE_BRANCH" == "$BASE_BRANCH" ]]; then
echo "Local merge stopped: check out the reviewed feature branch first." >&2
return 1 2>/dev/null || exit 1
fi
FEATURE_REF="refs/heads/$FEATURE_BRANCH"
: "${REVIEW_HEAD:?Restore the reviewed commit printed by Step 2}"
if [[ "$(git rev-parse --verify "$FEATURE_REF^{commit}")" != "$REVIEW_HEAD" ]]; then
echo "Local merge stopped: the feature branch differs from the reviewed commit." >&2
return 1 2>/dev/null || exit 1
fi
git switch -- "$BASE_BRANCH" || { return 1 2>/dev/null || exit 1; }
git pull origin "$BASE_BRANCH" || { return 1 2>/dev/null || exit 1; }
if [[ "$(git rev-parse --verify "$FEATURE_REF^{commit}")" != "$REVIEW_HEAD" ]]; then
echo "Local merge stopped: the feature branch changed while updating the base." >&2
return 1 2>/dev/null || exit 1
fi
git merge "$REVIEW_HEAD" || { return 1 2>/dev/null || exit 1; }
npm test || { return 1 2>/dev/null || exit 1; } # Or the test command from Step 1.
if ! git merge-base --is-ancestor "$REVIEW_HEAD" "refs/heads/$BASE_BRANCH"; then
echo "Kept the feature branch because the base no longer contains the reviewed commit." >&2
return 1 2>/dev/null || exit 1
fi
worktrees=$(git worktree list --porcelain) || { return 1 2>/dev/null || exit 1; }
if grep -Fqx -- "branch $FEATURE_REF" <<< "$worktrees"; then
echo "Kept the feature branch because it is checked out in a worktree." >&2
return 1 2>/dev/null || exit 1
fi
# Git lists rebasing and bisecting worktrees as detached. Check the operation's
# branch records in the primary and linked worktree administration directories.
common_git_dir=$(git rev-parse --git-common-dir) || { return 1 2>/dev/null || exit 1; }
for worktree_git_dir in "$common_git_dir" "$common_git_dir"/worktrees/*; do
for operation in rebase-apply/head-name rebase-merge/head-name rebase-merge/update-refs BISECT_START; do
operation_file="$worktree_git_dir/$operation"
[[ -e "$operation_file" || -L "$operation_file" ]] || continue
operation_branch="$FEATURE_REF"
if [[ "$operation" == BISECT_START ]]; then
operation_branch="$FEATURE_BRANCH"
fi
if grep -Fqx -- "$operation_branch" "$operation_file"; then
echo "Kept the feature branch because an active rebase or bisect uses it." >&2
return 1 2>/dev/null || exit 1
elif [[ $? != 1 ]]; then
echo "Kept the feature branch because its worktree operation state could not be read." >&2
return 1 2>/dev/null || exit 1
fi
done
done
# Compare and delete in one ref update so a newer tip is kept even if it tracks a newer upstream.
if ! git update-ref --no-deref -d "$FEATURE_REF" "$REVIEW_HEAD"; then
echo "Merged and tested the reviewed commit. Could not delete the reviewed feature ref." >&2
return 1 2>/dev/null || exit 1
fi
# Ref deletion leaves the branch's tracking configuration in the repository.
branch_config="branch.$FEATURE_BRANCH"
config_keys=$(git config --local --name-only --list) || { return 1 2>/dev/null || exit 1; }
if sed 's/\.[^.]*$//' <<< "$config_keys" | grep -Fqx -- "$branch_config"; then
if git show-ref --verify --quiet "$FEATURE_REF"; then
echo "Kept the configuration because the feature branch was recreated." >&2
return 1 2>/dev/null || exit 1
fi
git config --local --remove-section "$branch_config" || { return 1 2>/dev/null || exit 1; }
fi
If a command fails, report the current branch and Git status. Keep the feature branch and leave any in-progress merge or local merge commit available for recovery. If only deletion failed, report the completed merge and the retained branch. If configuration cleanup failed after deletion, report the deleted ref and the remaining configuration.
Report after merge, tests, and branch deletion succeed:
✅ Merged $FEATURE_BRANCH into $BASE_BRANCH
✅ Tests pass on merged result
✅ Feature branch deleted
Ready to push when you want: git push origin $BASE_BRANCH
✅ Keeping branch $FEATURE_BRANCH as-is.
Current state:
- Branch: $FEATURE_BRANCH
- Commits ahead of $BASE_BRANCH: N
- Tests: Passing
When ready, you can:
- Merge: git checkout main && git merge $FEATURE_BRANCH
- PR: git push -u origin $FEATURE_BRANCH && gh pr create
- Discard: git branch -D $FEATURE_BRANCH
Do NOT clean up anything.
Show the exact feature branch and its commits before requesting confirmation.
Wait for the exact response discard. Save the confirmed branch name in
FEATURE_BRANCH and restore the selected BASE_BRANCH from Step 3.
Preserve the remote branch by default. Set DISCARD_REMOTE=true only if the
user separately confirms deleting this branch from origin too.
: "${BASE_BRANCH:?Restore the selected base branch}"
: "${FEATURE_BRANCH:?Restore the confirmed feature branch}"
current_branch=$(git branch --show-current) || { return 1 2>/dev/null || exit 1; }
if [[ "$current_branch" != "$FEATURE_BRANCH" || "$FEATURE_BRANCH" == "$BASE_BRANCH" ]]; then
printf '%s\n' 'Discard stopped: check out the confirmed feature branch first.' >&2
return 1 2>/dev/null || exit 1
fi
git switch -- "$BASE_BRANCH" || { return 1 2>/dev/null || exit 1; }
git branch -D -- "$FEATURE_BRANCH" || { return 1 2>/dev/null || exit 1; }
printf 'Branch %s deleted locally.\n' "$FEATURE_BRANCH"
if [[ "${DISCARD_REMOTE:-false}" == true ]]; then
if ! git push origin --delete "$FEATURE_BRANCH"; then
printf 'Branch %s was deleted locally, but remote deletion failed.\n' "$FEATURE_BRANCH" >&2
return 1 2>/dev/null || exit 1
fi
printf 'Branch %s deleted from origin.\n' "$FEATURE_BRANCH"
fi
Report the operations that succeeded. If a step fails, show the Git error and report which branch refs were preserved.
For Options 1, 2, 4: After the selected operation succeeds, identify the current linked worktree and move to the primary checkout before removing it. Keep worktrees with uncommitted or ignored files, index flags that may hide local changes, or a Git lock. Report why cleanup stopped.
WORKTREE_PATH=$(git rev-parse --show-toplevel) || { return 1 2>/dev/null || exit 1; }
WORKTREE_GIT_DIR=$(git rev-parse --absolute-git-dir) || { return 1 2>/dev/null || exit 1; }
COMMON_GIT_DIR=$(git rev-parse --path-format=absolute --git-common-dir) || { return 1 2>/dev/null || exit 1; }
if [[ "$WORKTREE_GIT_DIR" != "$COMMON_GIT_DIR" ]]; then
# Git can remove a worktree with ignored files or index-hidden edits.
WORKTREE_STATUS=$(git -C "$WORKTREE_PATH" status --porcelain --untracked-files=normal --ignored) ||
{ return 1 2>/dev/null || exit 1; }
if [[ -n "$WORKTREE_STATUS" ]]; then
printf 'Cleanup stopped: uncommitted changes or ignored files in %s\n' "$WORKTREE_PATH" >&2
return 1 2>/dev/null || exit 1
fi
HIDDEN_INDEX=$(
set -o pipefail
git -C "$WORKTREE_PATH" ls-files -v | LC_ALL=C awk '/^[Sa-z] / { hidden = 1 } END { print hidden + 0 }'
) || { return 1 2>/dev/null || exit 1; }
if [[ "$HIDDEN_INDEX" == 1 ]]; then
printf 'Cleanup stopped: index flags may hide local changes in %s\n' "$WORKTREE_PATH" >&2
return 1 2>/dev/null || exit 1
fi
if ! IFS= read -r -d '' PRIMARY_WORKTREE < <(git worktree list --porcelain -z) ||
[[ "$PRIMARY_WORKTREE" != 'worktree '* ]]; then
printf '%s\n' 'Cleanup stopped: Git did not identify the primary checkout.' >&2
return 1 2>/dev/null || exit 1
fi
cd -- "${PRIMARY_WORKTREE#worktree }" || { return 1 2>/dev/null || exit 1; }
git --git-dir="$COMMON_GIT_DIR" worktree remove -- "$WORKTREE_PATH" ||
{ return 1 2>/dev/null || exit 1; }
printf 'Worktree cleaned up: %s\n' "$WORKTREE_PATH"
fi
For Option 3: Keep worktree intact.
| Option | Merge | Push | Keep Branch | Cleanup |
|---|---|---|---|---|
| 1. Create PR | - | ✓ | Keep | - |
| 2. Merge locally | ✓ | - | Delete | ✓ |
| 3. Keep as-is | - | - | Keep | - |
| 4. Discard | - | - | Delete | ✓ |
After completing octopus workflows, use this skill:
# After tangle (develop) phase completes successfully
# After ink (deliver) phase validates the work
# User says: "I'm done, create a PR"
# → Invoke finishing-branch skill
# → Verify tests
# → Present options
# → Execute Option 1 (Create PR)
# Run octopus validation before finishing
"${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${HOME}/.claude-octopus/plugin}}/scripts/orchestrate.sh" ink "Validate before merge"
# If validation passes, proceed with finishing-branch
| Action | Why It's Dangerous |
|---|---|
| Merge without testing | Ships broken code |
| Skip confirmation for discard | Loses work permanently |
| Force-push without asking | Destroys history |
| Delete remote branch silently | Affects collaborators |
| Proceed when tests fail | Corrupts main branch |
| Mistake | Fix |
|---|---|
| Offering options before testing | Always verify tests FIRST |
| Auto-merging without asking | Present 4 options, let user choose |
| Deleting without confirmation | Require typed "discard" |
| Cleaning up worktree on "keep" | Only cleanup for options 1, 2, 4 |
Finishing branch → Tests verified AND user chose option
Otherwise → Not complete
Verify tests. Present options. Execute safely. Clean up appropriately.
This generated Claude Code skill preserves an enforced workflow contract from the source skill.
PROHIBITED:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
git-workflow, branch-finish, pr-creation, test-verification, code-review
64 skills in this plugin
/council-verdictsStarter: interpret a council run's verdict artifacts — quorum, dissent, cross-lab validity, and what to do next/debate-kickoffStarter: frame a decision as a multi-model debate — picks sides, seats providers, and launches /octo:debate with a well-formed motion/flow-defineMulti-AI requirements scoping using available external providers (Double Diamond Define phase). Priority triggers: octo define, octo scope, co-define, co-scope. DO NOT use for implementation, research, review/validation, or built-in commands.npx claudepluginhub nyldn/claude-octopus --plugin octoOther plugins' skills for the same job