claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

Create PR from issue doesn't work - there's not anything to compare

Open Karabiy opened this issue 1 year ago • 10 comments

Image

Using this specific worfkflow

name: Claude PR Assistant

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]
  pull_request_review:
    types: [submitted]

jobs:
  claude-code-action:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Run Claude PR Action
        uses: anthropics/claude-code-action@beta
        with:
          anthropic_api_key: ${{ secrets.CLAUDE_API_KEY }}
          timeout_minutes: "60"

I can see reasoning, and what's exactly to change there, but PR part fails I've got PR url on top, job is done and no link at the bottom

Image Using official app for an installation

Karabiy avatar May 22 '25 18:05 Karabiy

Hi there! 👋

The "There isn't anything to compare." error typically occurs when Claude doesn't have the right permissions or tools to create branches.

Here are the two key changes you need to make:

  1. Update permissions to include write access:

    permissions:
      contents: write      # Changed from read to write
      pull-requests: write # Changed from read to write
      issues: read
      id-token: write
    
  2. Add Git commands to the allowed_tools parameter:

    allowed_tools: Bash(git status),Bash(git checkout -b claude-*),Bash(git add *),Bash(git commit *),Bash(git push origin HEAD:claude-*)
    

For security, notice how I've prefixed branch names with claude-* in the commands. This ensures that Claude can only create and push to branches with that prefix, protecting your main branches from accidental modification.

Let me know if it works!

TorbenWetter avatar May 23 '25 08:05 TorbenWetter

@TorbenWetter that's not entirely accurate. You shouldn't need to change those permissions generally. The Claude app uses its own github token with the appropriate permissions (unless you pass in a github_token parameter, which overrides the app token). By default, Claude also only gets access to committing to a single branch (either a newly created claude-* branch when tagged on an issue or the PR branch when tagged on a PR). So those allowed tools should not be necessary for typical use. We need to document this more clearly.

@Karabiy it sounds like this may just be a bug or model error. Since we released Claude Sonnet 4 and Claude Opus 4 today, could you try again and see if the issue persists? Sonnet 4 is now the default model, and should be less prone to these types of mistakes than 3.7 was.

ashwin-ant avatar May 23 '25 08:05 ashwin-ant

@ashwin-ant Sorry for the incorrect advice and thanks for clarifying!

Could this issue possibly be related to #29?

TorbenWetter avatar May 23 '25 08:05 TorbenWetter

Might be slightly stupid to give this as a reply, but still Claude analysis on the root cause

Analysis of Permission Issues
I can now explain what permissions were lacking in the previous attempts:

Current Situation:

The current branch (claude/issue-2-20250523_211428) is clean with no local changes
The repository only contains a README.md file locally
Previous changes appear to have been lost or were never properly applied
Permission Issues from Previous Attempts:

Bash tool access: The previous attempts tried to use git commands directly via Bash, but I don't have Bash permissions in this session
GitHub API tool access: I also don't have access to mcp__github__get_file_contents to read the workflow file from GitHub
File system limitations: The local checkout appears to be minimal (only README.md), suggesting the workflow files aren't in the local workspace
What This Means:
The previous comments saying "changes applied locally" were likely incorrect. Without proper tool permissions, the changes were never actually made to any files.

Next Steps:
To properly fix the JSON import issues, you would need to either:

Grant me additional tool permissions by updating my allowed tools to include:

Bash (for git commands and file operations)
mcp__github__get_file_contents (to read files from GitHub)
Other file system tools as neede

I've tested it just now, issue still is present

Karabiy avatar May 23 '25 21:05 Karabiy

I had the same issue, but resolved it with the following steps.

Update GitHub Token

unset GH_TOKEN
gh auth login
gh auth refresh -h github.com -s workflow

Run Claude

claude

Install GitHub App

/install-github-app

And you can create the PR from claude code.

name: Claude Code

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]
  pull_request_review:
    types: [submitted]

