Hand off test failures to an AI agent
When a test fails, Doc Detective’s GitHub Action can open an issue with the results and mention an AI agent in it. The agent analyzes the failure and suggests a fix. You review the suggestion and decide what to change.
How the handoff works
The handoff connects three components:
- Automated testing: Doc Detective runs on every push or pull request, catching documentation that no longer matches your product.
- Failure detection: When tests fail, the GitHub Action creates an issue with structured test results.
- AI diagnosis: The issue mentions an AI integration that analyzes the failure and suggests fixes.
A person reviews every change before it lands. When documentation drifts from your product, the issue surfaces the problem with the agent’s analysis, and you decide on the fix. Tests can also update screenshots and command outputs. With create_pr_on_change, the action opens a pull request with those updates, and you review it before merging.
Set up the handoff
Configure your workflow to create issues with AI integration when tests fail:
This configuration:
- Runs tests against the
./docsdirectory on every push tomain - Creates a GitHub issue when any test fails, using the token in the
DOC_DETECTIVE_ISSUE_TOKENsecret - Mentions Claude in the issue with a detailed diagnostic prompt
- Passes the test results to Claude for analysis
Claude Code answers from a GitHub Actions workflow that starts when an issue opens. GitHub doesn’t start workflows for events that the default GITHUB_TOKEN creates. An issue the action opens with that token therefore never reaches Claude. Set token to one of these:
- A fine-grained personal access token that can write issues, stored as a repository secret. Its owner needs write access to the repository, because Claude Code ignores issues from users without it.
- A GitHub App token that the workflow generates on each run, for example with
actions/create-github-app-token. Installation tokens expire after an hour, so don’t store one as a secret. Claude Code ignores bots by default, so add the app’s bot toallowed_botsin the Claude Code workflow.
The action also opens pull requests with token. If you set create_pr_on_change, as the weekly example does, the token also needs Pull requests: write.
The example runs on pushes to main, not on pull_request. By default, a pull request from a fork gets no secrets and a read-only GITHUB_TOKEN, so the action can’t open the issue there. A private repository can change that under Fork pull request workflows, as Tests are code explains. To check pull requests, keep a separate pull_request workflow without create_issue_on_fail.
Craft effective prompts
The prompt input determines how AI integrations analyze failures. A good prompt produces actionable suggestions rather than generic advice.
Prompt structure
Build your prompt around three elements:
Example prompts
For API documentation:
For procedural documentation:
For screenshot tests:
Prompt variables
Use these variables in your prompt or issue body:
Choose an AI integration
Each integration behaves differently. Choose based on your workflow:
Combine integrations to get multiple perspectives:
Advanced configuration
Custom issue templates
Override the default issue body to structure how results appear:
Scheduled runs
Run tests on a schedule to catch drift before it reaches production:
Auto-assign for triage
Route issues to specific team members:
Example: weekly docs health check
This workflow combines scheduled runs, AI diagnosis, and automatic PR creation:
This workflow:
- Runs weekly to catch gradual documentation drift
- Creates issues with Claude and Promptless analysis when tests fail
- Automatically opens PRs when tests update screenshots or command outputs
- Labels everything for straightforward filtering and triage