name: Claude Issue Solver
on:
issues:
types: [labeled]
jobs:
analyze-and-fix:
# Only run when 'claude-fix' label is added
if: github.event.action == 'labeled' && github.event.label.name == 'claude-fix'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better context
- name: Set up Git user
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create fix branch
id: branch
run: |
BRANCH_NAME="fix/issue-${{ github.event.issue.number }}"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
A new GitHub issue has been created that needs investigation:
**Issue #${{ github.event.issue.number }}**
**Title:** ${{ github.event.issue.title }}
**Description:**
${{ github.event.issue.body }}
Please:
1. Analyze this issue and determine if you can implement a fix
2. Search the codebase to understand the relevant code
3. If you can fix it, make the necessary code changes
4. Commit your changes with a descriptive message referencing the issue
If you cannot fix this issue (unclear requirements, needs human decision,
too complex, etc.), do NOT make any commits. The workflow will add a comment
explaining that human review is needed.
Guidelines:
- Only make changes directly related to the issue
- Follow existing code patterns and style
- Include tests if the area has test coverage
- Reference the issue number in commits: "fixes #${{ github.event.issue.number }}"
- Do not push to remote - the workflow handles that
claude_args: "--max-turns 15"
- name: Check for changes
id: changes
run: |
if git diff --quiet HEAD origin/main; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Push branch and create PR
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin "${{ steps.branch.outputs.branch_name }}"
gh pr create \
--title "Fix: ${{ github.event.issue.title }}" \
--body "$(cat <<'EOF'
## Summary
Automated fix attempt for #${{ github.event.issue.number }}
**Issue:** ${{ github.event.issue.title }}
---
> This PR was automatically generated by Claude Code. Please review carefully before merging.
Closes #${{ github.event.issue.number }}
EOF
)" \
--base main \
--head "${{ steps.branch.outputs.branch_name }}" \
--draft
- name: Comment on issue (no fix possible)
if: steps.changes.outputs.has_changes == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue comment ${{ github.event.issue.number }} \
--body "🤖 I analyzed this issue but couldn't generate an automated fix. This may require:
- Clarification on the requirements
- Human decision-making on the approach
- Changes that are too complex for automated fixing
A human developer should investigate further."