Push the current branch and open a PR with a generated description. Trigger: 'crew open pr'.
BRANCH=$(git branch --show-current)
BASE=$(git rev-parse --abbrev-ref HEAD@{upstream} 2>/dev/null | sed 's|origin/||' || echo "main")
Detect fork workflow and determine target repo:
UPSTREAM_REPO=$(gh repo view --json parent --jq '.parent.owner.login + "/" + .parent.name' 2>/dev/null)
ORIGIN_REPO=$(gh repo view --json nameWithOwner --jq '.nameWithOwner' 2>/dev/null)
If UPSTREAM_REPO is non-empty, origin is a fork. Check whether the base branch exists on upstream:
if [ -n "$UPSTREAM_REPO" ]; then
# Check if base branch exists on upstream
if gh api "repos/$UPSTREAM_REPO/branches/$BASE" --silent 2>/dev/null; then
TARGET_REPO="$UPSTREAM_REPO"
else
# Base branch only exists on the fork — target the fork
TARGET_REPO="$ORIGIN_REPO"
fi
else
TARGET_REPO="$ORIGIN_REPO"
fi
This handles the common case where feature branches are based on other feature branches in your fork, not on upstream's main.
Read these sources (in order of priority):
TASK_DIR using the canonical resolution recipe (see Session Capture block below) and read $TASK_DIR/SPEC.md for goal, context, acceptance criteria, and ## Tests > ### Manual section$TASK_DIR/runbook.md; if present, read its **Pass:** lines to extract human-judgment verification steps for the "How to test" section (do NOT include the file path — it's a local agent artifact, not committed to the repo)git log $BASE..HEAD --oneline for what was donegit diff $BASE...HEAD --stat for scope; git diff $BASE...HEAD for details if the stat is small enough (<30 files)Use the template in pr-template.md
git push -u origin HEAD
Present the title and description to the user. Title format: same as the primary commit message, or a summary if there are multiple commits.
Before creating, ask: "Did you use LLM assistance for this PR?" If yes, append to the end of the description body:
---
🤖 Co-authored with AI assistance.
After approval:
gh pr create --draft --title "TITLE" --body "BODY" --base BASE --repo "$TARGET_REPO"
PRs are always opened as drafts. Mark ready for review manually when appropriate.
If the repo uses a PR template, read it first and fill in the sections rather than using the default format above.
Show the PR URL and a one-line summary.
Next: build workflow complete. Watch for review comments — run
crew resolve PRif they arrive.
After creating the PR, resolve TASK_DIR and append to $TASK_DIR/SESSION.md (if found):
if [ -n "${CREW_TASK_DIR+x}" ]; then
TASK_DIR="$CREW_TASK_DIR"
elif TASK_DIR=$(~/.agent/tools/resolve-task-dir.py 2>/dev/null); then
export CREW_TASK_DIR="$TASK_DIR"
else
echo "Warning: resolve-task-dir failed — check git remote and branch." >&2
TASK_DIR=""
fi
[TIME] crew-open-pr: PR_URL — PR_TITLE
Also log the transition:
~/.agent/tools/log-progress.py "$TASK_DIR" "COMMITTING → PR_OPEN ($PR_URL)"
Then suggest: "Want to journal this session?"