jobs:
  claude:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
      (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Run Claude Code
        id: claude
        uses: anthropics/claude-code-action@beta
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

hampen2929 avatar May 25 '25 17:05 hampen2929

I am also running into that issue recently.

In the action logs I can see the tools:

  • mcp__github__create_or_update_file & mcp__github_file_ops__commit_files is in the list of tools
{
    "type": "system",
    "subtype": "init",
    "session_id": "f0af72ca-(redacted)",
    "tools": [
      "Task",
      "Bash",
      "Glob",
      "Grep",
      "LS",
      "Read",
      "Edit",
      "MultiEdit",
      "Write",
      "NotebookRead",
      "NotebookEdit",
      "TodoRead",
      "TodoWrite",
      "mcp__github_file_ops__commit_files",
      "mcp__github_file_ops__delete_files",
      "mcp__github__add_issue_comment",
      "mcp__github__add_pull_request_review_comment",
      "mcp__github__create_branch",
      "mcp__github__create_issue",
      "mcp__github__create_or_update_file",
      "mcp__github__create_pull_request",
      "mcp__github__create_pull_request_review",
      "mcp__github__create_repository",
      "mcp__github__delete_file",
      "mcp__github__fork_repository",
      "mcp__github__get_code_scanning_alert",
      "mcp__github__get_commit",
      "mcp__github__get_file_contents",
      "mcp__github__get_issue",
      "mcp__github__get_issue_comments",
      "mcp__github__get_me",
      "mcp__github__get_pull_request",
      "mcp__github__get_pull_request_comments",
      "mcp__github__get_pull_request_files",
      "mcp__github__get_pull_request_reviews",
      "mcp__github__get_pull_request_status",
      "mcp__github__get_secret_scanning_alert",
      "mcp__github__get_tag",
      "mcp__github__list_branches",
      "mcp__github__list_code_scanning_alerts",
      "mcp__github__list_commits",
      "mcp__github__list_issues",
      "mcp__github__list_pull_requests",
      "mcp__github__list_secret_scanning_alerts",
      "mcp__github__list_tags",
      "mcp__github__merge_pull_request",
      "mcp__github__push_files",
      "mcp__github__search_code",
      "mcp__github__search_issues",
      "mcp__github__search_repositories",
      "mcp__github__search_users",
      "mcp__github__update_issue",
      "mcp__github__update_issue_comment",
      "mcp__github__update_pull_request",
      "mcp__github__update_pull_request_branch",
      "mcp__github__update_pull_request_comment"
    ],
    "mcp_servers": [
      {
        "name": "github_file_ops",
        "status": "connected"
      },
      {
        "name": "github",
        "status": "connected"
      }
    ]
  },

And then later in the messages I see errors on using these two tools:

{
    "type": "assistant",
    "message": {
      "id": "msg_01EgxtZfmDVhZehzv4JEUvhM",
      "type": "message",
      "role": "assistant",
      "model": "claude-sonnet-4-20250514",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_01XkH7G4MQFAb55UCDCKztA5",
          "name": "mcp__github_file_ops__commit_files",
          "input": {
            "files": [
              ".github/workflows/smoke_test.yaml"
            ],
            "message": "fix: (redacted)"
          }
        }
      ],
      "stop_reason": "tool_use",
      "stop_sequence": null,
      "usage": {
        "input_tokens": 5,
        "cache_creation_input_tokens": 1451,
        "cache_read_input_tokens": 41280,
        "output_tokens": 230,
        "service_tier": "standard"
      }
    },
    "session_id": "f0af72ca-07e8-48c8-ac5c-2cb8b27350e2"
  },
  {
    "type": "user",
    "message": {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "content": "Error calling tool commit_files: undefined",
          "is_error": true,
          "tool_use_id": "toolu_01XkH7G4MQFAb55UCDCKztA5"
        }
      ]
    },
    "session_id": "f0af72ca-07e8-48c8-ac5c-2cb8b27350e2"
  },
  {
    "type": "assistant",
    "message": {
      "id": "msg_01LgBpMeV5dizfDeonU2XVis",
      "type": "message",
      "role": "assistant",
      "model": "claude-sonnet-4-20250514",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_01TqUZ7wCmuoXxZcEhZRvkP8",
          "name": "mcp__github__create_or_update_file",
          "input": {
            "owner": "(redacted)",
            "repo": "(redacted)",
            "path": ".github/workflows/smoke_test.yaml",
            "content": "name: (redacted)",
            "message": "fix: (redacted)",
            "branch": "claude/issue-549-20250526_154150"
          }
        }
      ],
      "stop_reason": "tool_use",
      "stop_sequence": null,
      "usage": {
        "input_tokens": 6,
        "cache_creation_input_tokens": 257,
        "cache_read_input_tokens": 42731,
        "output_tokens": 677,
        "service_tier": "standard"
      }
    },
    "session_id": "f0af72ca-07e8-48c8-ac5c-2cb8b27350e2"
  },
  {
    "type": "user",
    "message": {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "content": "Claude requested permissions to use mcp__github__create_or_update_file, but you haven't granted it yet.",
          "is_error": true,
          "tool_use_id": "toolu_01TqUZ7wCmuoXxZcEhZRvkP8"
        }
      ]
    },
    "session_id": "f0af72ca-07e8-48c8-ac5c-2cb8b27350e2"
  },

