Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: nightly Claude CI review and code cleanup workflows (#1111)

Maximilian Rooseae3c7a4a231
diff --git a/.claude/skills/pr-review/SKILL.md b/.claude/skills/pr-review/SKILL.md
index 961802c44..2ffc236ec 100644
--- a/.claude/skills/pr-review/SKILL.md
+++ b/.claude/skills/pr-review/SKILL.md
@@ -105,6 +105,20 @@ tactical checklist.
- Are the changes adequately tested?
- Do the tests follow the project's testing conventions (see tests/CLAUDE.md)?
+**Same pattern elsewhere:**
+
+When a PR fixes a bug or changes a pattern, search for the same pattern in
+other files. A fix applied to one location often needs to be applied to sibling
+files. For example, if a PR fixes a broken path in one workflow file, grep for
+the same broken path across all workflow files.
+
+```bash
+# Example: PR fixes `${{ env.HOME }}` in one workflow — check all workflows
+rg 'env\.HOME' .github/workflows/
+```
+
+If the same issue exists elsewhere, flag it in the review.
+
### 4. Resolve handled suggestions
After reviewing the code, check if any unresolved review threads from the bot
diff --git a/.github/workflows/claude-ci-fix.yaml b/.github/workflows/claude-ci-fix.yaml
index 2b2c08cbd..7be008781 100644
--- a/.github/workflows/claude-ci-fix.yaml
+++ b/.github/workflows/claude-ci-fix.yaml
@@ -154,6 +154,6 @@ jobs:
uses: actions/upload-artifact@v6
with:
name: claude-session-logs
- path: ${{ env.HOME }}/.claude/
+ path: /home/runner/.claude/projects/
retention-days: 30
if-no-files-found: warn
diff --git a/.github/workflows/claude-issue-triage.yaml b/.github/workflows/claude-issue-triage.yaml
index 88069e5b4..bab3dedd6 100644
--- a/.github/workflows/claude-issue-triage.yaml
+++ b/.github/workflows/claude-issue-triage.yaml
@@ -19,9 +19,14 @@ env:
jobs:
triage:
- # Skip bot-created issues and @claude mentions (handled by claude-mention.yaml)
+ # Skip bot-created issues, @claude mentions (handled by claude-mention.yaml),
+ # and issues from worktrunk-bot (nightly workflows, ci-fix, etc.). Nightly
+ # workflows handle their own remediation because they have richer context
+ # (session logs, aggregate diffs) that would be lost if the triager
+ # re-derived it from the issue body alone.
if: >-
github.event.issue.user.type != 'Bot' &&
+ github.event.issue.user.login != 'worktrunk-bot' &&
!contains(github.event.issue.body, '@claude') &&
!contains(github.event.issue.title, '@claude')
runs-on: ubuntu-24.04
@@ -92,6 +97,6 @@ jobs:
uses: actions/upload-artifact@v6
with:
name: claude-session-logs
- path: ${{ env.HOME }}/.claude/
+ path: /home/runner/.claude/projects/
retention-days: 30
if-no-files-found: warn
diff --git a/.github/workflows/claude-mention.yaml b/.github/workflows/claude-mention.yaml
index dd2d276cb..0bea79aac 100644
--- a/.github/workflows/claude-mention.yaml
+++ b/.github/workflows/claude-mention.yaml
@@ -97,6 +97,6 @@ jobs:
uses: actions/upload-artifact@v6
with:
name: claude-session-logs
- path: ${{ env.HOME }}/.claude/
+ path: /home/runner/.claude/projects/
retention-days: 30
if-no-files-found: warn
diff --git a/.github/workflows/claude-nightly-cleaner.yaml b/.github/workflows/claude-nightly-cleaner.yaml
new file mode 100644
index 000000000..4a3f8a9c7
--- /dev/null
+++ b/.github/workflows/claude-nightly-cleaner.yaml
@@ -0,0 +1,162 @@
+name: claude-nightly-cleaner
+# Runner versions pinned; see ci.yaml header comment for rationale.
+
+# Nightly code quality sweep — reviews all commits merged to main in the past
+# 24 hours for bugs, inconsistencies, and improvement opportunities.
+on:
+ schedule:
+ # Run at 6:17 AM UTC daily (off-peak minute, 30 min after review-reviewers)
+ - cron: '17 6 * * *'
+ workflow_dispatch:
+
+# Consistent with ci.yaml for cache compatibility
+env:
+ CARGO_TERM_COLOR: always
+ CLICOLOR_FORCE: 1
+ RUSTFLAGS: "-C debuginfo=0"
+ RUSTDOCFLAGS: "-Dwarnings"
+
+jobs:
+ cleaner:
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: write
+ pull-requests: write
+ issues: write
+ actions: read
+ id-token: write
+ steps:
+ - name: 📂 Checkout code
+ uses: actions/checkout@v6
+ with:
+ ref: main
+ fetch-depth: 0
+ fetch-tags: true
+ # Use bot token so pushed commits trigger CI workflows
+ token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
+
+ - name: 🔧 Configure git for Claude
+ run: |
+ git config --global user.name "Claude Code"
+ git config --global user.email "[email protected]"
+
+ - name: Install cargo-insta
+ uses: baptiste0928/cargo-install@v3
+ with:
+ crate: cargo-insta
+
+ - name: Install cargo-nextest
+ uses: baptiste0928/cargo-install@v3
+ with:
+ crate: cargo-nextest
+
+ - name: 💰 Cache
+ uses: Swatinem/rust-cache@v2
+ with:
+ prefix-key: ${{ hashFiles('Cargo.lock') }}
+ save-if: false
+
+ - name: Install shells (zsh, fish)
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y zsh fish
+
+ - name: 🤖 Run Claude Code for nightly cleanup
+ id: claude
+ uses: anthropics/claude-code-action@v1
+ with:
+ claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
+ github_token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
+ additional_permissions: |
+ actions: read
+
+ prompt: |
+ You are running as a nightly code quality sweep. Your job is to review all commits merged to main in the past 24 hours, find mistakes and improvement opportunities, and create issues or PRs.
+
+ ## Step 1: Find recent commits
+
+ ```
+ git log --since='24 hours ago' --oneline main
+ ```
+
+ If no commits were merged in the past 24 hours, report "no changes to review" and exit.
+
+ ## Step 2: Review the aggregate diff
+
+ Get the oldest commit from the past 24 hours and review the full diff:
+
+ ```
+ OLDEST=$(git log --since='24 hours ago' --format='%H' main | tail -1)
+ git diff ${OLDEST}^..HEAD
+ ```
+
+ Also review the individual commit messages to understand intent:
+ ```
+ git log --since='24 hours ago' --format='%h %s' main
+ ```
+
+ ## Step 3: Analyze the changes
+
+ Review the changes for:
+
+ 1. **Bugs or logic errors** in new code
+ 2. **Inconsistencies** with existing patterns in the codebase
+ 3. **Missing or outdated documentation**:
+ - Does `--help` still describe what the code does?
+ - Do CLAUDE.md instructions match current behavior?
+ 4. **Missing test coverage** for new code paths
+ 5. **Refactoring opportunities**:
+ - Duplicate code that should be shared
+ - Dead code that should be removed
+ - Non-canonical patterns (compatibility layers, parallel implementations)
+ 6. **CLAUDE.md or skill files** that need updating based on code changes
+
+ ## Step 4: Check for existing issues
+
+ Before creating any new issues, check for duplicates:
+ ```
+ gh issue list --state open --json number,title
+ ```
+
+ Also check for any open PRs that already address the same files or issues:
+ ```
+ gh pr list --state open --json number,title,headRefName
+ ```
+
+ ## Step 5: Report findings
+
+ For each finding:
+
+ 1. **Create a GitHub issue** with label `nightly-cleanup`:
+ - Title: Clear, actionable description
+ - Body: Include the relevant commit(s), code location (file:line), description of the problem, and suggested fix
+ - Use `gh issue create --label "nightly-cleanup"`
+
+ 2. **For confident fixes** (clear bugs, obvious missing tests, stale docs):
+ - Create a branch: `git checkout -b nightly/clean-${{ github.run_id }}`
+ - Make the changes
+ - Run tests to verify: use the test commands from CLAUDE.md
+ - Commit and push
+ - Create a PR referencing the issue(s)
+ - Monitor CI with `gh run watch`
+
+ ## Step 6: Summary
+
+ If the codebase looks clean, report a brief summary:
+ - Number of commits reviewed
+ - Files changed
+ - Assessment: clean / minor issues / needs attention
+
+ claude_args: |
+ --model opus
+ --allowedTools Bash,Edit,Read,Write,Glob,Grep,WebSearch,WebFetch,Task,Skill
+ --append-system-prompt "You are operating in a GitHub Actions CI environment. Use /running-in-ci before starting work."
+
+ - name: 📋 Upload Claude Code session logs
+ if: always()
+ uses: actions/upload-artifact@v6
+ with:
+ name: claude-session-logs
+ path: /home/runner/.claude/projects/
+ retention-days: 30
+ if-no-files-found: warn
diff --git a/.github/workflows/claude-nightly-review-reviewers.yaml b/.github/workflows/claude-nightly-review-reviewers.yaml
new file mode 100644
index 000000000..2d74f1f33
--- /dev/null
+++ b/.github/workflows/claude-nightly-review-reviewers.yaml
@@ -0,0 +1,152 @@
+name: claude-nightly-review-reviewers
+# Runner versions pinned; see ci.yaml header comment for rationale.
+
+# Nightly analysis of Claude CI session logs — identifies behavioral problems,
+# skill gaps, and workflow issues across all Claude-powered CI runs.
+on:
+ schedule:
+ # Run at 5:47 AM UTC daily (off-peak minute, after nightly-benchmark at 4:17)
+ - cron: '47 5 * * *'
+ workflow_dispatch:
+
+# Consistent with ci.yaml for cache compatibility
+env:
+ CARGO_TERM_COLOR: always
+ CLICOLOR_FORCE: 1
+ RUSTFLAGS: "-C debuginfo=0"
+ RUSTDOCFLAGS: "-Dwarnings"
+
+jobs:
+ review-reviewers:
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: write
+ pull-requests: write
+ issues: write
+ actions: read
+ id-token: write
+ steps:
+ - name: 📂 Checkout code
+ uses: actions/checkout@v6
+ with:
+ ref: main
+ fetch-depth: 0
+ fetch-tags: true
+ # Use bot token so pushed commits trigger CI workflows
+ token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
+
+ - name: 🔧 Configure git for Claude
+ run: |
+ git config --global user.name "Claude Code"
+ git config --global user.email "[email protected]"
+
+ - name: Install cargo-insta
+ uses: baptiste0928/cargo-install@v3
+ with:
+ crate: cargo-insta
+
+ - name: Install cargo-nextest
+ uses: baptiste0928/cargo-install@v3
+ with:
+ crate: cargo-nextest
+
+ - name: 💰 Cache
+ uses: Swatinem/rust-cache@v2
+ with:
+ prefix-key: ${{ hashFiles('Cargo.lock') }}
+ save-if: false
+
+ - name: Install shells (zsh, fish)
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y zsh fish
+
+ - name: 🤖 Run Claude Code to review reviewers
+ id: claude
+ uses: anthropics/claude-code-action@v1
+ with:
+ claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
+ github_token: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
+ additional_permissions: |
+ actions: read
+
+ prompt: |
+ You are running as a nightly job that reviews the behavior of all Claude-powered CI workflows from the past 24 hours. Your goal is to identify behavioral problems, skill gaps, and workflow issues — then create issues and/or PRs to fix them.
+
+ ## Step 1: Find recent Claude CI runs
+
+ Use `gh run list` to find all runs from Claude workflows in the past 24 hours:
+
+ ```
+ for wf in claude-review claude-ci-fix claude-issue-triage claude-mention claude-renovate claude-nightly-review-reviewers claude-nightly-cleaner; do
+ gh run list --workflow "${wf}.yaml" --created ">=$(date -d '24 hours ago' +%Y-%m-%dT%H:%M:%S)" --json databaseId,conclusion,createdAt --limit 50
+ done
+ ```
+
+ If no Claude CI runs occurred in the past 24 hours, report "no runs to review" and exit.
+
+ ## Step 2: Download session logs
+
+ For each run found, download the session log artifact:
+
+ ```
+ gh run download <run-id> --name claude-session-logs --dir /tmp/logs/<run-id>/
+ ```
+
+ Some runs may not have artifacts (e.g., skipped runs). That's fine — skip them.
+
+ ## Step 3: Analyze session logs
+
+ For each session log, analyze using jq extraction and gap analysis:
+ - Find JSONL files: `find /tmp/logs/ -name '*.jsonl' -type f`
+ - Extract conversation turns: `jq -c 'select(.type == "assistant" or .type == "tool_result")' < file.jsonl`
+ - Extract tool calls: `jq -c 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | {tool: .name, input: .input}' < file.jsonl`
+ - Look for tool calls, decisions, and outcomes
+ - Trace decision chains: what did Claude decide, what evidence did it use, what was the outcome?
+
+ ## Step 4: Identify problems
+
+ Compare each session against CLAUDE.md and project conventions. Flag anything where Claude's behavior diverged from the guidelines or produced a poor outcome.
+
+ ## Step 5: Check for existing issues
+
+ Before creating any new issues or PRs, check for duplicates:
+ ```
+ gh issue list --state open --json number,title
+ gh pr list --state open --json number,title,headRefName
+ ```
+
+ ## Step 6: Report findings
+
+ For each problem found:
+ 1. **Create a GitHub issue** with label `claude-behavior`:
+ - Title: Clear description of the behavioral problem
+ - Body: Include the run ID, specific log excerpts showing the problem, analysis of root cause, and suggested fix
+ - Use `gh issue create`
+
+ 2. **For actionable fixes** (skill edits, workflow tweaks, CLAUDE.md updates):
+ - Create a branch: `git checkout -b nightly/review-${{ github.run_id }}`
+ - Make the changes
+ - Commit and push
+ - Create a PR referencing the issue
+
+ ## Step 7: Summary
+
+ If no problems were found, report "all clear" with summary statistics:
+ - Number of runs analyzed
+ - Number of sessions reviewed
+ - Brief quality assessment
+
+ claude_args: |
+ --model opus
+ --allowedTools Bash,Edit,Read,Write,Glob,Grep,WebSearch,WebFetch,Task,Skill
+ --append-system-prompt "You are operating in a GitHub Actions CI environment. Use /running-in-ci before starting work."
+
+ - name: 📋 Upload Claude Code session logs
+ if: always()
+ uses: actions/upload-artifact@v6
+ with:
+ name: claude-session-logs
+ path: /home/runner/.claude/projects/
+ retention-days: 30
+ if-no-files-found: warn
diff --git a/.github/workflows/claude-renovate.yaml b/.github/workflows/claude-renovate.yaml
index f36e1bdf9..412dbf84c 100644
--- a/.github/workflows/claude-renovate.yaml
+++ b/.github/workflows/claude-renovate.yaml
@@ -117,6 +117,6 @@ jobs:
uses: actions/upload-artifact@v6
with:
name: claude-session-logs
- path: ${{ env.HOME }}/.claude/
+ path: /home/runner/.claude/projects/
retention-days: 30
if-no-files-found: warn