Skip to content

gh agent-task create ... Should Not Be Restricted to Only OAUTH Tokens #11845

Open

Description

@ryaugusta

The problem

Requiring OAUTH tokens only when executing agent-task commands makes it difficult to automate.
For example:
Let's say I have a workflow that performs various activities on a repository or migrates that repository to another organization. Once that first step is completed, I want to assign copilot a task to go off and do something on the destination repository as outlined in a copilot-instructions.md file. I can't just call gh agent-task create -R <org/repo> -F copilot-instructions.md as this will return an error:

this command requires an OAuth token. Re-authenticate with: gh auth login

In most if not all previous steps I can perform other gh cli commands by having one of the following:

env:
  GITHUB_TOKEN: ${{ github.token }}

or

env:
  GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

When specifically setting the GITHUB_TOKEN env to my personal access token, I still cannot run a create option for the agent-task command.

The workaround for this is to use a self-hosted runner and run:

`gh auth login`
`gh agent-task create ... `

When the workflow reaches this step, the workflow pauses and waits for me to follow the device-code flow, then will proceed - not ideal for hands-off automation

Proposed solution

Do not restrict agent-task commands to be OAUTH required (the requireOAuthToken func will need to change)

OR

Potentially provide a copilot permissions section when generating a PAT/creating an App and allow us to automate creating a task for copilot.

Looking forward to a discussion on this 🚀

