home / skills / proxiblue / claude-skills / audit-loop

audit-loop skill

/audit-loop

This skill automates an iterative audit-fix loop for changed files, detecting issues and re-auditing until clean.

npx playbooks add skill proxiblue/claude-skills --skill audit-loop

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.7 KB
---
name: audit-loop
description: Iterative audit-fix loop using Ralph Wiggum. Spawns parallel performance, security, and code quality audits on currently edited files, fixes Critical/High issues, and re-audits until clean. Invoke with /audit-loop.
---

# Audit Loop Skill

Automated iterative audit-fix cycle using the Ralph Wiggum loop plugin. Detects your currently edited files via `git diff`, spawns 3 parallel audit agents (performance, security, code quality), fixes any Critical or High findings, then re-audits until clean.

## When to Use

- After implementing a feature or refactoring, before committing
- When you want hands-off audit-fix iteration
- Invoke with: `/audit-loop`

## Execution Steps

### Step 1: Detect Changed Files

Run `git diff --name-only HEAD` and `git diff --name-only --cached` to get all modified and staged files. Filter to only `.php`, `.phtml`, and `.xml` files (auditable code). If no changed files are found, inform the user and stop.

### Step 2: Start the Ralph Loop

Use the `/ralph-loop` command with the following prompt template. Replace `{FILE_LIST}` with the actual file list from Step 1.

```
/ralph-loop "Audit the following recently edited files for performance, security, and code quality issues.

## Files to Audit
{FILE_LIST}

## Process

1. **Detect files**: Run `git diff --name-only HEAD` and `git diff --name-only --cached` to get current changed files (only .php, .phtml, .xml). Use these as the audit target.

2. **Run 3 parallel audits** using the Task tool:
   - **Performance** (subagent_type: magento-performance-analyst, model: opus): Check for N+1 queries, redundant DB loads, missing collection attribute preloading, cache concerns, memory issues.
   - **Security** (subagent_type: magento-security-analyst, model: opus): Check for XSS, CSS/SQL injection, output escaping, input validation, CSRF.
   - **Code Quality** (subagent_type: magento-code-reviewer, model: opus): Check PSR-12, type hints, PHPDoc, use statements, Magento patterns. Do NOT flag missing copyright headers (project standard prohibits them).

3. **Collect findings** with severity: Critical / High / Medium / Low.

4. **If Critical or High findings exist**:
   - Fix them in the code immediately
   - Run `bin/magento setup:di:compile` if any PHP files were changed, to verify compilation
   - Run `bin/magento cache:flush`
   - Exit (Ralph loop will feed this prompt back for re-audit)

5. **If NO Critical or High findings remain**:
   - Print the final audit summary table
   - Output: <promise>AUDIT CLEAN</promise>

## Rules
- Do NOT add copyright headers (project CLAUDE.md says: do not add copyright headers)
- Do NOT flag deprecated Registry usage as Critical/High (deferred by design)
- Do NOT flag pre-existing issues in files you did not modify
- Focus audit on the CHANGED code, not the entire codebase
- Always verify PHP changes compile before declaring clean" --completion-promise "AUDIT CLEAN" --max-iterations 5
```

### Step 3: Monitor

The Ralph loop handles everything automatically:
- **Iteration 1**: Audit → find issues → fix → exit → loop restarts
- **Iteration N**: Re-audit → if clean → outputs `<promise>AUDIT CLEAN</promise>` → loop ends
- **Safety**: `--max-iterations 5` prevents runaway token burn (5 full audit-fix cycles max)

## Example Usage

```
/audit-loop
```

That's it. Claude will:
1. Detect your changed files
2. Start the ralph loop
3. Audit → fix → re-audit automatically
4. Stop when clean or after 5 iterations

## Cost Estimate

Each iteration spawns 3 opus agents (~30-40k tokens each). Expect:
- **Clean code**: ~120k tokens (1 iteration, exits immediately)
- **1-2 fix cycles**: ~250-400k tokens
- **Max 5 iterations**: ~600-800k tokens (worst case)

Overview

This skill runs an automated, iterative audit-and-fix loop focused on the files you recently edited. It spawns three parallel audits—performance, security, and code quality—fixes any Critical or High findings, and repeats until the changed files are clean or a max iteration limit is reached. Invoke with /audit-loop to run the process on staged and unstaged changes.

How this skill works

The skill detects changed files via git diff (HEAD and cached) and filters to auditable extensions (.php, .phtml, .xml). It starts a Ralph Wiggum loop that runs three parallel subagents for performance, security, and code quality audits, collects severity-labeled findings, and automatically applies fixes for Critical and High issues. After fixes it compiles PHP changes and flushes caches, then re-runs audits up to five iterations or until no Critical/High findings remain.

When to use it

  • Before committing a feature or refactor to catch regressions early
  • When you want a hands-off audit-and-fix cycle for recently edited files
  • To verify performance, security, and quality concerns focused only on changed code
  • When you need automated re-auditing until Critical/High issues are resolved

Best practices

  • Run on the branch containing your work before pushing to remote
  • Stage any files you want audited so both staged and unstaged changes are detected
  • Review automated fixes before committing, especially for behavioral changes
  • Ensure your development environment can run bin/magento commands used for compile and cache flush
  • Limit edits to relevant files per audit (.php, .phtml, .xml) to keep audits focused

Example use cases

  • After refactoring a checkout flow, run /audit-loop to catch N+1, escaping, or PSR violations in changed files
  • When adding a new controller or model, ensure security and code quality fixes are applied automatically
  • Before opening a pull request, run the loop to ensure no Critical/High findings remain in modified files
  • Use during a rapid iteration cycle to automatically apply urgent fixes and re-audit until clean

FAQ

What files are inspected?

Only files returned by git diff --name-only HEAD and git diff --name-only --cached, filtered to .php, .phtml, and .xml are audited.

What happens to fixes the skill makes?

The loop applies fixes directly to the changed files, then runs bin/magento setup:di:compile if PHP changed and bin/magento cache:flush. You should review and commit changes manually after verification.