FabianHertwig avatar May 26 '25 16:05 FabianHertwig

FWIW, I tried everything listed in this thread, none of them worked. What I ended up doing is issuing my own GitHub Personal Access Token, adding it as a secret to the repo, then changing the workflow yaml to use my own GitHub token:

name: Claude Code

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]
  pull_request_review:
    types: [submitted]

jobs:
  claude:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
      (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Set up Elixir and OTP
        uses: erlef/setup-beam@v1
        with:
          elixir-version: '1.17.3'
          otp-version: '27.1'
          version-type: strict

      - name: Run Claude Code
        id: claude
        uses: anthropics/claude-code-action@beta
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          github_token: ${{ secrets.GH_TOKEN }}

thmsmlr avatar May 27 '25 00:05 thmsmlr

@thmsmlr which permissions have you put for your PAT?

Karabiy avatar May 27 '25 11:05 Karabiy

I've been running into a similar error when Claude tries to commit a file. In my case, it was the mcp__github_file_ops__commit_files tool and it results in a 403 error.

  {
    "type": "assistant",
    "message": {
      "id": "msg_01GWvyGf5KeuyCzxZ7vRWcMx",
      "type": "message",
      "role": "assistant",
      "model": "claude-sonnet-4-20250514",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_01PDNNFfoDuEPiuqkayWnBVk",
          "name": "mcp__github_file_ops__commit_files",
          "input": {
            "files": [
              ".github/workflows/ci.yaml"
            ],
            "message": "ci: migrate CI workflow from Terraform to OpenTofu\n\n<snip>"
          }
        }
      ],
      "stop_reason": "tool_use",
      "stop_sequence": null,
      "usage": {
        "input_tokens": 0,
        "cache_creation_input_tokens": 1446,
        "cache_read_input_tokens": 58852,
        "output_tokens": 211,
        "service_tier": "standard"
      }
    },
    "session_id": "5cc83665-e22b-4157-9c74-e39e32ef9206"
  },
  {
    "type": "user",
    "message": {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "content": "Error calling tool commit_files: Failed to create tree: 403 - {\"message\":\"Resource not accessible by integration\",\"documentation_url\":\"https://docs.github.com/rest/git/trees#create-a-tree\",\"status\":\"403\"}",
          "is_error": true,
          "tool_use_id": "toolu_01PDNNFfoDuEPiuqkayWnBVk"
        }
      ]
    },
    "session_id": "5cc83665-e22b-4157-9c74-e39e32ef9206"
  },

It looks like the issue results from asking Claude to update a file under .github/workflows, an operation which requires an extra set of permissions - Workflows: write in addition to Contents: write (source: Github docs). This would apply to @FabianHertwig's example above as well.

Perhaps this permission is not available for the key returned from exchangeForAppToken(oidcToken).

My workaround is to create a personal access token which has the Workflows permission set to "Read and Write" and explicitly set that, as suggested by @thmsmlr. This has resolved the issue for me.

tobyjsullivan avatar May 28 '25 03:05 tobyjsullivan

@tobyjsullivan Thank you!!! It worked for me.

gizumon avatar Jul 09 '25 02:07 gizumon