From code-coherence
This skill should be used when the user asks to "check this code", "validate this", "verify this implementation", "is this correct", "review this code", "check for errors", "multi-agent verification", or mentions production-critical code, financial calculations, security implementations, or high-stakes operations. Provides comprehensive multi-agent verification workflow with specialized critic agents.
npx claudepluginhub reggiechan74/cc-plugins --plugin code-coherenceThis skill uses the workspace's default tool permissions.
Execute comprehensive multi-agent verification for production-critical code using the "Team of Rivals" architecture. This skill orchestrates specialized critic agents with opposing incentives to catch errors before they reach production, achieving 92%+ reliability versus 60% single-agent baseline.
Enforces C++ Core Guidelines for writing, reviewing, and refactoring modern C++ code (C++17+), promoting RAII, immutability, type safety, and idiomatic practices.
Provides patterns for shared UI in Compose Multiplatform across Android, iOS, Desktop, and Web: state management with ViewModels/StateFlow, navigation, theming, and performance.
Implements Playwright E2E testing patterns: Page Object Model, test organization, configuration, reporters, artifacts, and CI/CD integration for stable suites.
Execute comprehensive multi-agent verification for production-critical code using the "Team of Rivals" architecture. This skill orchestrates specialized critic agents with opposing incentives to catch errors before they reach production, achieving 92%+ reliability versus 60% single-agent baseline.
Activate this skill for high-stakes code where errors have significant consequences:
Do not use for exploratory coding, prototypes, or low-stakes experiments.
Before any code changes, create an execution plan with pre-declared acceptance criteria:
Acceptance criteria must be:
Example plan structure:
EXECUTION PLAN
Scope: Refactor authentication to JWT tokens
Files: src/auth/login.ts, src/auth/middleware.ts
SUCCESS CRITERIA (Pre-Declared):
✓ All existing auth tests pass
✓ No OWASP Top 10 vulnerabilities introduced
✓ Token storage uses httpOnly cookies (not localStorage)
✓ Token refresh logic handles 401 responses
✓ Code coverage maintained at 85%+
CRITICS ASSIGNED:
- Code Critic: Test pass rate, coverage, logic correctness
- Security Critic: OWASP compliance, token storage, auth flow
- Domain Critic: Session management business rules
RETRY BUDGET: 6 iterations before escalation
ESTIMATED COST: +40% tokens (~$0.15 additional)
VETO AUTHORITY: ANY critic can reject (unanimous approval required)
Execute changes while maintaining strict context boundaries:
Context isolation rules:
Run specialized critics in parallel (default) or sequential (optional):
Code Critic evaluation:
EVALUATION: Code Changes
✓ Syntax: All files parse correctly
✓ Logic: JWT token generation handles expiration
✓ Performance: No N+1 queries introduced
❌ VETO: Missing error handling in token refresh
Reason: 401 response from refresh endpoint not caught
Impact: Users experience silent logout without feedback
Fix: Add try-catch around fetch(), show re-login modal
Security Critic evaluation:
EVALUATION: Security Review
✓ OWASP: No SQL injection vectors
✓ Auth: JWT signature validation correct
✓ Data: No sensitive data in logs
❌ VETO: XSS vulnerability in error messages
Reason: User input echoed in error modal without escaping
Impact: Reflected XSS if attacker controls username
Fix: Use textContent instead of innerHTML for error display
.claude/rules/Domain Critic evaluation:
EVALUATION: Domain Rules (Financial)
✓ Precision: Using Decimal type, not float
✓ Rounding: Banker's rounding applied
❌ VETO: Missing audit trail for token generation
Reason: Financial regulations require logging all auth events
Impact: Cannot prove compliance during audit
Fix: Log token generation with user_id, timestamp, IP to audit table
Process critic verdicts following hierarchical veto authority:
Retry loop example:
Iteration 1: Security Critic vetoes (XSS vulnerability)
→ Executor fixes: Use textContent instead of innerHTML
Iteration 2: Domain Critic vetoes (missing audit trail)
→ Executor fixes: Add logging to audit table
Iteration 3: All Critics approve ✓
→ Advance to user review
Retry budget: 6 iterations (default), configurable per project Escalation: Require human review, downgrade to single-agent, or fail with report
Present final results with complete decision history:
Summary report format:
✓ COHERENCE CHECK COMPLETE
Status: All Critics Approved
Iterations: 3 (budget: 6 remaining)
Time: 4.2 minutes (verification: 1.8min, execution: 2.4min)
Cost: +38.6% tokens ($0.15 additional)
CRITIC VERDICTS:
✓ Code Critic: Approved (iteration 1)
✓ Security Critic: Approved (iteration 2, after XSS fix)
✓ Domain Critic: Approved (iteration 3, after audit trail added)
FILES CHANGED:
- src/auth/login.ts (+42, -15)
- src/auth/middleware.ts (+28, -8)
ACCEPTANCE CRITERIA MET:
✓ All existing auth tests pass (18/18)
✓ No OWASP Top 10 vulnerabilities
✓ Token storage uses httpOnly cookies
✓ Token refresh handles 401 responses
✓ Code coverage maintained (87%, was 85%)
View detailed audit trail: /audit-trail show session-abc123
Load settings from .claude/code-coherence.local.md:
Define file patterns requiring automatic verification:
highStakesPatterns:
- "src/auth/**"
- "src/payment/**"
- "src/financial/**"
- "database/migrations/**"
When user requests changes to files matching these patterns, proactively suggest coherence check.
Enable/disable critics and select models:
critics:
code:
enabled: true
model: opus
vetoThreshold: strict # or critical-only
security:
enabled: true
model: opus
domain:
enabled: true
model: opus
specialization: financial # or healthcare, legal, custom
retryBudget: 6
consensusMode: unanimous # unanimous, majority, weighted
parallelExecution: true # parallel (faster) or sequential (cheaper)
autoVerify: false # false = ask user, true = auto-run on high-stakes
acceptableErrorRate: 0.079 # 7.9% residual per research paper
costVisibility:
showTokens: true # Display token counts per critic
showTime: true # Show time breakdown
estimateCost: true # Estimate before running
After creating execution plan, automatically invoke:
/plan-review
This validates the plan itself before execution, checking for completeness, clarity, and measurability.
For domain-specific criteria not covered by pre-built templates:
/acceptance-criteria define for this authentication refactoring
All decisions automatically logged. Retrieve with:
/audit-trail show session-abc123
Or search:
/audit-trail search security critic rejections
After running coherence check, optionally validate critics have orthogonal failure modes:
/swiss-cheese-validation verify independence
Investment: 38.6% computational overhead (research-validated) Return: 80% reduction in user-facing errors
When justified:
When not justified:
Three independent critics with misaligned failure modes:
Code Critic catches 87.8% of errors:
Security Critic catches what Code Critic misses:
Domain Critic catches what both miss:
Result: Errors that slip through one layer encounter another. With orthogonal failure modes, 92.1% of errors caught before user exposure.
Problem: Multiple critics veto for conflicting reasons Solution: Escalate to human review with detailed rationale from each critic
Problem: 6 iterations completed, critics still rejecting Solution: Three escalation options (user-configurable):
Problem: Token usage higher than estimated Solution:
Problem: 7.9% residual error rate (expected per research) Cause: Errors requiring external context (requirement ambiguity, subjective preferences, domain edge cases) Solution: Refine acceptance criteria with more specificity, add custom domain critic
For detailed patterns, advanced techniques, and implementation guides:
references/research-paper.md - Original "Team of Rivals" research paper summaryreferences/swiss-cheese-model.md - Error prevention through layered validationreferences/organizational-intelligence.md - How organizational principles apply to AI systemsreferences/critic-patterns.md - Common critic evaluation patterns and heuristicsreferences/cost-optimization.md - Strategies for reducing overhead while maintaining reliabilityWorking examples demonstrating coherence check in action:
examples/financial-calculation.md - Multi-agent verification for compound interest calculatorexamples/auth-refactoring.md - JWT implementation with security and domain criticsexamples/data-migration.md - Database schema change with rollback validationPre-built acceptance criteria for common scenarios:
templates/financial.yaml - Financial calculation standards (precision, rounding, audit)templates/security.yaml - OWASP Top 10 checklist, auth patternstemplates/performance.yaml - Latency SLAs, memory limits, query optimizationTriggering: Broad patterns for accessibility - users don't need to know exact command Default behavior: Interactive (ask user for approval), option for automation Output format: Summary by default, detailed report on request Critic execution: Parallel by default (faster), sequential option (cheaper) Consensus: Unanimous approval required (any veto blocks), majority/weighted as options
Integration points:
.claude/code-coherence.local.md.claude/coherence-audit/ with git commit references