From codeant
Learn your team's review patterns from PR history, project guidelines (.cursorrules, CLAUDE.md), and coding conventions to generate custom CodeAnt review rules in .codeant/review.json
How this skill is triggered — by the user, by Claude, or both
Slash command
/codeant:codeant-implement-repo-learningsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyze the last 100 pull requests to extract recurring human review feedback patterns, combine them with project guidelines from committed config files (.cursorrules, CLAUDE.md, .guidelines, etc.), and generate a `.codeant/review.json` with custom review rules tailored to the team's standards. Each candidate rule is presented for interactive approval before being included.
Analyze the last 100 pull requests to extract recurring human review feedback patterns, combine them with project guidelines from committed config files (.cursorrules, CLAUDE.md, .guidelines, etc.), and generate a .codeant/review.json with custom review rules tailored to the team's standards. Each candidate rule is presented for interactive approval before being included.
Before doing anything else, check that the codeant CLI is on the latest version:
npm view codeant-cli version
Compare with the installed version:
codeant --version
If the installed version is older than the latest published version, update it:
npm install -g codeant-cli@latest
If the update fails (e.g., permission error), warn the user and continue.
Verify the repo has a remote and detect the SCM platform:
git remote -v
If no remote is found, tell the user: "This repo has no remote. Please add one or run this from a repo with PR history." and stop.
The codeant CLI auto-detects the repository name, remote platform (GitHub/GitLab/Bitbucket/Azure), and default branch from the git remote URL. You do not need to manually detect these.
Verify the user has a token set for the detected platform:
codeant pr list --state closed --limit 1
If this fails with an authentication error, tell the user: "Please set your SCM token first: codeant set-token <github|gitlab|bitbucket|azure> <your-token>" and stop.
Before starting, check if a .codeant/review.json already exists:
cat .codeant/review.json 2>/dev/null
If it exists:
.codeant/review.json with N rules. I'll merge new rules with the existing ones — existing rules will be preserved, and I'll flag any duplicates or conflicts."If it does not exist, continue normally.
codeant track --event "skill_invoked" --props '{"skill_name": "codeant-implement-repo-learnings", "source": "claude-code"}'
Fetch the most recent 100 closed/merged PRs to ensure a rich feedback history. Use pagination with offset:
codeant pr list --state closed --limit 100
The output is a JSON array of PR objects with fields: number, title, state, merged, author, sourceBranch, targetBranch, createdAt, updatedAt, url.
Filter to keep only PRs where merged is true (closed but not merged PRs are not useful).
If fewer than 10 merged PRs are returned, warn the user: "Only N merged PRs found. The generated rules may be less accurate with limited history. Continuing anyway."
If zero merged PRs are returned, stop and tell the user: "No merged PRs found in this repo. Custom rules require PR history to learn from."
Tell the user: "Found N merged PRs. Fetching review comments..."
For each merged PR, fetch only non-CodeAnt comments using the --codeant-generated false flag. This is critical — without this flag, the CLI returns all comments including CodeAnt bot reviews, quality gate reports, and coverage reports which would overwhelm the results.
codeant pr comments --pr-number <N> --codeant-generated false
The output is a JSON array of comment objects. The fields vary slightly by platform (GitHub, GitLab, Bitbucket, Azure DevOps) — the CLI auto-detects the platform from the git remote.
Common fields (all platforms):
| Field | Description |
|---|---|
id | Unique comment identifier (integer) |
type | "review" (inline on code) or "issue" (general PR comment) |
author | Comment author login string (e.g., "Chhinna", "Sagar-CodeAnt") |
body | The full comment text in markdown |
path | File path the comment refers to (null for general comments) |
line | Line number the comment refers to (null for general comments) |
createdAt | ISO 8601 timestamp when the comment was posted |
updatedAt | ISO 8601 timestamp when the comment was last edited |
isCodeantComment | Boolean — always false when using --codeant-generated false |
Platform-specific fields:
| Field | GitHub | GitLab | Bitbucket | Azure DevOps |
|---|---|---|---|---|
inReplyToId | Yes | No | No | No |
resolved | No | Yes | Yes | Yes |
discussionId | No | Yes | No | No |
threadId | No | No | No | Yes |
Important: Process PRs in batches of 10–15 to be efficient. After each batch, tell the user the progress: "Processed X/Y PRs, collected Z comments so far..."
Even with --codeant-generated false, additional filtering is needed. The filtering strategy must account for platform differences.
Filter out comments where author matches bot patterns (case-insensitive):
[bot] suffix (e.g., dependabot[bot], renovate[bot])-bot suffix (e.g., snyk-bot)dependabot, renovate, codecov, sonarcloud, github-actions, copilot, mergify, stale, allcontributors, semantic-release-bot, greenkeeperPR authors often reply to CodeAnt bot suggestions with acknowledgements like "it is correct", "updated", "this is okay. no change needed here", "frontend will handle this". These are NOT peer review feedback and must be filtered out.
The detection strategy differs by platform:
GitHub — Use inReplyToId:
inReplyToId is not null AND the comment author is the same person as the PR author → DISCARD. These are the PR author responding to bot reviews.inReplyToId is not null AND the comment author is different from the PR author → KEEP. These may be peer reviewers adding context to a thread.GitLab / Bitbucket / Azure DevOps — No inReplyToId field exists. Use content-based heuristics instead:
@codeant or @codeant-aiComments with type: "issue" and path: null are general PR conversation comments — not inline code review feedback. These include:
@codeant-ai : review)Discard all comments where type is "issue".
Filter out comments where body length is < 15 characters — these are typically reactions like "LGTM", "+1", "nice", "thanks", "updated", "fixed".
On platforms that provide the resolved field (GitLab, Bitbucket, Azure DevOps), also consider: resolved comments are less likely to contain patterns worth codifying if the fix was trivial. However, do NOT discard resolved comments — they often contain the best feedback (reviewer pointed out an issue → author fixed it → thread resolved). Only use the resolved field as a signal during Step 4 classification: resolved comments with substantive feedback are high-confidence patterns.
After all filtering, tell the user: "Collected N human review comments from M pull requests (platform: )."
From the filtered human comments, classify each into one of two categories:
FEEDBACK (keep) — Actionable review suggestions. These suggest a concrete change or enforce a convention:
NOT FEEDBACK (discard) — Non-actionable comments:
Use the following heuristic to classify:
After classification, tell the user: "Found N actionable feedback comments out of M total human comments."
If fewer than 5 feedback comments are found, warn: "Very few actionable feedback comments found. The generated rules may be generic. Consider running this again after more PRs have been reviewed."
Mine the git history for commits that fix bugs or revert changes — these reveal what patterns cause production issues and are high-confidence rule candidates.
git log --oneline --all -500 --grep="fix" --grep="bug" --grep="hotfix" --grep="patch" --grep="resolve" --or
Also search for revert commits:
git log --oneline --all -500 --grep="revert" --grep="Revert"
For each bug-fix or revert commit (up to 50 most recent), examine what was changed:
git show --stat <commit-hash>
git show --format="" <commit-hash>
Look for patterns in what keeps getting fixed:
time.sleep in async handlers), race conditionsIf a bug-fix pattern aligns with feedback found in Step 4 (e.g., reviewers keep saying "add error handling" AND there are multiple commits fixing missing error handling), that's a very high confidence rule. Mark these as "reinforced by bug history" during rule generation.
Tell the user: "Analyzed N bug-fix commits and M reverts. Found P recurring fix patterns."
If zero bug-fix commits are found, skip this step silently and continue.
Search the repository root for any committed guidelines or configuration files that encode team standards:
ls -la .cursorrules .cursor/rules/*.mdc .cursor/rules/*.md CLAUDE.md .claude/CLAUDE.md .github/CONTRIBUTING.md CONTRIBUTING.md .guidelines .github/CODEOWNERS 2>/dev/null
Read any files that exist. Focus on extracting code logic, architecture, and convention rules — not styling/formatting:
.cursorrules / .cursor/rules/* — AI coding assistant rules (often contain team conventions)CLAUDE.md / .claude/CLAUDE.md — Claude Code project instructionsCONTRIBUTING.md — Contribution guidelines (focus on code conventions, not formatting).guidelines — Explicit team guidelinesIgnore styling/formatting files — do NOT read or extract rules from:
.editorconfig, .prettierrc*, .eslintrc* (formatting rules only)CODE_STYLE.md, STYLE_GUIDE.md (styling/formatting guides).clang-format, .clang-tidyThe goal is to capture logic, architecture, security, and convention patterns — not formatting preferences that are already handled by formatters and linters.
For each file found, extract any rules that are:
Tell the user: "Found K guideline/config files with relevant conventions."
Detect the primary languages in the repo:
git ls-files | sed 's/.*\.//' | sort | uniq -c | sort -rn | head -20
Also detect the directory structure for precise file globs:
git ls-files | head -200
Map extensions to glob patterns:
.ts / .tsx → **/*.ts, **/*.tsx.js / .jsx → **/*.js, **/*.jsx.py → **/*.py.go → **/*.go.rs → **/*.rs.java → **/*.java.rb → **/*.rbUse actual directory paths from the project when a rule only applies to certain areas (e.g., src/api/**/*.ts for API-specific rules).
Analyze all collected feedback comments to identify recurring patterns. Group similar feedback into clusters:
Confidence levels for each candidate rule:
Only generate rules with MEDIUM or HIGH confidence. LOW confidence patterns should be mentioned to the user but not proposed as rules.
For each identified cluster, draft a candidate rule with:
If an existing .codeant/review.json was found in Step 0c, compare each candidate rule against the existing rules:
This step is critical. Do NOT skip it. Present each candidate rule to the user one at a time and get their approval before including it.
For each candidate rule, present it like this:
Rule N of M: rule-id-here — Confidence: HIGH
Description: "Full description of the rule"
Applies to: ["glob-pattern-1", "glob-pattern-2"]
Scope: ["ide", "pr"]
Evidence:
abc123: "fix: missing null check in payment handler" (fixes same pattern).cursorrules mentions "..."Action: Should I include this rule? You can:
Wait for the user's response before moving to the next rule. If the user says "modify", apply their changes and confirm the updated version before proceeding.
If there are many rules (>15), after presenting the first 5, ask the user: "There are M more rules to review. Would you like to continue one-by-one, or should I show the rest in a batch and you can tell me which to remove?"
After all rules have been confirmed, convert the approved rules into the CodeAnt review.json format:
{
"id": "unique-kebab-case-id",
"description": "Clear, specific description of what to enforce and why",
"files": ["glob-pattern-1", "glob-pattern-2"],
"scope": ["ide", "pr"]
}
Rule quality guidelines:
["ide"] — for style/convention rules developers should see while coding["pr"] — for rules that need full PR context (e.g., "every PR touching the API must update the OpenAPI spec")["ide", "pr"] — for critical rules that should be enforced everywhere (security, error handling)Create the .codeant directory and write the review.json:
mkdir -p .codeant
If no existing review.json was found — write the file with the approved rules:
{
"rules": [
{
"id": "rule-id-1",
"description": "...",
"files": ["..."],
"scope": ["ide", "pr"]
}
]
}
If an existing review.json was found — merge the new approved rules into the existing file:
id values — if a new rule has the same id as an existing one, suffix it with -v2 or ask the user to rename.After writing, show the user a diff summary: "Added N new rules, kept M existing rules, replaced P rules."
Show the user a summary:
Custom Rules Generated:
Then list the final rules grouped by theme:
For each rule show:
Tell the user:
"Custom rules written to .codeant/review.json. These rules will be applied on top of CodeAnt's default bug and security detection during IDE and PR reviews.
Next steps:
.codeant/review.json file so your team benefits from these rules/codeant-review on your current changes to see the rules in action/codeant-implement-repo-learnings anytime to update rules as your team's practices evolve.codeant/review.json anytime to add, remove, or tweak rulesWould you like me to commit the file now?"
codeant track --event "custom_rules_generated" --props '{"skill_name": "codeant-implement-repo-learnings", "source": "claude-code", "rules_count": <N>, "prs_analyzed": <M>, "feedback_comments": <K>, "bugfix_commits": <P>, "guideline_files": <G>, "rules_skipped": <Z>, "existing_rules_preserved": <E>}'
.codeant/review.json rules without user confirmation. Always merge, never replace.**/* everywhere.Provides CDSS development patterns for drug interaction checking, dose validation, clinical scoring (NEWS2, qSOFA), and alert classification integrated into EMR workflows.
npx claudepluginhub codeant-ai/skills --plugin codeant