Activity

  1. added
    enhancement
    on Oct 2, 2025
  2. github-actions commented on Oct 2, 2025

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as a feature request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  3. added
    needs-triage
    on Oct 2, 2025
  4. guidocelada commented on Oct 3, 2025

    @guidocelada

    +1

  5. added
    gh-agent-task
    on Oct 6, 2025
  6. BagToad commented on Oct 6, 2025

    @BagToad
    Member

    Thank you for the great issue @guidocelada ✨

    I think this is blocked currently on the API requiring an OAuth token, but it's something that we're in active discussions about. I've labelled it as blocked for now.

    To anyone that comes across this issue, please react to the original post as we use that count for enhancement discussions and prioritization ❤️ And we'd love to hear any other use-cases as well - those are very interesting and helpful to us.

  7. added
    platform
    on Oct 6, 2025
  8. Houndie commented on Oct 9, 2025

    @Houndie

    Hi @BagToad, the job API definitely accepts PATs! It doesn't work (yet) with fine-grained tokens, but "classic" PATs should work just fine.

    As it turns out I'm very wrong here...there's staff exceptions I didn't know about! @BagToad is correct about the blockers

  9. guidocelada commented on Oct 10, 2025

    @guidocelada

    @BagToad This is my use case:

    # This action deletes feature toggles from multiple repositories using AI (Github Copilot).
    # It creates a pull request in each repository to remove the specified feature toggle branch.
    name: Feature Toggle Slayer - Github Copilot
    
    on:
      workflow_dispatch:
        inputs:
          dry_run:
            description: 'Dry run mode - show what would be created without actually creating tasks'
            required: false
            type: boolean
            default: false
          repo_filter:
            description: 'Comma-separated list of repos to target (e.g., Glovo/repo1,Glovo/repo2). Leave empty for all repos.'
            required: false
            type: string
            default: ''
    
    permissions:
      contents: read        # Read repository contents for checkout
      actions: write        # Required for gh agent-task create
    
    jobs:
      create-agent-tasks:
        name: "Feature Toggle Slayer - Create Agent Tasks"
        runs-on: glovo-shared-small-arm
        steps:
          - name: Install GitHub CLI
            run: >
              (type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) 
              && sudo mkdir -p -m 755 /etc/apt/keyrings 
              && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg 
              && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null 
              && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg 
              && sudo mkdir -p -m 755 /etc/apt/sources.list.d 
              && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null 
              && sudo apt update 
              && sudo apt install gh -y
    
          - name: Login to GitHub CLI
            run: gh auth login
    
          - name: Checkout repository
            uses: actions/checkout@v4
    
          - name: Parse and filter feature toggles
            id: parse_feature_toggles
            run: |
              # Read the JSON file
              echo "Reading feature toggles from ./data/feature_toggles_stats.json..."
              FEATURE_TOGGLES_JSON=$(cat ./data/feature_toggles_stats.json)
              
              # Keep only the boolean FTs, with no rules (empty array), with healthy != 'Y'
              # with non empty 'usages', and mobile = null
              FILTERED_FTS=$(echo "$FEATURE_TOGGLES_JSON" | jq -c '.[] | select(.ft_type == "BOOLEAN" and (.rules | length == 0) and (.healthy != "Y") and (.usages | length > 0) and (.mobile == null)) | {name: .name, repo: .usages[0].github_project, toggle_value_to_keep: .default_value}')
              
              # Map to the following structure
              # [{ "repo": "Glovo/repo1", "toggle_name": "SHOULD_WORK", "toggle_value_to_keep": false }]
              FEATURE_TOGGLES=$(echo "$FILTERED_FTS" | jq -s '[.[] | {repo: .repo, toggle_name: .name, toggle_value_to_keep: .toggle_value_to_keep}]')
              
              # Apply repo filter if specified
              REPO_FILTER="${{ inputs.repo_filter }}"
              if [ -n "$REPO_FILTER" ]; then
                echo "Applying repo filter: $REPO_FILTER"
                # Convert comma-separated list to jq array format
                REPO_ARRAY=$(echo "$REPO_FILTER" | jq -R 'split(",") | map(gsub("^\\s+|\\s+$";""))')
                echo "Repo filter array: $REPO_ARRAY"
                FEATURE_TOGGLES=$(echo "$FEATURE_TOGGLES" | jq --argjson repos "$REPO_ARRAY" '[.[] | select(.repo as $r | $repos | index($r) != null)]')
              fi
              
              echo "Final FTs to process: $(echo "$FEATURE_TOGGLES" | jq .)"
              
              # Save to a file for the next step
              echo "$FEATURE_TOGGLES" > /tmp/feature_toggles.json
    
          - name: Create Agent Tasks for each Feature Toggle
            run: |
              # Read the feature toggles
              FEATURE_TOGGLES=$(cat /tmp/feature_toggles.json)
              
              # Get the count
              FT_COUNT=$(echo "$FEATURE_TOGGLES" | jq 'length')
              echo "Processing $FT_COUNT feature toggles..."
              
              # Loop through each feature toggle
              echo "$FEATURE_TOGGLES" | jq -c '.[]' | while read -r ft; do
                REPO=$(echo "$ft" | jq -r '.repo')
                TOGGLE_NAME=$(echo "$ft" | jq -r '.toggle_name')
                TOGGLE_VALUE=$(echo "$ft" | jq -r '.toggle_value_to_keep')
                
                echo ""
                echo "================================================"
                echo "Processing: $TOGGLE_NAME in $REPO"
                echo "================================================"
                
                # Read the prompt template and substitute the variables
                PROMPT_CONTENT=$(cat ./.github/actions/feature-toggle-slayer/prompt.md | \
                  sed "s#__TOGGLE_NAME__#${TOGGLE_NAME}#g" | \
                  sed "s#__TOGGLE_VALUE_TO_KEEP__#${TOGGLE_VALUE}#g" | \
                  sed "s#__REPO__#${REPO}#g")
                
                # Create a temporary file with the substituted content
                TEMP_PROMPT=$(mktemp)
                echo "$PROMPT_CONTENT" > "$TEMP_PROMPT"
                
                # Check if dry run mode is enabled
                if [ "${{ inputs.dry_run }}" = "true" ]; then
                  echo "🔍 DRY RUN MODE - Would create agent task with:"
                  echo "Repository: $REPO"
                  echo "Toggle Name: $TOGGLE_NAME"
                  echo "Toggle Value to Keep: $TOGGLE_VALUE"
                  echo ""
                  echo "Prompt content:"
                  echo "----------------------------------------"
                  cat "$TEMP_PROMPT"
                  echo "----------------------------------------"
                else
                  # Create the agent task with the processed prompt
                  echo "Creating agent task for $TOGGLE_NAME in $REPO..."
                  gh agent-task create --repo "$REPO" --from-file "$TEMP_PROMPT"
                  echo "✅ Agent task created successfully!"
                fi
                
                # Clean up the temporary file
                rm "$TEMP_PROMPT"
              done
              
              echo ""
              echo "================================================"
              echo "✅ All agent tasks processed!"
              echo "================================================"
    
    ## Main task
    Your task is to remove a feature toggle from the codebase.
    Remove all code that executes when the toggle is not equal to __TOGGLE_VALUE_TO_KEEP__. 
    
    ## Context:
    Toggle uses FeatureToggleClient#getBooleanValue from com.glovoapp.featuretoggles.sdk and passes "__TOGGLE_NAME__" as argument to fetch the feature toggle value.
    
    ## Instructions:
    - Find the toggle: Search for all occurrences of __TOGGLE_NAME__ in the codebase. 
    - Look for conditional statements using this toggle.
    - Remove the paths in which the toggle is not equal to __TOGGLE_VALUE_TO_KEEP__.
    - Keep only the code that executes when the toggle is equal to __TOGGLE_VALUE_TO_KEEP__.
    - Do not add any new comments to the code.
    - I cannot do anything locally, so you must provide exact code changes that do not require any manual intervention from me.
    - Ensure to also consider the unit and integration tests while removing the toggle.
    
    ## Clean up:
    - Remove unused imports, variables, or helper functions only used by the toggle logic.
    - Remove all the dead code depending on the code that was just removed.
    
    ## Verification:
    - Confirm all instances of __TOGGLE_NAME__ are removed
    - Ensure no other toggles were accidentally modified
    - Check that code logic remains valid
    
    ## Testing:
    - If you are not able to build or run tests, do not try to fix them by modifying gradle or test configurations. This is critical.
    - Examples of tests you SHOULD remove:
        - Test that mocks FeatureToggleClient for "__TOGGLE_NAME__" where value is not __TOGGLE_VALUE_TO_KEEP__
        - Test that validates specific behavior when toggle is not __TOGGLE_VALUE_TO_KEEP__
        - Test that explicitly checks the removed code path
    - Examples of tests you MUST NOT remove (fix your code instead):
      - Tests that don't reference __TOGGLE_NAME__ at all
      - Tests that set the toggle to __TOGGLE_VALUE_TO_KEEP__
      - Tests for general functionality that should work regardless of the toggle
      - Integration tests that test the overall feature behavior
      - Tests that validate business logic that should remain after toggle removal
    
    # Final result summary:
    When you finish, include a final result summary, including:
    - Explain what the toggle was doing, and what's the behaviour after your changes.
    - A clarification if you could not run the build or tests, and why.
    - Summary of changes you did, including:
        - A summary of all the work you did.
        - Which assumptions you made.
        - Which tests you REMOVED and why.
        - Which tests you FIXED and why.
    - The full initial prompt used to generate this result.

    I need to run it on a schedule every week or so.

  10. guidocelada commented on Oct 10, 2025

    @guidocelada

    Can you also clarify which scopes are required for gh agent-task create please?

  11. Houndie commented on Oct 10, 2025

    @Houndie

    @guidocelada I'm not super knowledgeable on actions, but what I think you're going to want to do is create a log-lived PAT (settings->Developer Settings->Personal Access Tokens->Generate a new token (classic). For classic tokens, you should be good to give it repo permissions (if fine-grained tokens ever start working, you'd want "pull_request:write" and "actions:write", but those are both rolled up into the repo permissions on a classic token).

    This is where my knowledge gets a bit fuzzy, but I don't think you can ever use the secret.GITHUB_TOKEN that comes with the action, since I don't think they're user scoped, and copilot always requires user tokens to use for billing purposes, so you'll need to inject a PAT into your action.

  12. removed
    needs-triage
    on Nov 10, 2025
  13. cpatel-mck commented on Nov 13, 2025

    @cpatel-mck

    Hello, I'm running into the same issue when I try to assign a GitHub issue to Copilot agent using GitHub actions. I tried creating a PAT classic and FGT token under my profile (as I have a enterprise copilot license) but still when I try running gh agent-task create "my-agent" -a "my-agent" -R "https://github.com/<my_gh_org/<my_gh_repo>" I get this command requires an OAuth token. Re-authenticate with: gh auth login

    I tried running echo "${{ secrets.MY_TOKEN }}" | gh auth login --with-token just before gh-agent-task.. command above, while the login is successful, I still get this command requires an OAuth token. Re-authenticate with: gh auth login error.

  14. BagToad commented on Nov 13, 2025

    @BagToad
    Member

    Hey @cpatel-mck, this is currently intended behavior you're seeing due to API requirements, but it's a known request that is being tracked internally.

  15. ALUIZDEB commented on Dec 10, 2025

    @ALUIZDEB

    Any updates here guys? Or workarrounds?

    I think this is a important use case for a lot of people!

  16. asklar commented on Dec 10, 2025

    @asklar

    for now I'm using the gh cli to create an issue and assign it to ghcp, but that's certainly less magical than have it show up in Sessions

  17. ALUIZDEB commented on Dec 11, 2025

    @ALUIZDEB

    for now I'm using the gh cli to create an issue and assign it to ghcp, but that's certainly less magical than have it show up in Sessions

    I also do this here from my side. But I need to select a "Feature Branch", not default branch... =(

  18. goataka commented on Jan 25, 2026

    @goataka

    +1

  19. vinicius-oa commented on Feb 8, 2026

    @vinicius-oa

    any workaround?

  20. alexef commented on Feb 8, 2026

    @alexef
  21. added
    pitch
    on Mar 10, 2026
  22. cameronfleet-paxos commented on Mar 16, 2026

    @cameronfleet-paxos

    +1, this is a blocker to even doing basic slackbots / building ontop of GH Agent HQ as an agent executor platform.

  23. clement911 commented on Apr 23, 2026

    @clement911

    We also ran into that same issue.
    Can gh agent-test create not be automated?

  24. keithballdotnet commented on Apr 23, 2026

    @keithballdotnet

    Blocked. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedenhancementgh-agent-taskpitchplatform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions