From b61185b14c406b7dbdfbc88d8e0eb2d7194052c3 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 13:55:00 -0700 Subject: [PATCH 01/30] Test: Update README title for workflow testing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce976ef08..38b7cab6e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Claude Code Action responding to a comment](https://github.com/user-attachments/assets/1d60c2e9-82ed-4ee5-b749-f9e021c85f4d) -# Claude Code Action +# Claude Code Action - TEST CHANGE A general-purpose [Claude Code](https://claude.ai/code) action for GitHub PRs and issues that can answer questions and implement code changes. This action listens for a trigger phrase in comments and activates Claude act on the request. It supports multiple authentication methods including Anthropic direct API, Amazon Bedrock, and Google Vertex AI. From 8052d271cef48cd3809d92fb118fe0a714dfe42c Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 14:00:48 -0700 Subject: [PATCH 02/30] Enable PR review submission and remove old workflow - Add back review submission tools to allow Claude to comment - Keep using v1-dev with the fixed agent mode - This replaces the old claude-review.yml functionality --- .github/workflows/claude-auto-review-test.yml | 6 ++-- .github/workflows/claude-review.yml | 33 ------------------- undefined/claude-prompts/claude-prompt.txt | 1 + 3 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 .github/workflows/claude-review.yml create mode 100644 undefined/claude-prompts/claude-prompt.txt diff --git a/.github/workflows/claude-auto-review-test.yml b/.github/workflows/claude-auto-review-test.yml index 87f4c0087..a7db466f9 100644 --- a/.github/workflows/claude-auto-review-test.yml +++ b/.github/workflows/claude-auto-review-test.yml @@ -44,6 +44,6 @@ jobs: Use inline comments to highlight specific areas of concern. After your review, submit a proper GitHub review with your findings. - # Only include essential tools for reviewing (no submitting) - # This prevents multiple review submissions - claude_args: "--allowedTools Bash,Read,Grep,mcp__github-comment-server__get_pull_request_diff,mcp__github-comment-server__get_pull_request_files,mcp__github-comment-server__get_pull_request" + # Include tools needed for submitting PR reviews + # Note: mcp__github__ tools are from @main version, mcp__github-comment-server__ are from @v1-dev + claude_args: "--allowedTools Bash,Read,Grep,mcp__github-comment-server__get_pull_request_diff,mcp__github-comment-server__get_pull_request_files,mcp__github-comment-server__get_pull_request,mcp__github-comment-server__create_pending_pull_request_review,mcp__github-comment-server__add_comment_to_pending_review,mcp__github-comment-server__submit_pending_pull_request_review" diff --git a/.github/workflows/claude-review.yml b/.github/workflows/claude-review.yml deleted file mode 100644 index 10706cc20..000000000 --- a/.github/workflows/claude-review.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Auto review PRs - -on: - pull_request: - types: [opened] - -jobs: - auto-review: - permissions: - contents: read - id-token: write - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Auto review PR - uses: anthropics/claude-code-action@main - with: - direct_prompt: | - Please review this PR. Look at the changes and provide thoughtful feedback on: - - Code quality and best practices - - Potential bugs or issues - - Suggestions for improvements - - Overall architecture and design decisions - - Documentation consistency: Verify that README.md and other documentation files are updated to reflect any code changes (especially new inputs, features, or configuration options) - - Be constructive and specific in your feedback. Give inline comments where applicable. - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - allowed_tools: "mcp__github__create_pending_pull_request_review,mcp__github__add_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,mcp__github__get_pull_request_diff" diff --git a/undefined/claude-prompts/claude-prompt.txt b/undefined/claude-prompts/claude-prompt.txt new file mode 100644 index 000000000..8e2256454 --- /dev/null +++ b/undefined/claude-prompts/claude-prompt.txt @@ -0,0 +1 @@ +Custom prompt content \ No newline at end of file From 44dd9dd8a8e1daa5b785d00413231ffb58aa2f97 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 14:01:41 -0700 Subject: [PATCH 03/30] Final test: Update README for complete review workflow test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 38b7cab6e..b7c3decc2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Claude Code Action responding to a comment](https://github.com/user-attachments/assets/1d60c2e9-82ed-4ee5-b749-f9e021c85f4d) -# Claude Code Action - TEST CHANGE +# Claude Code Action (Final Test) A general-purpose [Claude Code](https://claude.ai/code) action for GitHub PRs and issues that can answer questions and implement code changes. This action listens for a trigger phrase in comments and activates Claude act on the request. It supports multiple authentication methods including Anthropic direct API, Amazon Bedrock, and Google Vertex AI. From 57cb0d982891f675d680aa8a9ffd5c14711c8c40 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 14:54:48 -0700 Subject: [PATCH 04/30] Match old workflow exactly - prevent approvals - Use exact same permissions as old workflow - Use fetch-depth: 1 like old workflow - Remove timeout and extra features - Only trigger on opened PRs - Use claude_args with --allowedTools format --- .github/workflows/claude-auto-review-test.yml | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/.github/workflows/claude-auto-review-test.yml b/.github/workflows/claude-auto-review-test.yml index a7db466f9..98ae27eeb 100644 --- a/.github/workflows/claude-auto-review-test.yml +++ b/.github/workflows/claude-auto-review-test.yml @@ -1,49 +1,33 @@ -name: Claude PR Review (Fixed) +name: Auto review PRs on: pull_request: - types: [opened, synchronize] - workflow_dispatch: - inputs: - pr_number: - description: "PR number to review" - required: false - type: string + types: [opened] jobs: auto-review: - runs-on: ubuntu-latest permissions: contents: read - pull-requests: write - issues: write id-token: write + runs-on: ubuntu-latest + steps: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - - name: Automatic PR Review + - name: Auto review PR uses: anthropics/claude-code-action@v1-dev with: - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - timeout_minutes: "60" prompt: | - Please review this pull request and provide comprehensive feedback. - - Focus on: + Please review this PR. Look at the changes and provide thoughtful feedback on: - Code quality and best practices - Potential bugs or issues - - Performance considerations - - Security implications - - Test coverage - - Documentation updates if needed - - Provide constructive feedback with specific suggestions for improvement. - Use inline comments to highlight specific areas of concern. + - Suggestions for improvements + - Overall architecture and design decisions + - Documentation consistency: Verify that README.md and other documentation files are updated to reflect any code changes (especially new inputs, features, or configuration options) - After your review, submit a proper GitHub review with your findings. - # Include tools needed for submitting PR reviews - # Note: mcp__github__ tools are from @main version, mcp__github-comment-server__ are from @v1-dev - claude_args: "--allowedTools Bash,Read,Grep,mcp__github-comment-server__get_pull_request_diff,mcp__github-comment-server__get_pull_request_files,mcp__github-comment-server__get_pull_request,mcp__github-comment-server__create_pending_pull_request_review,mcp__github-comment-server__add_comment_to_pending_review,mcp__github-comment-server__submit_pending_pull_request_review" + Be constructive and specific in your feedback. Give inline comments where applicable. + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + claude_args: "--allowedTools mcp__github-comment-server__create_pending_pull_request_review,mcp__github-comment-server__add_comment_to_pending_review,mcp__github-comment-server__submit_pending_pull_request_review,mcp__github-comment-server__get_pull_request_diff" From 14e99e2a2bc46ce01dd0355ad56a2029ee4abde5 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:21:12 -0700 Subject: [PATCH 05/30] Add auto-review workflow for testing --- .github/workflows/claude-auto-review.yml | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/claude-auto-review.yml diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml new file mode 100644 index 000000000..cc9528ab7 --- /dev/null +++ b/.github/workflows/claude-auto-review.yml @@ -0,0 +1,39 @@ +name: Auto Review PRs + +on: + pull_request: + types: [opened, synchronize] + +jobs: + auto-review: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + issues: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Auto review PR + uses: anthropics/claude-code-action@v1-dev + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + prompt: | + Please review this pull request and provide comprehensive feedback. + + Focus on: + - Code quality and best practices + - Potential bugs or issues + - Suggestions for improvements + - Overall architecture and design decisions + - Documentation consistency + + Use the GitHub MCP tools to create a proper PR review with comments. + You have access to mcp__github__ tools for creating and submitting reviews. + + Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). \ No newline at end of file From c9bad6e9cbaa5845d179a565d66ee844b87ca659 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:24:25 -0700 Subject: [PATCH 06/30] Allow MCP GitHub tools in auto-review workflow --- .github/workflows/claude-auto-review.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index cc9528ab7..9565f8348 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -36,4 +36,5 @@ jobs: Use the GitHub MCP tools to create a proper PR review with comments. You have access to mcp__github__ tools for creating and submitting reviews. - Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). \ No newline at end of file + Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). + claude_args: "--allowedTools mcp__github__*,Read,Grep,Glob" \ No newline at end of file From 0932e8cf26ca8ce047f22375fa6cc7f7bdbc58fb Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:26:35 -0700 Subject: [PATCH 07/30] Fix quoting in claude_args for workflow --- .github/workflows/claude-auto-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 9565f8348..9ea74bbc8 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -37,4 +37,4 @@ jobs: You have access to mcp__github__ tools for creating and submitting reviews. Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). - claude_args: "--allowedTools mcp__github__*,Read,Grep,Glob" \ No newline at end of file + claude_args: '--allowedTools "mcp__github__*,Read,Grep,Glob"' \ No newline at end of file From 583874c9e017502ea680a632a8f29b6c37802765 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:29:30 -0700 Subject: [PATCH 08/30] Explicitly list MCP tools instead of using glob --- .github/workflows/claude-auto-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 9ea74bbc8..fa2a14c40 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -37,4 +37,4 @@ jobs: You have access to mcp__github__ tools for creating and submitting reviews. Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). - claude_args: '--allowedTools "mcp__github__*,Read,Grep,Glob"' \ No newline at end of file + claude_args: '--allowedTools "mcp__github__get_pull_request,mcp__github__get_pull_request_diff,mcp__github__get_pull_request_files,mcp__github__create_pending_pull_request_review,mcp__github__add_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,Read,Grep,Glob"' \ No newline at end of file From 74ee3b534f6434897ebe5f8483083fb12a985f64 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:40:13 -0700 Subject: [PATCH 09/30] Explicitly specify PR number in prompt --- .github/workflows/claude-auto-review.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index fa2a14c40..2bf0eb20a 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -24,7 +24,7 @@ jobs: with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | - Please review this pull request and provide comprehensive feedback. + Please review pull request #${{ github.event.pull_request.number }} in the ${{ github.repository }} repository. Focus on: - Code quality and best practices @@ -34,7 +34,7 @@ jobs: - Documentation consistency Use the GitHub MCP tools to create a proper PR review with comments. - You have access to mcp__github__ tools for creating and submitting reviews. + Important: When using the GitHub MCP tools, make sure to use PR number ${{ github.event.pull_request.number }}. Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). claude_args: '--allowedTools "mcp__github__get_pull_request,mcp__github__get_pull_request_diff,mcp__github__get_pull_request_files,mcp__github__create_pending_pull_request_review,mcp__github__add_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,Read,Grep,Glob"' \ No newline at end of file From 6c58dba4ad2b17d12d4f2058ca38dc8b96b57483 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:40:58 -0700 Subject: [PATCH 10/30] Use fork's v1-dev with context prefixing --- .github/workflows/claude-auto-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 2bf0eb20a..2a5a60a47 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: Auto review PR - uses: anthropics/claude-code-action@v1-dev + uses: km-anthropic/claude-code-action@v1-dev with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | From e2e42868571a752ca6a4313e3bc23b86bd9f4330 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:49:10 -0700 Subject: [PATCH 11/30] Simplify workflow - use origin v1-dev without explicit PR number --- .github/workflows/claude-auto-review.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 2a5a60a47..4bc92e458 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -20,11 +20,11 @@ jobs: fetch-depth: 0 - name: Auto review PR - uses: km-anthropic/claude-code-action@v1-dev + uses: anthropics/claude-code-action@v1-dev with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | - Please review pull request #${{ github.event.pull_request.number }} in the ${{ github.repository }} repository. + Please review this pull request and provide comprehensive feedback. Focus on: - Code quality and best practices @@ -34,7 +34,4 @@ jobs: - Documentation consistency Use the GitHub MCP tools to create a proper PR review with comments. - Important: When using the GitHub MCP tools, make sure to use PR number ${{ github.event.pull_request.number }}. - - Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). - claude_args: '--allowedTools "mcp__github__get_pull_request,mcp__github__get_pull_request_diff,mcp__github__get_pull_request_files,mcp__github__create_pending_pull_request_review,mcp__github__add_comment_to_pending_review,mcp__github__submit_pending_pull_request_review,Read,Grep,Glob"' \ No newline at end of file + Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). \ No newline at end of file From ff46b611696fc4b6de3f52ed538448bbb26f1a75 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:52:31 -0700 Subject: [PATCH 12/30] Add explicit MCP tool instructions to workflow --- .github/workflows/claude-auto-review.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 4bc92e458..dc8bb5fe9 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -33,5 +33,11 @@ jobs: - Overall architecture and design decisions - Documentation consistency - Use the GitHub MCP tools to create a proper PR review with comments. + Steps: + 1. Use mcp__github__get_pull_request to get PR details + 2. Use mcp__github__get_pull_request_diff to see the changes + 3. Use mcp__github__create_pending_pull_request_review to start a review + 4. Use mcp__github__add_comment_to_pending_review for specific feedback + 5. Use mcp__github__submit_pending_pull_request_review with event: COMMENT to submit + Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). \ No newline at end of file From dc5d6645af3eabd13b062160762cd61e3465b977 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 12:56:53 -0700 Subject: [PATCH 13/30] Use fork's v1-dev which has context prefixing --- .github/workflows/claude-auto-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index dc8bb5fe9..644ece448 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: Auto review PR - uses: anthropics/claude-code-action@v1-dev + uses: km-anthropic/claude-code-action@v1-dev with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | From 89eda5e43220a8aa865bca74ef1c2dd84c7f0638 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 13:22:46 -0700 Subject: [PATCH 14/30] Point workflow to origin's v1-dev branch --- .github/workflows/claude-auto-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index 644ece448..dc8bb5fe9 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: Auto review PR - uses: km-anthropic/claude-code-action@v1-dev + uses: anthropics/claude-code-action@v1-dev with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | From 1dd746f3e22555d1dc7dc109e0495b320701d192 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 14:11:22 -0700 Subject: [PATCH 15/30] Add slash command for comprehensive PR review - Multi-agent review process with parallel analysis - Confidence scoring for issues (80+ threshold) - Strict formatting for GitHub comments - Uses gh CLI for all GitHub interactions --- .claude/commands/review.md | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .claude/commands/review.md diff --git a/.claude/commands/review.md b/.claude/commands/review.md new file mode 100644 index 000000000..2e74fca7d --- /dev/null +++ b/.claude/commands/review.md @@ -0,0 +1,73 @@ +--- +allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh api:*), Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Bash(gh pr review:*), Bash(gh pr list:*), Task, Read, Glob, Grep, TodoWrite +description: Code review a pull request +--- + +Provide a code review for the given pull request. + +To do this, follow these steps precisely: + +1. Use an agent to check if the pull request (a) is closed, (b) is a draft, (c) does not need a code review (eg. because it is an automated pull request, or is very simple and obviously ok), or (d) already has a code review from you from earlier. If so, do not proceed. +2. Use another agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root CLAUDE.md file (if one exists), as well as any CLAUDE.md files in the directories whose files the pull request modified +3. Use an agent to view the pull request, and ask the agent to return a summary of the change +4. Then, launch 4 parallel agents to independently code review the change. The agents should do the following: + a. Agents #1 and #2: Independently audit the changes to make sure they comply with the CLAUDE.md + b. Agent #3: Read the file changes in the pull request, then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore pre-existing issues. + c. Agent #4: Read the git blame and history of the code modified, to identify any bugs in light of that historical context +5. For each issue found in #4, launch a parallel agent that takes the PR, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or (a) a false positive bug, (b) a pedantic nitpick, or (c) a minor stylistic issues that a linter should flag. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. The scale is (give this rubric to the agent verbatim): + a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue. + b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md. + c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the PR, it's not very important. + d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach in the PR is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md. + e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this. +6. Filter out any issues with a score less than 80. If there are no issues that meet this criteria, do not proceed. +7. Finally, comment back on the pull request with a list of issues you found. When writing your comment, keep in mind to: + a. Keep your output brief + b. Avoid emojis + c. Link and cite relevant code, files, and URLs + +Notes: + +- Use `gh` to interact with Github (eg. to fetch a pull request, or to create inline comments), rather than web fetch +- Make a todo list first +- You must cite and link each bug (eg. if referring to a CLAUDE.md, you must link it) +- For your comment, follow the following format precisely (assuming for this example that you found 3 issues): + +--- + +## Auto code review + +Found 3 issues: + +1. (CLAUDE.md says "<...>") + + + +2. (some/other/CLAUDE.md says "<...>") + + + +3. (bug due to ) + + + +🤖 Generated with [Claude Code](https://claude.ai/code) + +## [ANT-ONLY] If this code review was useful, please react with 👍. Otherwise, react with 👎. + +- Or, if you found no issues: + +--- + +## Auto code review + +No issues found. Checked for bugs and CLAUDE.md compliance. + +🤖 Generated with [Claude Code](https://claude.ai/code) + +- When linking to code, follow the following format precisely, otherwise the Markdown preview won't render correctly: https://github.com/anthropics/claude-cli-internal/blob/c21d3c10bc8e898b7ac1a2d745bdc9bc4e423afe/package.json#L10-L15 + - Requires full git sha + - Repo name must match the repo you're code reviewing + - # sign after the file name + - Line range format is L[start]-L[end] + - Provide at least 1 line of context before and after, centered on the line you are commenting about (eg. if you are commenting about lines 5-6, you should link to `L4-7`) \ No newline at end of file From d6a4b9c8570975478d30f9504a32f8427e40d813 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 14:27:20 -0700 Subject: [PATCH 16/30] Add simple PR review slash command for GitHub Actions - Reviews PR using embedded GitHub Actions variables - Fetches PR details and diff using gh CLI - Posts review as comment using gh pr comment - Designed for use in automated workflows --- .claude/commands/review.md | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .claude/commands/review.md diff --git a/.claude/commands/review.md b/.claude/commands/review.md new file mode 100644 index 000000000..0978aa3d5 --- /dev/null +++ b/.claude/commands/review.md @@ -0,0 +1,44 @@ +--- +allowed-tools: Bash(gh pr view:*), Bash(gh pr diff:*), Bash(gh pr comment:*), Bash(gh api:*), Read, Glob, Grep +description: Review the current PR in GitHub Actions +--- + +Review PR #${{ github.event.pull_request.number }} and post a comment with your findings. + +## Steps + +1. Get the PR details to understand context: + ```bash + gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json title,body,author,state,isDraft,files,baseRefName,headRefName + ``` + +2. Get the diff to see what changed: + ```bash + gh pr diff ${{ github.event.pull_request.number }} --repo ${{ github.repository }} + ``` + +3. Review the changes focusing on: + - Code quality and best practices + - Potential bugs or security issues + - Performance concerns + - Missing tests or documentation + - Consistency with existing codebase + +4. Write your review to a file, then post it: + ```bash + cat > /tmp/pr-review.md << 'EOF' + ## Code Review + + [Your review here - be specific and constructive] + + 🤖 Generated with [Claude Code](https://claude.ai/code) + EOF + + gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body-file /tmp/pr-review.md + ``` + +## Important +- Be constructive and specific +- Reference specific files and line numbers when pointing out issues +- Acknowledge what's done well +- Provide actionable suggestions for improvements \ No newline at end of file From 39b3855841dda761f363cf9b0fd302e06743b52c Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 14:29:54 -0700 Subject: [PATCH 17/30] Update workflow to use /review slash command --- .github/workflows/claude-auto-review.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/claude-auto-review.yml b/.github/workflows/claude-auto-review.yml index dc8bb5fe9..67d5778aa 100644 --- a/.github/workflows/claude-auto-review.yml +++ b/.github/workflows/claude-auto-review.yml @@ -23,21 +23,4 @@ jobs: uses: anthropics/claude-code-action@v1-dev with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - prompt: | - Please review this pull request and provide comprehensive feedback. - - Focus on: - - Code quality and best practices - - Potential bugs or issues - - Suggestions for improvements - - Overall architecture and design decisions - - Documentation consistency - - Steps: - 1. Use mcp__github__get_pull_request to get PR details - 2. Use mcp__github__get_pull_request_diff to see the changes - 3. Use mcp__github__create_pending_pull_request_review to start a review - 4. Use mcp__github__add_comment_to_pending_review for specific feedback - 5. Use mcp__github__submit_pending_pull_request_review with event: COMMENT to submit - - Create a review with constructive feedback and submit it as a COMMENT (not APPROVE). \ No newline at end of file + prompt: /review \ No newline at end of file From 50aee38198d6b856fae827dfde9f12a155b3ef69 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 15:00:33 -0700 Subject: [PATCH 18/30] Update review slash command to simple version that always posts comments --- .claude/commands/review.md | 75 ++++++-------------------------------- 1 file changed, 12 insertions(+), 63 deletions(-) diff --git a/.claude/commands/review.md b/.claude/commands/review.md index 2e74fca7d..0d15884fc 100644 --- a/.claude/commands/review.md +++ b/.claude/commands/review.md @@ -1,73 +1,22 @@ --- -allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh api:*), Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Bash(gh pr review:*), Bash(gh pr list:*), Task, Read, Glob, Grep, TodoWrite +allowed-tools: Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Read, Glob, Grep description: Code review a pull request --- -Provide a code review for the given pull request. +Review the current pull request and provide feedback. -To do this, follow these steps precisely: +1. Use `gh pr view` to get the PR details and `gh pr diff` to see the changes +2. Look for potential bugs, issues, or improvements +3. Always post a comment with your findings using `gh pr comment` -1. Use an agent to check if the pull request (a) is closed, (b) is a draft, (c) does not need a code review (eg. because it is an automated pull request, or is very simple and obviously ok), or (d) already has a code review from you from earlier. If so, do not proceed. -2. Use another agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root CLAUDE.md file (if one exists), as well as any CLAUDE.md files in the directories whose files the pull request modified -3. Use an agent to view the pull request, and ask the agent to return a summary of the change -4. Then, launch 4 parallel agents to independently code review the change. The agents should do the following: - a. Agents #1 and #2: Independently audit the changes to make sure they comply with the CLAUDE.md - b. Agent #3: Read the file changes in the pull request, then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore pre-existing issues. - c. Agent #4: Read the git blame and history of the code modified, to identify any bugs in light of that historical context -5. For each issue found in #4, launch a parallel agent that takes the PR, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or (a) a false positive bug, (b) a pedantic nitpick, or (c) a minor stylistic issues that a linter should flag. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. The scale is (give this rubric to the agent verbatim): - a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue. - b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md. - c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the PR, it's not very important. - d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach in the PR is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md. - e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this. -6. Filter out any issues with a score less than 80. If there are no issues that meet this criteria, do not proceed. -7. Finally, comment back on the pull request with a list of issues you found. When writing your comment, keep in mind to: - a. Keep your output brief - b. Avoid emojis - c. Link and cite relevant code, files, and URLs +Format your comment like this: -Notes: +## Code Review -- Use `gh` to interact with Github (eg. to fetch a pull request, or to create inline comments), rather than web fetch -- Make a todo list first -- You must cite and link each bug (eg. if referring to a CLAUDE.md, you must link it) -- For your comment, follow the following format precisely (assuming for this example that you found 3 issues): +[Your feedback here - be specific and constructive] ---- - -## Auto code review - -Found 3 issues: - -1. (CLAUDE.md says "<...>") - - - -2. (some/other/CLAUDE.md says "<...>") - - - -3. (bug due to ) - - - -🤖 Generated with [Claude Code](https://claude.ai/code) - -## [ANT-ONLY] If this code review was useful, please react with 👍. Otherwise, react with 👎. - -- Or, if you found no issues: - ---- - -## Auto code review - -No issues found. Checked for bugs and CLAUDE.md compliance. - -🤖 Generated with [Claude Code](https://claude.ai/code) +- If you find issues, describe them clearly +- If everything looks good, say so +- Link to specific lines when relevant -- When linking to code, follow the following format precisely, otherwise the Markdown preview won't render correctly: https://github.com/anthropics/claude-cli-internal/blob/c21d3c10bc8e898b7ac1a2d745bdc9bc4e423afe/package.json#L10-L15 - - Requires full git sha - - Repo name must match the repo you're code reviewing - - # sign after the file name - - Line range format is L[start]-L[end] - - Provide at least 1 line of context before and after, centered on the line you are commenting about (eg. if you are commenting about lines 5-6, you should link to `L4-7`) \ No newline at end of file +🤖 Generated with [Claude Code](https://claude.ai/code) \ No newline at end of file From f317d3c55df867a1ee96c285acb2843fb9099919 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 14 Aug 2025 15:02:28 -0700 Subject: [PATCH 19/30] Add deep-thinker subagent for testing subagent functionality --- .claude/agents/deep-thinker.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .claude/agents/deep-thinker.md diff --git a/.claude/agents/deep-thinker.md b/.claude/agents/deep-thinker.md new file mode 100644 index 000000000..b0c501350 --- /dev/null +++ b/.claude/agents/deep-thinker.md @@ -0,0 +1,31 @@ +--- +name: deep-thinker +description: A subagent that performs deep analysis with extended thinking +tools: + - "*" +proactive: false +--- + +# Deep Thinker Subagent + +You are a specialized subagent designed to perform deep, thorough analysis of complex problems using extended thinking capabilities. + +## Your Purpose + +You excel at: +- Breaking down complex problems into smaller components +- Analyzing trade-offs and implications +- Providing comprehensive, well-reasoned solutions +- Exploring edge cases and potential issues + +## Instructions + +When given a task: +1. Use extended thinking to thoroughly analyze the problem +2. Consider multiple approaches and their trade-offs +3. Identify potential issues or edge cases +4. Provide a detailed, well-structured response + +## Important + +Always think deeply before responding. Take your time to ensure thoroughness and accuracy in your analysis. \ No newline at end of file From 7ccb615087a8f59aa10595fd938b316592454e2f Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 14 Aug 2025 15:07:01 -0700 Subject: [PATCH 20/30] Fix: Copy subagent files from repo to Claude runtime environment This enables custom subagents to work in GitHub Actions by copying .claude/agents/*.md files from the repository to ~/.claude/agents/ during setup --- base-action/src/setup-claude-code-settings.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/base-action/src/setup-claude-code-settings.ts b/base-action/src/setup-claude-code-settings.ts index 6c40cfe25..a341a4fef 100644 --- a/base-action/src/setup-claude-code-settings.ts +++ b/base-action/src/setup-claude-code-settings.ts @@ -79,4 +79,35 @@ export async function setupClaudeCodeSettings( console.log(`Slash commands directory not found or error copying: ${e}`); } } + + // Copy subagent files from repository to Claude's agents directory + const repoAgentsDir = `${process.cwd()}/.claude/agents`; + const targetAgentsDir = `${home}/.claude/agents`; + + try { + const agentsDirExists = await $`test -d ${repoAgentsDir}`.quiet().nothrow(); + if (agentsDirExists.exitCode === 0) { + console.log(`Found subagents directory at ${repoAgentsDir}`); + + // Create target agents directory if it doesn't exist + await $`mkdir -p ${targetAgentsDir}`.quiet(); + console.log(`Created target agents directory at ${targetAgentsDir}`); + + // Copy all .md files from repo agents to Claude's agents directory + const copyResult = await $`cp -r ${repoAgentsDir}/*.md ${targetAgentsDir}/ 2>/dev/null`.quiet().nothrow(); + + if (copyResult.exitCode === 0) { + // List copied agents for logging + const agents = await $`ls -la ${targetAgentsDir}/*.md 2>/dev/null | wc -l`.quiet().text(); + const agentCount = parseInt(agents.trim()) || 0; + console.log(`Successfully copied ${agentCount} subagent(s) to ${targetAgentsDir}`); + } else { + console.log(`No subagent files found in ${repoAgentsDir}`); + } + } else { + console.log(`No subagents directory found at ${repoAgentsDir}`); + } + } catch (e) { + console.log(`Error handling subagents: ${e}`); + } } From 3005c85ceec25f193627ec91e61f8aa8dd8e8e22 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 14 Aug 2025 15:10:13 -0700 Subject: [PATCH 21/30] Fix: Use CLAUDE_WORKING_DIR to correctly locate subagent files The previous fix was looking in the wrong directory. Now uses CLAUDE_WORKING_DIR environment variable which points to the repository being processed, ensuring subagent files are found correctly. --- base-action/src/setup-claude-code-settings.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base-action/src/setup-claude-code-settings.ts b/base-action/src/setup-claude-code-settings.ts index a341a4fef..74acef70d 100644 --- a/base-action/src/setup-claude-code-settings.ts +++ b/base-action/src/setup-claude-code-settings.ts @@ -81,7 +81,9 @@ export async function setupClaudeCodeSettings( } // Copy subagent files from repository to Claude's agents directory - const repoAgentsDir = `${process.cwd()}/.claude/agents`; + // CLAUDE_WORKING_DIR is set by the action to point to the repo being processed + const workingDir = process.env.CLAUDE_WORKING_DIR || process.cwd(); + const repoAgentsDir = `${workingDir}/.claude/agents`; const targetAgentsDir = `${home}/.claude/agents`; try { From a37014c520c58a06607b2fa6e72ae375508cdb03 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 14 Aug 2025 15:14:20 -0700 Subject: [PATCH 22/30] Update workflow to use fork version with subagent fix --- .github/workflows/claude.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 99407a33b..48c4a3daf 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -31,7 +31,7 @@ jobs: - name: Run Claude Code id: claude - uses: anthropics/claude-code-action@beta + uses: km-anthropic/claude-code-action@main with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} allowed_tools: "Bash(bun install),Bash(bun test:*),Bash(bun run format),Bash(bun typecheck)" From 0a82bcdb04598e99502abecc165df92154edcb0e Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 18 Aug 2025 17:17:52 -0700 Subject: [PATCH 23/30] Test PR 411: Point workflow to piotrb's fork with sticky comment feature --- .github/workflows/claude.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 48c4a3daf..4a7598f96 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -31,9 +31,13 @@ jobs: - name: Run Claude Code id: claude - uses: km-anthropic/claude-code-action@main + uses: piotrb/claude-code-action@main with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} allowed_tools: "Bash(bun install),Bash(bun test:*),Bash(bun run format),Bash(bun typecheck)" custom_instructions: "You have also been granted tools for editing files and running bun commands (install, run, test, typecheck) for testing your changes: bun install, bun test, bun run format, bun typecheck." model: "claude-opus-4-1-20250805" + # Testing PR 411 - sticky comment customization + use_sticky_comment: true + sticky_comment_app_bot_id: "209825114" + sticky_comment_app_bot_name: "claude" From 9700ba81303a9c099bb102cb6b0d623da9234ed6 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 18 Aug 2025 17:25:59 -0700 Subject: [PATCH 24/30] Fix: Use correct fork path janeapp/claude-code-action --- .github/workflows/claude.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 4a7598f96..8a64f53c7 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -31,7 +31,7 @@ jobs: - name: Run Claude Code id: claude - uses: piotrb/claude-code-action@main + uses: janeapp/claude-code-action@main with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} allowed_tools: "Bash(bun install),Bash(bun test:*),Bash(bun run format),Bash(bun typecheck)" From e9dc3050fb1fc00e6531050e36dfcc5c21187ff4 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 13:44:34 -0700 Subject: [PATCH 25/30] Add auto-fix CI workflows with slash command and inline approaches - Add /fix-ci slash command for programmatic CI failure fixing - Create auto-fix-ci.yml workflow using slash command approach - Create auto-fix-ci-inline.yml workflow with full inline prompt - Both workflows automatically analyze CI failures and create fix branches --- .claude/commands/fix-ci.md | 67 +++++++++ .github/workflows/auto-fix-ci-inline.yml | 175 +++++++++++++++++++++++ .github/workflows/auto-fix-ci.yml | 117 +++++++++++++++ slash-commands/fix-ci.md | 67 +++++++++ 4 files changed, 426 insertions(+) create mode 100644 .claude/commands/fix-ci.md create mode 100644 .github/workflows/auto-fix-ci-inline.yml create mode 100644 .github/workflows/auto-fix-ci.yml create mode 100644 slash-commands/fix-ci.md diff --git a/.claude/commands/fix-ci.md b/.claude/commands/fix-ci.md new file mode 100644 index 000000000..33efbde33 --- /dev/null +++ b/.claude/commands/fix-ci.md @@ -0,0 +1,67 @@ +--- +description: Analyze and fix CI failures by examining logs and making targeted fixes +allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" +--- + +# Fix CI Failures + +You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps: + +## Context Provided + +$ARGUMENTS + +## Step 1: Analyze the Failure + +Parse the provided CI failure information to understand: +- Which jobs failed and why +- The specific error messages and stack traces +- Whether failures are test-related, build-related, or linting issues + +## Step 2: Search and Understand the Codebase + +Use search tools to locate the failing code: +- Search for the failing test names or functions +- Find the source files mentioned in error messages +- Review related configuration files (package.json, tsconfig.json, etc.) + +## Step 3: Apply Targeted Fixes + +Make minimal, focused changes: +- **For test failures**: Determine if the test or implementation needs fixing +- **For type errors**: Fix type definitions or correct the code logic +- **For linting issues**: Apply formatting using the project's tools +- **For build errors**: Resolve dependency or configuration issues +- **For missing imports**: Add the necessary imports or install packages + +Requirements: +- Only fix the actual CI failures, avoid unrelated changes +- Follow existing code patterns and conventions +- Ensure changes are production-ready, not temporary hacks +- Preserve existing functionality while fixing issues + +## Step 4: Create Branch and Commit Changes + +After applying fixes: +1. Create a branch named `claude-fix-ci-${timestamp}` +2. Stage all modified files with `git add` +3. Commit with a descriptive message explaining what was fixed +4. Document which CI jobs/tests were addressed + +## Step 5: Verify Fixes Locally + +Run available verification commands: +- Execute the failing tests locally to confirm they pass +- Run the project's lint command (check package.json for scripts) +- Run type checking if available +- Execute any build commands to ensure compilation succeeds + +## Important Guidelines + +- Focus exclusively on fixing the reported CI failures +- Maintain code quality and follow the project's established patterns +- If a fix requires significant refactoring, document why it's necessary +- When multiple solutions exist, choose the simplest one that maintains code quality +- Add clear comments only if the fix is non-obvious + +Begin by analyzing the failure details provided above. \ No newline at end of file diff --git a/.github/workflows/auto-fix-ci-inline.yml b/.github/workflows/auto-fix-ci-inline.yml new file mode 100644 index 000000000..6334849bd --- /dev/null +++ b/.github/workflows/auto-fix-ci-inline.yml @@ -0,0 +1,175 @@ +name: Auto Fix CI Failures (Inline) + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + +permissions: + contents: write + pull-requests: write + actions: read + issues: write + +jobs: + auto-fix: + if: | + github.event.workflow_run.conclusion == 'failure' && + github.event.workflow_run.name != 'Auto Fix CI Failures' && + github.event.workflow_run.name != 'Auto Fix CI Failures (Inline)' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_branch }} + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup git + run: | + git config --global user.name "claude[bot]" + git config --global user.email "198276+claude[bot]@users.noreply.github.com" + + - name: Create fix branch + id: branch + run: | + BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}" + git checkout -b "$BRANCH_NAME" + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + + - name: Get CI failure details + id: failure_details + uses: actions/github-script@v7 + with: + script: | + const run = await github.rest.actions.getWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }} + }); + + const jobs = await github.rest.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }} + }); + + const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure'); + + let errorLogs = []; + for (const job of failedJobs) { + const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + job_id: job.id + }); + errorLogs.push({ + jobName: job.name, + logs: logs.data + }); + } + + return { + runUrl: run.data.html_url, + failedJobs: failedJobs.map(j => j.name), + errorLogs: errorLogs + }; + + - name: Fix CI failures with Claude + uses: km-anthropic/claude-code-action@v1-dev + with: + prompt: | + You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps: + + ## Context Provided + + Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }} + Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }} + + Error logs: + ${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }} + + ## Step 1: Analyze the Failure + + Parse the provided CI failure information to understand: + - Which jobs failed and why + - The specific error messages and stack traces + - Whether failures are test-related, build-related, or linting issues + + ## Step 2: Search and Understand the Codebase + + Use search tools to locate the failing code: + - Search for the failing test names or functions + - Find the source files mentioned in error messages + - Review related configuration files (package.json, tsconfig.json, etc.) + + ## Step 3: Apply Targeted Fixes + + Make minimal, focused changes: + - **For test failures**: Determine if the test or implementation needs fixing + - **For type errors**: Fix type definitions or correct the code logic + - **For linting issues**: Apply formatting using the project's tools + - **For build errors**: Resolve dependency or configuration issues + - **For missing imports**: Add the necessary imports or install packages + + Requirements: + - Only fix the actual CI failures, avoid unrelated changes + - Follow existing code patterns and conventions + - Ensure changes are production-ready, not temporary hacks + - Preserve existing functionality while fixing issues + + ## Step 4: Create Branch and Commit Changes + + After applying fixes: + 1. Stage all modified files with `git add` + 2. Commit with a descriptive message explaining what was fixed + 3. Document which CI jobs/tests were addressed + + ## Step 5: Verify Fixes Locally + + Run available verification commands: + - Execute the failing tests locally to confirm they pass + - Run the project's lint command (check package.json for scripts) + - Run type checking if available + - Execute any build commands to ensure compilation succeeds + + ## Important Guidelines + + - Focus exclusively on fixing the reported CI failures + - Maintain code quality and follow the project's established patterns + - If a fix requires significant refactoring, document why it's necessary + - When multiple solutions exist, choose the simplest one that maintains code quality + + Begin by analyzing the failure details provided above. + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + github_token: ${{ secrets.GITHUB_TOKEN }} + timeout_minutes: "30" + use_sticky_comment: "true" + claude_args: "--max-turns 15" + + - name: Push fix branch + if: success() + run: | + git push origin ${{ steps.branch.outputs.branch_name }} + + - name: Create pull request comment + if: success() + uses: actions/github-script@v7 + with: + script: | + const branchName = '${{ steps.branch.outputs.branch_name }}'; + const baseBranch = '${{ github.event.workflow_run.head_branch }}'; + const prUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${baseBranch}...${branchName}?quick_pull=1`; + + const issueNumber = ${{ github.event.workflow_run.pull_requests[0]?.number || 'null' }}; + + if (issueNumber) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body: `## 🤖 CI Auto-Fix Available\n\nClaude has analyzed the CI failures and prepared fixes.\n\n[**→ Create pull request to fix CI**](${prUrl})\n\n_This fix was generated automatically based on the [failed CI run](${{ fromJSON(steps.failure_details.outputs.result).runUrl }})._` + }); + } \ No newline at end of file diff --git a/.github/workflows/auto-fix-ci.yml b/.github/workflows/auto-fix-ci.yml new file mode 100644 index 000000000..9f5df9c8a --- /dev/null +++ b/.github/workflows/auto-fix-ci.yml @@ -0,0 +1,117 @@ +name: Auto Fix CI Failures + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + +permissions: + contents: write + pull-requests: write + actions: read + issues: write + +jobs: + auto-fix: + if: | + github.event.workflow_run.conclusion == 'failure' && + github.event.workflow_run.name != 'Auto Fix CI Failures' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_branch }} + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup git + run: | + git config --global user.name "claude[bot]" + git config --global user.email "198276+claude[bot]@users.noreply.github.com" + + - name: Create fix branch + id: branch + run: | + BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}" + git checkout -b "$BRANCH_NAME" + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT + + - name: Get CI failure details + id: failure_details + uses: actions/github-script@v7 + with: + script: | + const run = await github.rest.actions.getWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }} + }); + + const jobs = await github.rest.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{ github.event.workflow_run.id }} + }); + + const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure'); + + let errorLogs = []; + for (const job of failedJobs) { + const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + job_id: job.id + }); + errorLogs.push({ + jobName: job.name, + logs: logs.data + }); + } + + return { + runUrl: run.data.html_url, + failedJobs: failedJobs.map(j => j.name), + errorLogs: errorLogs + }; + + - name: Fix CI failures with Claude + uses: km-anthropic/claude-code-action@v1-dev + with: + prompt: | + /fix-ci Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }} + Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }} + + Error logs: + ${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }} + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + github_token: ${{ secrets.GITHUB_TOKEN }} + timeout_minutes: "30" + use_sticky_comment: "true" + claude_args: "--max-turns 15" + + - name: Push fix branch + if: success() + run: | + git push origin ${{ steps.branch.outputs.branch_name }} + + - name: Create pull request comment + if: success() + uses: actions/github-script@v7 + with: + script: | + const branchName = '${{ steps.branch.outputs.branch_name }}'; + const baseBranch = '${{ github.event.workflow_run.head_branch }}'; + const prUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${baseBranch}...${branchName}?quick_pull=1`; + + const issueNumber = ${{ github.event.workflow_run.pull_requests[0]?.number || 'null' }}; + + if (issueNumber) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body: `## 🤖 CI Auto-Fix Available\n\nClaude has analyzed the CI failures and prepared fixes.\n\n[**→ Create pull request to fix CI**](${prUrl})\n\n_This fix was generated automatically based on the [failed CI run](${{ fromJSON(steps.failure_details.outputs.result).runUrl }})._` + }); + } \ No newline at end of file diff --git a/slash-commands/fix-ci.md b/slash-commands/fix-ci.md new file mode 100644 index 000000000..33efbde33 --- /dev/null +++ b/slash-commands/fix-ci.md @@ -0,0 +1,67 @@ +--- +description: Analyze and fix CI failures by examining logs and making targeted fixes +allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" +--- + +# Fix CI Failures + +You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps: + +## Context Provided + +$ARGUMENTS + +## Step 1: Analyze the Failure + +Parse the provided CI failure information to understand: +- Which jobs failed and why +- The specific error messages and stack traces +- Whether failures are test-related, build-related, or linting issues + +## Step 2: Search and Understand the Codebase + +Use search tools to locate the failing code: +- Search for the failing test names or functions +- Find the source files mentioned in error messages +- Review related configuration files (package.json, tsconfig.json, etc.) + +## Step 3: Apply Targeted Fixes + +Make minimal, focused changes: +- **For test failures**: Determine if the test or implementation needs fixing +- **For type errors**: Fix type definitions or correct the code logic +- **For linting issues**: Apply formatting using the project's tools +- **For build errors**: Resolve dependency or configuration issues +- **For missing imports**: Add the necessary imports or install packages + +Requirements: +- Only fix the actual CI failures, avoid unrelated changes +- Follow existing code patterns and conventions +- Ensure changes are production-ready, not temporary hacks +- Preserve existing functionality while fixing issues + +## Step 4: Create Branch and Commit Changes + +After applying fixes: +1. Create a branch named `claude-fix-ci-${timestamp}` +2. Stage all modified files with `git add` +3. Commit with a descriptive message explaining what was fixed +4. Document which CI jobs/tests were addressed + +## Step 5: Verify Fixes Locally + +Run available verification commands: +- Execute the failing tests locally to confirm they pass +- Run the project's lint command (check package.json for scripts) +- Run type checking if available +- Execute any build commands to ensure compilation succeeds + +## Important Guidelines + +- Focus exclusively on fixing the reported CI failures +- Maintain code quality and follow the project's established patterns +- If a fix requires significant refactoring, document why it's necessary +- When multiple solutions exist, choose the simplest one that maintains code quality +- Add clear comments only if the fix is non-obvious + +Begin by analyzing the failure details provided above. \ No newline at end of file From 110acf1b440954a3765f5ceb78d2d6ce2158d7aa Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 13:47:27 -0700 Subject: [PATCH 26/30] Test CI failure for auto-fix workflows --- test-failure.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test-failure.ts diff --git a/test-failure.ts b/test-failure.ts new file mode 100644 index 000000000..f75b6cede --- /dev/null +++ b/test-failure.ts @@ -0,0 +1,12 @@ +// This file intentionally has TypeScript errors to trigger CI failure +const testFunction = (param: string): number => { + // Type error: returning string instead of number + return "this should be a number"; +} + +// Syntax error: missing closing brace +function brokenFunction() { + console.log("missing closing brace" +} + +export { testFunction, brokenFunction }; \ No newline at end of file From 54d68a2a5f4781d9544baf40781c57facc97feaf Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 13:58:08 -0700 Subject: [PATCH 27/30] Trigger new CI failure to test auto-fix workflows --- test-failure.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test-failure.ts b/test-failure.ts index f75b6cede..3b13016ca 100644 --- a/test-failure.ts +++ b/test-failure.ts @@ -1,4 +1,5 @@ // This file intentionally has TypeScript errors to trigger CI failure +// Updated to trigger new workflow run const testFunction = (param: string): number => { // Type error: returning string instead of number return "this should be a number"; From 130eff6d9ceb0f65c9f1473e5123de3c65701aa7 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 14:08:14 -0700 Subject: [PATCH 28/30] Update CI fix workflows to ensure Claude commits changes - Clarify that Claude must commit changes even when branch exists - Update both slash command and inline workflow instructions - Make git add and commit commands more explicit --- .claude/commands/fix-ci.md | 10 +++++----- .github/workflows/auto-fix-ci-inline.yml | 10 +++++----- slash-commands/fix-ci.md | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.claude/commands/fix-ci.md b/.claude/commands/fix-ci.md index 33efbde33..2257c301b 100644 --- a/.claude/commands/fix-ci.md +++ b/.claude/commands/fix-ci.md @@ -40,13 +40,13 @@ Requirements: - Ensure changes are production-ready, not temporary hacks - Preserve existing functionality while fixing issues -## Step 4: Create Branch and Commit Changes +## Step 4: Commit Changes After applying fixes: -1. Create a branch named `claude-fix-ci-${timestamp}` -2. Stage all modified files with `git add` -3. Commit with a descriptive message explaining what was fixed -4. Document which CI jobs/tests were addressed +1. Stage all modified files with `git add -A` or `git add .` +2. Commit with a descriptive message using `git commit -m "Fix CI failures: "` +3. Include details about which CI jobs/tests were fixed in the commit message +4. Important: Always commit your changes even if you're already on a branch ## Step 5: Verify Fixes Locally diff --git a/.github/workflows/auto-fix-ci-inline.yml b/.github/workflows/auto-fix-ci-inline.yml index 6334849bd..913d86e8c 100644 --- a/.github/workflows/auto-fix-ci-inline.yml +++ b/.github/workflows/auto-fix-ci-inline.yml @@ -120,12 +120,12 @@ jobs: - Ensure changes are production-ready, not temporary hacks - Preserve existing functionality while fixing issues - ## Step 4: Create Branch and Commit Changes + ## Step 4: Commit Changes - After applying fixes: - 1. Stage all modified files with `git add` - 2. Commit with a descriptive message explaining what was fixed - 3. Document which CI jobs/tests were addressed + After applying ALL fixes: + 1. Stage all modified files with `git add -A` + 2. Commit with: `git commit -m "Fix CI failures: prettier formatting and syntax errors"` + 3. Important: You MUST commit your changes - the branch already exists ## Step 5: Verify Fixes Locally diff --git a/slash-commands/fix-ci.md b/slash-commands/fix-ci.md index 33efbde33..2257c301b 100644 --- a/slash-commands/fix-ci.md +++ b/slash-commands/fix-ci.md @@ -40,13 +40,13 @@ Requirements: - Ensure changes are production-ready, not temporary hacks - Preserve existing functionality while fixing issues -## Step 4: Create Branch and Commit Changes +## Step 4: Commit Changes After applying fixes: -1. Create a branch named `claude-fix-ci-${timestamp}` -2. Stage all modified files with `git add` -3. Commit with a descriptive message explaining what was fixed -4. Document which CI jobs/tests were addressed +1. Stage all modified files with `git add -A` or `git add .` +2. Commit with a descriptive message using `git commit -m "Fix CI failures: "` +3. Include details about which CI jobs/tests were fixed in the commit message +4. Important: Always commit your changes even if you're already on a branch ## Step 5: Verify Fixes Locally From 71431089b590a291719030047314b884d301dc19 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 14:18:06 -0700 Subject: [PATCH 29/30] Add explicit fix-ci-commit command for clearer git commit instructions - Create new slash command specifically for when branch already exists - Makes it crystal clear that Bash tool must be used for git commands - Update workflow to use the new command --- .claude/commands/fix-ci-commit.md | 56 +++++++++++++++++++++++++++++++ .claude/commands/fix-ci.md | 8 ++--- .github/workflows/auto-fix-ci.yml | 2 +- slash-commands/fix-ci-commit.md | 56 +++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 .claude/commands/fix-ci-commit.md create mode 100644 slash-commands/fix-ci-commit.md diff --git a/.claude/commands/fix-ci-commit.md b/.claude/commands/fix-ci-commit.md new file mode 100644 index 000000000..9ecf8f4bb --- /dev/null +++ b/.claude/commands/fix-ci-commit.md @@ -0,0 +1,56 @@ +--- +description: Fix CI failures and commit changes (for use when branch already exists) +allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" +--- + +# Fix CI Failures and Commit + +You are on a branch that was created to fix CI failures. Your task is to fix the issues and commit the changes. + +## CI Failure Information + +$ARGUMENTS + +## Your Tasks + +1. **Analyze the failures** - Understand what went wrong from the logs +2. **Fix the issues** - Make the necessary code changes +3. **Commit your fixes** - Use git to commit all changes + +## Step-by-Step Instructions + +### 1. Fix the Issues + +Based on the error logs: +- Fix syntax errors +- Fix formatting issues +- Fix test failures +- Fix any other CI problems + +### 2. Commit Your Changes (REQUIRED) + +After fixing ALL issues, you MUST: + +```bash +# Stage all changes +git add -A + +# Commit with descriptive message +git commit -m "Fix CI failures + +- Fixed syntax errors +- Fixed formatting issues +- Fixed test failures +[List actual fixes made]" +``` + +**IMPORTANT**: You MUST use the Bash tool to run the git add and git commit commands above. The workflow expects you to commit your changes. + +### 3. Verify (Optional) + +If possible, run verification commands: +- `bun run format:check` for formatting +- `bun test` for tests +- `bun run typecheck` for TypeScript + +Begin by analyzing the failure logs and then fix the issues. \ No newline at end of file diff --git a/.claude/commands/fix-ci.md b/.claude/commands/fix-ci.md index 2257c301b..05f442048 100644 --- a/.claude/commands/fix-ci.md +++ b/.claude/commands/fix-ci.md @@ -42,11 +42,11 @@ Requirements: ## Step 4: Commit Changes -After applying fixes: -1. Stage all modified files with `git add -A` or `git add .` -2. Commit with a descriptive message using `git commit -m "Fix CI failures: "` +After applying ALL fixes, use the Bash tool to: +1. Run: `git add -A` to stage all modified files +2. Run: `git commit -m "Fix CI failures: "` to commit the changes 3. Include details about which CI jobs/tests were fixed in the commit message -4. Important: Always commit your changes even if you're already on a branch +4. Important: You MUST use the Bash tool to run these git commands to commit your changes ## Step 5: Verify Fixes Locally diff --git a/.github/workflows/auto-fix-ci.yml b/.github/workflows/auto-fix-ci.yml index 9f5df9c8a..465234ea6 100644 --- a/.github/workflows/auto-fix-ci.yml +++ b/.github/workflows/auto-fix-ci.yml @@ -80,7 +80,7 @@ jobs: uses: km-anthropic/claude-code-action@v1-dev with: prompt: | - /fix-ci Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }} + /fix-ci-commit Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }} Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }} Error logs: diff --git a/slash-commands/fix-ci-commit.md b/slash-commands/fix-ci-commit.md new file mode 100644 index 000000000..9ecf8f4bb --- /dev/null +++ b/slash-commands/fix-ci-commit.md @@ -0,0 +1,56 @@ +--- +description: Fix CI failures and commit changes (for use when branch already exists) +allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" +--- + +# Fix CI Failures and Commit + +You are on a branch that was created to fix CI failures. Your task is to fix the issues and commit the changes. + +## CI Failure Information + +$ARGUMENTS + +## Your Tasks + +1. **Analyze the failures** - Understand what went wrong from the logs +2. **Fix the issues** - Make the necessary code changes +3. **Commit your fixes** - Use git to commit all changes + +## Step-by-Step Instructions + +### 1. Fix the Issues + +Based on the error logs: +- Fix syntax errors +- Fix formatting issues +- Fix test failures +- Fix any other CI problems + +### 2. Commit Your Changes (REQUIRED) + +After fixing ALL issues, you MUST: + +```bash +# Stage all changes +git add -A + +# Commit with descriptive message +git commit -m "Fix CI failures + +- Fixed syntax errors +- Fixed formatting issues +- Fixed test failures +[List actual fixes made]" +``` + +**IMPORTANT**: You MUST use the Bash tool to run the git add and git commit commands above. The workflow expects you to commit your changes. + +### 3. Verify (Optional) + +If possible, run verification commands: +- `bun run format:check` for formatting +- `bun test` for tests +- `bun run typecheck` for TypeScript + +Begin by analyzing the failure logs and then fix the issues. \ No newline at end of file From 7fc38f28c024646161fd9e5ec9197596e6871358 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 19 Aug 2025 14:33:35 -0700 Subject: [PATCH 30/30] Remove tool restrictions from fix-ci slash commands to allow git operations --- .claude/commands/fix-ci-commit.md | 1 - .claude/commands/fix-ci.md | 1 - slash-commands/fix-ci-commit.md | 1 - slash-commands/fix-ci.md | 1 - 4 files changed, 4 deletions(-) diff --git a/.claude/commands/fix-ci-commit.md b/.claude/commands/fix-ci-commit.md index 9ecf8f4bb..55bf47a25 100644 --- a/.claude/commands/fix-ci-commit.md +++ b/.claude/commands/fix-ci-commit.md @@ -1,6 +1,5 @@ --- description: Fix CI failures and commit changes (for use when branch already exists) -allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" --- # Fix CI Failures and Commit diff --git a/.claude/commands/fix-ci.md b/.claude/commands/fix-ci.md index 05f442048..83b21bc4e 100644 --- a/.claude/commands/fix-ci.md +++ b/.claude/commands/fix-ci.md @@ -1,6 +1,5 @@ --- description: Analyze and fix CI failures by examining logs and making targeted fixes -allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" --- # Fix CI Failures diff --git a/slash-commands/fix-ci-commit.md b/slash-commands/fix-ci-commit.md index 9ecf8f4bb..55bf47a25 100644 --- a/slash-commands/fix-ci-commit.md +++ b/slash-commands/fix-ci-commit.md @@ -1,6 +1,5 @@ --- description: Fix CI failures and commit changes (for use when branch already exists) -allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" --- # Fix CI Failures and Commit diff --git a/slash-commands/fix-ci.md b/slash-commands/fix-ci.md index 2257c301b..f178147a4 100644 --- a/slash-commands/fix-ci.md +++ b/slash-commands/fix-ci.md @@ -1,6 +1,5 @@ --- description: Analyze and fix CI failures by examining logs and making targeted fixes -allowed_tools: "Read, Write, Edit, MultiEdit, Bash, Grep, Glob, TodoWrite" --- # Fix CI Failures