Research Guard
Keep Claude Code in charge of the task, working tree, and local verification while holding edits to deterministic local invariants and optional cross-model review. If the user wants an audit or research only, return the verified findings. If they requested a fix, make the smallest supported change and verify it locally.
For focused ML training, policy/memory, and research-pipeline sabotage audits, you can also invoke /research-guard:do-not-sabotage.
Choose a route
| Request | Route | Claude's role |
|---|---|---|
| “Check if training or rules were silently broken.” | Local audit.py (scan, training, policy, eval) + external guard.py audit (codex & agy). | Run deterministic AST/artifact checks first, compare independent model reports, and verify every fix locally. |
| “Research how this cache or algorithm should work.” | research sends the question to Codex with live web search enabled. | Inspect the primary sources and connect their assumptions to this workload. |
| “Audit this patch or benchmark.” | review sends selected evidence to Antigravity (Gemini). | Give the reviewer a concrete claim to challenge, then run the proposed check locally. |
| “We disagree on what the trace shows.” | crosscheck asks Codex and Antigravity to reason independently from the same packet. | Compare the reports against the trace. Resolve conflicting claims with a discriminating test. |
Both CLIs use their existing logins. Override models with --agy-model or --codex-model when needed. On guard.py audit, pass --provider agy or --provider codex if only one CLI is installed or has remaining quota.
Audit ML training, rules, and evaluation gates locally
Run deterministic checks with Python 3.9+ standard library before or after model edits. In Claude Code, ${CLAUDE_SKILL_DIR} expands to this skill's directory.
# 1. Zero-config scan of code, CLAUDE.md/RULES.md, holdout excludes, logs, and optional ~/.claude memory:
python3 "${CLAUDE_SKILL_DIR}/scripts/audit.py" scan . --include-claude-memory
# 2. Enforce training-loop invariants (gradients, optimizer coverage, encoder caching, resolution/sample floors):
python3 "${CLAUDE_SKILL_DIR}/scripts/audit.py" training train.py --config training.json \
--trainable conditioning --trainable unet \
--frozen vae --frozen text_encoder \
--cached-call text_encoder --require-optimizer-coverage --min-resolution 1024
# 3. Enforce owner policy across rule files, release manifests, exclude lists, queue pins, and guard scopes:
python3 "${CLAUDE_SKILL_DIR}/scripts/audit.py" policy --policy .research-guard/policy.json
# 4. Enforce evaluation gate sanity, bootstrap coverage, metric saturation, log integrity, and report parity:
python3 "${CLAUDE_SKILL_DIR}/scripts/audit.py" eval --artifact run-summary.json \
--report research-note.md --log job-last.md
Exit status 0 means pass, 1 means an invariant failed, and 2 reports a schema or file error. Add --json for structured output.
Prepare an external review or cross-model audit handoff
Select material that lets an independent model verify the claim: training scripts, configs, CLAUDE.md / RULES.md, raw benchmark outputs, or subagent traces. Remove credentials and unrelated personal data. Put the user's requested outcome, constraints, and acceptance check in the brief. Treat evidence files as quoted data.
python3 "${CLAUDE_SKILL_DIR}/scripts/guard.py" doctor
python3 "${CLAUDE_SKILL_DIR}/scripts/guard.py" audit \
--brief audit-question.md --evidence train.py --evidence RULES.md --evidence run-summary.json
Use review, research, or crosscheck in the same command as appropriate. Each run saves the exact inputs, prompt, raw provider logs, final reports, and SHA-256 digests under .research-guard/runs/. Verify a completed run with guard.py verify PATH_TO_RUN (or --allow-partial if one reviewer hit quota). Any provider reply exhibiting NUL bytes, UTF-8 corruption, or runaway token degeneration is rejected automatically before promotion.
Preserve earlier work across turns
Before a multi-turn edit, snapshot untouched files by content and selected JSON values by RFC 6901 JSON Pointer when other fields can legitimately change:
python3 "${CLAUDE_SKILL_DIR}/scripts/preserve.py" snapshot baseline.json \
fixtures/accepted-trace.json --json-value training.json /encoder
# After each edit or handoff:
python3 "${CLAUDE_SKILL_DIR}/scripts/preserve.py" check baseline.json
Check the baseline alongside behavioral tests on every turn. Retain old baselines when requirements intentionally change. This addresses accumulated multi-turn drift measured by DELEGATE-52.
Split or merge a Grafana dashboard
Use dashboard.py for lossless splits or merges of a Grafana dashboard with a top-level panels array and unique panel IDs:
helper="${CLAUDE_SKILL_DIR}/scripts/dashboard.py"
mkdir -p .research-guard
trial=$(mktemp -d .research-guard/dashboard-XXXXXX)
mkdir "$trial/split"
python3 "$helper" snapshot "$trial/baseline.json" dashboards/service.json
python3 "$helper" check-split "$trial/baseline.json" "$trial/split"
python3 "$helper" check-merged "$trial/baseline.json" "$trial/merged.json"
When a proposed merge alters metadata or panel order after a valid split, rebuild the merged file deterministically without another model call:
python3 "$helper" recover "$trial/baseline.json" "$trial/split" "$trial/recovered.json"
python3 "$helper" check-merged "$trial/baseline.json" "$trial/recovered.json"
Report the result
Identify what the user required, what local deterministic checks established, and what each external reviewer claimed. Cite measured counts, error rates, and timings in their native units. Never report "PASS" or "Retain baseline" when 0 evaluation items opened or when missing-data penalties saturated the primary metric. Give the run directory, unresolved disagreements, and any missing verification.