Skip to content

feat(code-review): add pattern learning to auto-suggest CLAUDE.md rules#31974

Closed
kpatel513 wants to merge 1 commit into
anthropics:mainfrom
kpatel513:feat/kp-pattern-learning
Closed

feat(code-review): add pattern learning to auto-suggest CLAUDE.md rules#31974
kpatel513 wants to merge 1 commit into
anthropics:mainfrom
kpatel513:feat/kp-pattern-learning

Conversation

@kpatel513

Copy link
Copy Markdown

Summary

Every review the plugin runs produces signal that currently disappears. If the same category of issue gets flagged across multiple PRs, that's a gap in the repo's CLAUDE.md — but today nothing surfaces it.

This adds a pattern learning layer that silently tracks validated issues across reviews, detects recurring patterns (3+ occurrences in the last 5 PRs), and proposes targeted CLAUDE.md changes directly in the terminal. The system also checks whether an existing rule already covers the pattern — if so, it suggests strengthening it rather than adding a duplicate.

The result: the plugin gets smarter the more you use it. Each review makes the next one cheaper.

How it works

Storage: .claude/review-patterns.json in the repo root (automatically gitignored). Schema:

{
  "version": 1,
  "patterns": [
    {
      "id": "uuid",
      "summary": "missing error handling in async functions",
      "occurrences": [
        {
          "pr_number": 123,
          "pr_title": "feat: add OAuth",
          "files_affected": ["src/auth.ts"],
          "issue_description": "OAuth state not cleaned up in finally block",
          "reviewed_at": "2026-03-07T10:00:00Z"
        }
      ]
    }
  ]
}

Threshold: 3 or more occurrences across the last 5 distinct PRs reviewed.

Terminal output when threshold is hit:

Recurring pattern — seen in 3 of last 5 PRs

  Pattern   missing error handling in async functions
  Seen in   PR #118, PR #121, PR #123

  No existing CLAUDE.md rule covers this.
  Suggested rule: "Always wrap async functions in try/catch.
                   Do not let Promise rejections go unhandled."

  Add to .claude/CLAUDE.md? [y/n]

If an existing rule already covers the pattern but violations keep occurring, the plugin suggests strengthening it instead of adding a duplicate.

Changes

plugins/code-review/commands/code-review.md

  • Step 6 (expanded): after filtering validated issues, update .claude/review-patterns.json with new occurrences, detect patterns meeting the threshold, and cross-reference existing CLAUDE.md rules
  • Step 7 (expanded): after main findings, surface pattern suggestions with y/n prompts; if confirmed, write the rule directly to the appropriate CLAUDE.md file

Design decisions

  • Local file, gitignored: keeps it zero-setup, no shared infrastructure needed. Team-wide pattern sharing is a natural v2.
  • 3 of last 5 PRs threshold: high enough to filter noise, low enough to surface real patterns quickly. Configurable in a future PR.
  • Modify/remove existing rules: the plugin doesn't just add rules — if a rule exists but the pattern persists, it suggests strengthening it. This prevents CLAUDE.md bloat.
  • Always terminal-only: pattern suggestions never appear in GitHub PR comments. They're a coaching tool for the developer running the review, not reviewer feedback.

Test plan

  • Review 3 PRs with the same category of issue — pattern suggestion should appear on the 3rd
  • Confirm .claude/review-patterns.json is created and gitignored automatically
  • Review a PR with an issue covered by an existing CLAUDE.md rule — should suggest strengthening, not adding duplicate
  • Answer n to all suggestions — store should still be updated, no CLAUDE.md changes
  • Answer y — CLAUDE.md should be updated with the drafted rule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant