Overview
A nightly GitHub Actions job runs Claude Code over recent CI results to rank flaky tests, rerun the worst few and open a pull request with a proposed fix and its evidence for a developer to review.
Problem or Objective
- Which agents write or run tests against an application?
- Which agents turn an issue report into a fix?
More in Coding and Code Review
AI Agents and Models
Tools and Integrations
- Tools
- Claude Code · GitHub Actions
- Prerequisites
- A GitHub repository with CI, the Claude GitHub App, and an Anthropic API key or subscription token stored as a repository secret.
How It Works
Install the Claude GitHub App and add the Claude Code GitHub Action to the repository, with an API key or subscription token stored as a repository secret. Create a workflow on a cron schedule, for example nightly, with a prompt that asks Claude to collect the results of recent CI runs, rank the tests that failed and then passed on a retry, and take the top few. For each, Claude reruns the test several times in the job, reads the test and the code under it, and writes down the likely cause (timing, shared state, test order, network). Grant only the tools the prompt needs with --allowedTools. Claude opens a pull request with a small fix and the evidence, or posts a report when it cannot reproduce the failure. A developer reviews every pull request, and the next night shows whether the test still fails.
Implementation Workflow
Steps assembled from the agents, tools and prompt of this entry. Adapt them to your own setup.
- Choose the agentSet up Claude Code.
- Connect the toolsConnect the tools this workflow relies on: Claude Code, GitHub Actions.
- Check the prerequisitesA GitHub repository with CI, the Claude GitHub App, and an Anthropic API key or subscription token stored as a repository secret.
- Gather your detailsCollect what the prompt asks for: Branch to analyse, Days of CI history, Tests to investigate per night.
- Run the starter promptPaste the starter prompt below into Claude Code and adapt it to your case.
- Check against the documentationCompare what you get with the documentation at code.claude.com before you rely on it.
Practical Starter Prompt: Rank and fix tonight's flakiest tests
Fill the fields to adapt the prompt. Empty fields stay as visible [placeholders].
Look at the CI runs for [Branch to analyse] over the last [Days of CI history] days. List tests that failed and then passed on a retry, ranked by how often. Take the top [Tests to investigate per night]. For each, rerun it repeatedly, read the test and the code under test, and explain the most likely cause with evidence. If you can reproduce the failure, open a pull request with a minimal fix and the evidence in the description; otherwise post a short report. Do not merge, skip or delete tests: a developer will review every change.Start with a small number of tests per night and grant only the tools the prompt needs. Every pull request is reviewed by a developer before merge.
Expected Results and Benefits
This is a suggested workflow, not a reported result. The points below are what the cited documentation says the tools can do.
This is a suggested workflow, not a reported outcome. Anthropic's docs say the Claude Code GitHub Action can run a prompt on any GitHub event, including a cron schedule, can turn issues into pull requests, and has no shell or GitHub API access until you grant tools. They do not describe flaky-test analysis, so how well it ranks and fixes flaky tests in your suite is untested.
Limitations and Considerations
GitHub runs scheduled workflows only from the default branch, and in public repositories it disables a schedule once the repository has had no activity for 60 days. Rerunning tests many times uses CI minutes and model usage, so cap the number of tests per night. A change that makes a test pass once can hide a real bug, so keep merges a human decision and never let the job skip or delete tests. Results depend on your setup and were not independently reproduced by Top 200 Repos.
GitHub Repositories
AI Agent Repository
Source code of the agent that does the work.
Official Website
The official site of the main tool or project in this use case.
Visit Website (opens in a new tab)code.claude.com
Related Videos
About anthropics/claude-code
The SECRET Claude Code Upgrade That Has Everyone Going Nuts (Full Guide) (opens in a new tab)
The title names the project, the description links the project website.
Watch on YouTube (opens in a new tab)About anthropics/claude-code
The only Claude Code guide you'll ever need (Opus 4.5) (opens in a new tab)
The title names the project, the description links the project website.
Watch on YouTube (opens in a new tab)Independent creators. Listing a video implies no endorsement, sponsorship or partnership.
Sources
- Claude Code GitHub Actions - Claude Code Docs (opens in a new tab)
Project documentation · code.claude.com · Undated · Source checked 26 Nov 2026, 17:27 UTC
What this source supports
- A GitHub Action runs Claude Code in repository workflows and can be used to turn issues into pull requests, fix bugs from a comment or automate recurring tasks.
- With a prompt input the action runs in automation mode on any GitHub event, including a cron schedule; for a plain-text prompt Claude has no shell or GitHub API access until the needed tools are granted with --allowedTools.
- GitHub runs scheduled workflows only from the default branch and, in public repositories, disables the schedule after 60 days without repository activity.

