Skip to content

Request help in internal slack: Solve the problem where the Copilot cloud agent does not reliably select the specified topic branch as the base for its work when it starts working. #1939

Description

@edburns

To share in #coding-agent slack channel.

Executive Summary

Is there a way to specify the base branch the coding agent should use upon assignment using gh? Consider this:

gh issue edit $TASK_ISSUE --add-assignee "@copilot" -R $REPO

QUESTION: Is there a --base-branch option? I did RTFM and did not see such a thing.

Details

I am working on a low-key system that uses a combination of scripting, and skills to shepherd issues from "assigned to copilot" to "merged to the specified (almost always non-main) base branch. The script has things like this:

status "Phase 1: Launching copilot --yolo for task #$TASK_ISSUE"

PHASE1_PROMPT="Invoke skill \`shepherd-task-to-ready\` with these inputs:

- TASK_ISSUE: $TASK_ISSUE
- BASE_BRANCH: $BASE_BRANCH
- REPO: $REPO"

status "Phase 1 prompt:"
echo "$PHASE1_PROMPT"
echo "$PHASE1_PROMPT" | copilot --yolo

status "Phase 1: copilot exited. Verifying state..."

# --- Verify Phase 1 outcome ---
PR_NUMBER=$(find_linked_pr) || fail "No open PR found linked to issue #$TASK_ISSUE after Phase 1."
status "Found PR #$PR_NUMBER"

There is a bunch of text in the skill that assigns the issue to copilot and tries to specify the base branch, but it doesn't work reliably. Here's the skill if you're curious: link to skill.

DETAIL_QUESTION: What I'm looking for is a way for gh to programmatically do the analog of the Select base branch component here:

Image

Copilot research

Showing my work that lead me to ask the question here.

Prompt

Consider this question about the gh CLI:

Is there a way to specify the base branch the coding agent should use using gh?

gh issue edit $TASK_ISSUE --add-assignee "@copilot" -R $REPO

Is there a --base-branch option?

Response

No,  gh issue edit  does not have a  --base-branch  option.

The way to specify a base branch for the Copilot coding agent is not via  gh issue edit  — instead, you use  gh api  to set it via the GitHub API when creating the Copilot agent task. Specifically, you'd POST to the issue with the base branch encoded in the request body, or create a PR with a specific base.

The more direct approach is to use the Copilot API endpoint:

gh api repos/$REPO/copilot/tasks
--method POST
-f issue_number=$TASK_ISSUE
-f base_branch=main

Or, since assigning  @copilot  triggers the agent automatically, you can create the branch first and then set it as the default in your repo context before assigning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions