majiayu000/claude-skill-registry-agent-loops-nickcrew-claude-cortex-agent-loops
Complete operational workflow for implementer agents (Codex, Gemini, etc.) making code changes and writing tests. Defines the Code Change Loop, Test Writing Loop, and Issue Filing process with circuit breakers, severity levels, and escalation rules. Includes bundled scripts for specialist-review (code review) and test-review-request (test audit) that delegate to Claude CLI. Use this skill when starting any implementation task.
npx skills add https://github.com/majiayu000/claude-skill-registry --skill agent-loops
This skill defines the operational loops that implementer agents follow when making
code changes and writing tests. Each loop has explicit entry criteria, exit criteria,
and escalation rules. If you are an agent, follow these loops exactly.
You do not review your own work. All reviews are performed by Claude via dedicated
skills. You never grade your own homework.
Bundled references:
references/testing-standards.md — Test quality standards (how to write tests)references/audit-workflow.md — Test gap discovery (how to find what's missing)references/perspective-catalog.md — Review perspective selection (used by specialist-review)references/review-prompt.md — Claude review prompt templatereferences/audit-prompt.md — Claude test audit prompt templateBundled scripts:
scripts/specialist-review.sh — Shell out to Claude CLI for code reviewscripts/test-review-request.sh — Shell out to Claude CLI for test audit| Role | Agent | How |
|------|-------|-----|
| Implementer | Codex or Gemini | Writes code changes and test code |
| Code Reviewer | Claude | Invoked via specialist-review skill |
| Test Auditor | Claude | Invoked via test-review-request skill — finds gaps AND flags bad tests |
| Remediator | Codex or Gemini | Fixes findings from Claude's reviews |
Critical rule: Codex and Gemini NEVER self-review. Every review step means invoking a skill to send work to Claude. If you cannot invoke the review skill, STOP and escalate to the user — do not substitute your own review.
If shelling out to Claude fails (script error, CLI unavailable, permissions/network failure, timeout), escalate to the user immediately.
specialist-review — Request Code Review from ClaudeWhen: After completing implementation, after each remediation cycle.
What you get back: Findings with severity levels (P0-P3) and a verdict (BLOCKED / PASS WITH ISSUES / CLEAN).
Your ONLY job is to run the script and read the output file. Do NOT analyze the diff.
Do NOT write review comments. Do NOT adopt perspectives. Shell out and read the result.
The review requires Claude's skills ecosystem (JIT loading of domain-specific skills
like owasp-top-10, secure-coding-practices, python-testing-patterns, etc.).
Non-Claude agents do not have access to these skills.
# Review only the files you changed (RECOMMENDED)
scripts/specialist-review.sh --git -- src/parser/ src/auth.rs
# Review changes since a specific ref, scoped to a directory
scripts/specialist-review.sh --git origin/main -- claude_ctx_py/
# Review all changes vs last commit (use sparingly in monorepos)
scripts/specialist-review.sh --git
# Pipe in a pre-filtered diff
git diff HEAD~3..HEAD -- src/ | scripts/specialist-review.sh -
# Review a diff file
scripts/specialist-review.sh /path/to/changes.diff
# Custom output directory
scripts/specialist-review.sh --git --output ./my-reviews -- src/
Read the output file path printed to stdout:
REVIEW_FILE=$(scripts/specialist-review.sh --git -- src/parser/)
cat "$REVIEW_FILE"
Always scope to the files you touched. In a monorepo, an unscoped --git sends
the entire repo diff to Claude, wasting tokens and risking timeouts.
test-review-request — Request Test Audit from ClaudeWhen: Initial audit (before writing tests) and re-audit (after writing/fixing tests).
What you get back: A gap report covering both missing coverage AND test quality issues (mirror tests, flaky assertions, etc.), with P0/P1/P2 severity.
Your ONLY job is to run the script and read the output file. Do NOT read source code
to map behaviors. Do NOT classify test coverage. Do NOT produce a gap report.
Shell out and read the result.
The audit requires Claude's skills ecosystem — specifically the test-review skill
which pipelines testing standards into a structured audit workflow. Non-Claude agents
do not have access to these skills or the project-specific testing standards.
# Full audit of a module (default)
scripts/test-review-request.sh /path/to/module
# Full audit with specific test directory
scripts/test-review-request.sh /path/to/module --tests /path/to/tests
# Quick review of specific test files only
scripts/test-review-request.sh --quick /path/to/test_file.py
# Custom output directory
scripts/test-review-request.sh /path/to/module --output ./my-reports
Read the output file path printed to stdout:
REPORT_FILE=$(scripts/test-review-request.sh src/parser)
cat "$REPORT_FILE"
Act on findings:
There are two primary loops. They run sequentially — the code loop completes before the test loop begins.
┌─────────────────────────────────────────────────────────────────┐
│ CODE CHANGE LOOP │
│ Implement → specialist-review → Remediate → specialist-review │
│ Exit: all P0/P1 findings resolved │
│ Output: clean code + issues filed for P2+ │
├─────────────────────────────────────────────────────────────────┤
│ TEST WRITING LOOP │
│ Audit → Write Tests → Verify → Re-audit → Remediate → ... │
│ Exit: all P0/P1 gaps covered, no bad tests │
│ Output: tests passing + issues filed for P2+ │
└─────────────────────────────────────────────────────────────────┘
| Severity | Meaning | Loop Behavior |
|----------|---------|---------------|
| P0 | Security flaw, incorrect behavior, data loss, crashes | MUST fix before exit |
| P1 | Error handling gaps, resource leaks, missing validation, concurrency issues | MUST fix before exit |
| P2 | Code quality, naming, documentation, minor edge cases | File issue, do not block |
| P3 | Style preferences, optional improvements, future optimization | File issue, do not block |
ENTRY: Task spec or ticket describing the required change.
┌──────────────────┐
│ IMPLEMENT │ ← You (Codex/Gemini): write the code change per spec
└──────┬───────────┘
│
▼
┌──────────────────┐
│ specialist-review│ ← Run: scripts/specialist-review.sh --git -- <files>
└──────┬───────────┘ Script diffs your changed files, sends to Claude
│
├── Findings? ──► Yes ──► Any P0 or P1? ──► Yes ──┐
│ │
│ No ──► File P2/P3 issues │
│ Exit loop │
│ │
│ No findings ──► Exit loop │
│ │
▼ ▼
┌──────────────────┐
│ REMEDIATE │ ← You: fix ONLY P0/P1
└──────┬───────────┘ findings cited by Claude
│
▼
┌──────────────────┐
│ specialist-review│ ← Run script again (same paths)
└──────┬───────────┘ Script diffs remediated files,
│ Claude re-evaluates
└── Loop back to findings check
Maximum iterations: 3 specialist-review cycles.
If P0/P1 findings remain after 3 cycles:
This prevents infinite loops when you keep introducing new issues while fixing old ones, or when a finding requires a design-level change you can't make in remediation scope.
Claude evaluates against these criteria via specialist-review. You need to understand these so you can anticipate and prevent issues before review, and correctly interpret findings during remediation.
Correctness:
Security (when applicable):
Patterns and conventions:
Resource management:
Concurrency (when applicable):
Claude's specialist-review response will follow this format. Parse it to determine your next action.
## Code Review: [change description]
**Files reviewed:** [list]
**Iteration:** N of 3
### Findings
#### P0-001: [title]
**File:** `src/tunnel.rs:45-52`
**Issue:** [what's wrong]
**Impact:** [what happens if not fixed]
**Suggested fix:** [specific guidance, not just "fix this"]
#### P1-001: [title]
**File:** `src/auth.rs:23`
**Issue:** [what's wrong]
**Impact:** [what happens if not fixed]
**Suggested fix:** [specific guidance]
#### P2-001: [title]
**File:** `src/config.rs:100`
**Issue:** [what's wrong]
**Recommendation:** [what to improve]
### Summary
- P0: N findings (MUST fix)
- P1: N findings (MUST fix)
- P2: N findings (file issues)
- P3: N findings (file issues)
- **Verdict:** BLOCKED / PASS WITH ISSUES / CLEAN
When fixing findings from Claude's review:
specialist-review cycle.Fixed P0-001: [what was changed]This loop runs after the code change loop exits cleanly. It ensures the new (and existing) code has adequate test coverage.
The audit does double duty: it finds missing coverage AND flags bad tests (mirror tests, flaky assertions, etc.). A bad test doesn't close a gap, so a single audit pass catches both problems. No separate quality review step needed.
| Role | Agent | Skill |
|------|-------|-------|
| Auditor | Claude | test-review-request — finds gaps and flags bad tests per references/audit-workflow.md |
| Test Writer | Codex or Gemini | Writes tests per references/testing-standards.md standards |
Use a hybrid gate to avoid unnecessary friction while preserving confidence:
test-review-request and a re-audit state with no unresolved P0/P1 gaps.audit skipped: trivial with a one-line reason in the loop summary.Practical close criteria for implementer loops:
ENTRY: Code change loop has exited cleanly.
┌──────────────────────┐
│ AUDIT │ ← Run: scripts/test-review-request.sh <module>
└──────┬───────────────┘ Script sends module + tests to Claude, returns gap report
│
▼
┌──────────────────────┐
│ SCOPE APPROVAL │ ← Human reviews gap report
└──────┬───────────────┘ P0/P1 auto-approved. P2+ at human discretion.
│ Approved gaps become your work list.
▼
┌──────────────────────┐
│ WRITE TESTS │ ← You (Codex/Gemini): write tests for P0 first,
└──────┬───────────────┘ then P1. Follow testing-standards.md.
│
▼
┌──────────────────────┐
│ VERIFY │ ← You: run the tests locally. They must:
└──────┬───────────────┘ 1. Compile / pass lint
│ 2. All pass (no test is born failing)
│ 3. Actually exercise the code (not no-ops)
▼
┌──────────────────────┐
│ RE-AUDIT │ ← Run: scripts/test-review-request.sh <module>
└──────┬───────────────┘ Same module path — script re-reads source + tests
│ Claude checks: gaps closed? new tests good?
│
├── All P0/P1 resolved? ──► Yes ──► File P2/P3 issues
│ Exit loop ✅
│
└── No ──► Any P0/P1 remaining?
│
▼
┌──────────────────┐
│ REMEDIATE │ ← You: fix/rewrite the flagged tests
└──────┬───────────┘ or write tests for remaining gaps
│
└── Back to VERIFY
The audit report covers both gap analysis and quality in a single pass:
Coverage gaps (missing tests):
Test quality issues (bad tests):
assert(true), assertions that can never failA bad test shows up as an unclosed gap. A mirror test for behavior X means X is still "Missing" in the gap report, not "Covered". This is why one audit pass is sufficient.
| Severity | Meaning | Example |
|----------|---------|---------|
| P0 | Critical gap or false confidence | Missing auth test, mirror test on security path, assertion that passes with implementation deleted |
| P1 | Meaningful gap or fragile test | No error path test, happy-path-only, hardcoded port, timing-dependent assertion |
| P2 | Coverage improvement or test hygiene | Missing edge case, poor naming, verbose setup that should be a helper |
Maximum iterations: 3 audit cycles (initial audit + 2 re-audits).
If P0/P1 gaps remain after 3 cycles, escalate to human with a summary of what's proving difficult to test and why. This usually indicates the code needs refactoring to be testable — that's a design problem, not a test problem.
After both loops exit, file issues for everything that was deferred.
When filing deferred findings in this repository:
backlog/ folder exists at repo root and Backlog tooling is available (Backlog MCP tools and/or Backlog CLI), use Backlog to create tracked issues/tasks..agents/fixes/.review with fix from the source artifact name (s/review/fix/).*-fix.md filename.## [P2/P3] [Module]: [Brief description]
**Source:** [Code Review / Test Audit] iteration N
**Severity:** P2 | P3
**Module:** [file path]
### Description
[What's missing or what could be improved]
### Context
[Why this was deferred — not blocking but worth addressing]
### Suggested approach
[Brief guidance on how to address]
### Acceptance criteria
[How to verify this is done]
quality or test-gap as appropriate.improvement.You (Codex / Gemini) are responsible for:
scripts/specialist-review.sh --git -- <your-files> after implementation and each code remediationscripts/test-review-request.sh <module> for initial audit and each re-auditYou are NOT responsible for:
If Claude flags something you believe is incorrect:
Disputed P1-003: [your reasoning]When the circuit breaker triggers:
Per loop run:
These metrics help tune the loop — if you're consistently hitting 3 iterations, either the review checklist is too strict or the implementer instructions need work.
1. TASK SPEC arrives
│
▼
2. CODE CHANGE LOOP
├── You: implement
├── scripts/specialist-review.sh --git -- <files> → Claude reviews diff (max 3 cycles)
├── You: remediate P0/P1
├── File issues for P2/P3
└── Exit with clean code
│
▼
3. TEST WRITING LOOP
├── scripts/test-review-request.sh <module> → Claude audits (gaps + quality)
├── Human: scope approval (P0/P1 auto-approved)
├── You: write tests (testing-standards.md)
├── You: verify tests pass locally
├── scripts/test-review-request.sh <module> → Claude re-audits (max 3 cycles)
├── You: remediate P0/P1 gaps and bad tests
├── File issues for P2/P3
└── Exit with tested code
│
▼
4. ISSUE FILING
└── P2/P3 findings → tracked issues
│
▼
5. PR READY FOR HUMAN REVIEW
Take majiayu000/claude-skill-registry-agent-loops-nickcrew-claude-cortex-agent-loops from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.