Code Change Guardian
Protect a code change from proposal through proof. Lead with a native Markdown report, distinguish evidence from inference, and never claim safety without verification.
Select a mode
- impact: Analyze a proposed change without editing project files. Use this by default when the user asks what could break or says not to change code.
- refactor: Analyze, request approval, capture baseline behavior, edit incrementally, and verify behavior preservation.
- verify: Inspect an existing diff, branch, commit, or pull request and determine what it may break. Do not rewrite it unless asked.
If the request is ambiguous, start in impact mode. State the selected mode in the report.
Create the report first
Create CODE-CHANGE-REPORT.md in the repository root, unless the user specifies another path. Write the report in English. Keep updating the same file throughout the task so it remains the single source of truth inside Codex.
Use scripts/collect_change_context.mjs for the initial repository snapshot when Node.js is available:
node <skill-dir>/scripts/collect_change_context.mjs \
--root <repository-root> \
--mode impact \
--request "<requested change>" \
--out .codex/change-guardian/context.json
Read analysis-playbook.md before tracing impact. Read risk-model.md before scoring risks. Populate a report model following report-schema.md, then render it:
node <skill-dir>/scripts/generate_report.mjs \
--input .codex/change-guardian/report.json \
--out CODE-CHANGE-REPORT.md
Do not wait until the end to create the report. A partial, clearly labeled report is preferable to an invisible analysis.
Phase 1: Establish scope and baseline
- Resolve the repository root and inspect local instructions.
- Record the requested outcome, explicit non-goals, selected mode, current branch, HEAD, and dirty working-tree files.
- Preserve unrelated user changes. Never discard or overwrite them.
- Discover relevant validation commands from package manifests, CI configuration, build files, and repository docs.
- Run only proportionate read-only baseline checks. Record exact commands, results, duration when available, and skipped checks with reasons.
Phase 2: Map the blast radius
Start from the requested symbol, file, endpoint, schema, dependency, or current diff. Trace outward using repository-native tools and rg:
- Identify definitions, imports, exports, callers, consumers, registrations, routes, schemas, configuration, persistence, side effects, and tests.
- Inspect dynamic and implicit connections: string keys, reflection, dependency injection, event names, environment variables, generated code, serialization, migrations, feature flags, native boundaries, and public package exports.
- Use Git history only when it adds evidence: files that change together, prior regressions, reversions, and ownership hotspots.
- Classify each affected surface as direct, transitive, contractual, operational, or test-only.
- Attach evidence to every material claim with a file path, symbol, command result, diff hunk, or commit. Label unsupported conclusions
Inference or Unknown.
Do not treat a text search as a complete dependency graph. Explicitly list blind spots.
Phase 3: Model failure and risk
For each credible failure mode, record:
- trigger and affected user or system behavior;
- evidence and impacted files;
- likelihood, severity, detectability, and blast-radius scores;
- total risk tier using risk-model.md;
- prevention, detection, rollback, and remaining uncertainty.
Prioritize behavioral and contract risks over aesthetic code-quality observations.
Phase 4: Build a safe change plan
Produce an ordered plan with small reversible steps. For each step include files, preserved behavior, validation, rollback boundary, and prerequisites.
In impact mode, stop after the report and recommend the next safest action.
In refactor mode, pause before editing and request explicit approval for the proposed file scope and verification plan. Analysis does not authorize implementation.
Phase 5: Preserve behavior and change incrementally
After approval in refactor mode:
- Add or identify characterization tests for behavior that is important but insufficiently protected.
- Capture baseline outputs for observable contracts when tests are impractical.
- Make one coherent change at a time with recoverable checkpoints.
- Run the narrowest relevant checks after each step.
- Stop and update the report if the observed impact contradicts the plan or unrelated user changes overlap the target.
Do not call a feature change a refactor. If externally observable behavior intentionally changes, document the changed contract and obtain approval.
Phase 6: Verify and conclude
Run validation in layers: focused tests, contract or integration tests, type checking and linting, build, then broader suites when proportionate. Compare baseline and final behavior.
Update CODE-CHANGE-REPORT.md with:
- final verdict:
SAFE TO PROCEED, PROCEED WITH CONDITIONS, NOT SAFE YET, or INCONCLUSIVE;
- what was analyzed or changed;
- proof ledger with exact commands and results;
- residual risks, skipped checks, blind spots, and rollback plan;
- links to the most important local files.
Use SAFE TO PROCEED only when all high-risk paths have relevant passing evidence and no material unknown remains. Passing tests alone never prove universal safety.
Report quality rules
- Keep the executive summary useful without reading the rest.
- Include at least one compact impact table and one risk table.
- Include a Mermaid impact map only when it clarifies three or more relationships.
- Prefer clickable repository-relative paths in the report.
- Never fabricate coverage, call graphs, test results, or Git history.
- Separate
Observed, Inferred, and Unknown evidence.
- Make the file readable as a decision artifact, not a raw scanner dump.
1---2name: code-change-guardian3description: Analyze the blast radius of proposed or existing code changes, plan and execute behavior-preserving refactors, and prove whether changes are safe with repository evidence. Use when Codex needs to assess what could break before editing, safely refactor complex code, review a working-tree diff or pull request for regressions, map dependencies and implicit contracts, create characterization tests, plan rollback, or produce a native Markdown CODE-CHANGE-REPORT.md that opens directly in Codex.4---56# Code Change Guardian78Protect a code change from proposal through proof. Lead with a native Markdown report, distinguish evidence from inference, and never claim safety without verification.910## Select a mode1112- **impact**: Analyze a proposed change without editing project files. Use this by default when the user asks what could break or says not to change code.13- **refactor**: Analyze, request approval, capture baseline behavior, edit incrementally, and verify behavior preservation.14- **verify**: Inspect an existing diff, branch, commit, or pull request and determine what it may break. Do not rewrite it unless asked.1516If the request is ambiguous, start in `impact` mode. State the selected mode in the report.1718## Create the report first1920Create `CODE-CHANGE-REPORT.md` in the repository root, unless the user specifies another path. Write the report in English. Keep updating the same file throughout the task so it remains the single source of truth inside Codex.2122Use `scripts/collect_change_context.mjs` for the initial repository snapshot when Node.js is available:2324```bash25node <skill-dir>/scripts/collect_change_context.mjs \26 --root <repository-root> \27 --mode impact \28 --request "<requested change>" \29 --out .codex/change-guardian/context.json30```3132Read [analysis-playbook.md](references/analysis-playbook.md) before tracing impact. Read [risk-model.md](references/risk-model.md) before scoring risks. Populate a report model following [report-schema.md](references/report-schema.md), then render it:3334```bash35node <skill-dir>/scripts/generate_report.mjs \36 --input .codex/change-guardian/report.json \37 --out CODE-CHANGE-REPORT.md38```3940Do not wait until the end to create the report. A partial, clearly labeled report is preferable to an invisible analysis.4142## Phase 1: Establish scope and baseline43441. Resolve the repository root and inspect local instructions.452. Record the requested outcome, explicit non-goals, selected mode, current branch, HEAD, and dirty working-tree files.463. Preserve unrelated user changes. Never discard or overwrite them.474. Discover relevant validation commands from package manifests, CI configuration, build files, and repository docs.485. Run only proportionate read-only baseline checks. Record exact commands, results, duration when available, and skipped checks with reasons.4950## Phase 2: Map the blast radius5152Start from the requested symbol, file, endpoint, schema, dependency, or current diff. Trace outward using repository-native tools and `rg`:53541. Identify definitions, imports, exports, callers, consumers, registrations, routes, schemas, configuration, persistence, side effects, and tests.552. Inspect dynamic and implicit connections: string keys, reflection, dependency injection, event names, environment variables, generated code, serialization, migrations, feature flags, native boundaries, and public package exports.563. Use Git history only when it adds evidence: files that change together, prior regressions, reversions, and ownership hotspots.574. Classify each affected surface as direct, transitive, contractual, operational, or test-only.585. Attach evidence to every material claim with a file path, symbol, command result, diff hunk, or commit. Label unsupported conclusions `Inference` or `Unknown`.5960Do not treat a text search as a complete dependency graph. Explicitly list blind spots.6162## Phase 3: Model failure and risk6364For each credible failure mode, record:6566- trigger and affected user or system behavior;67- evidence and impacted files;68- likelihood, severity, detectability, and blast-radius scores;69- total risk tier using [risk-model.md](references/risk-model.md);70- prevention, detection, rollback, and remaining uncertainty.7172Prioritize behavioral and contract risks over aesthetic code-quality observations.7374## Phase 4: Build a safe change plan7576Produce an ordered plan with small reversible steps. For each step include files, preserved behavior, validation, rollback boundary, and prerequisites.7778In `impact` mode, stop after the report and recommend the next safest action.7980In `refactor` mode, pause before editing and request explicit approval for the proposed file scope and verification plan. Analysis does not authorize implementation.8182## Phase 5: Preserve behavior and change incrementally8384After approval in `refactor` mode:85861. Add or identify characterization tests for behavior that is important but insufficiently protected.872. Capture baseline outputs for observable contracts when tests are impractical.883. Make one coherent change at a time with recoverable checkpoints.894. Run the narrowest relevant checks after each step.905. Stop and update the report if the observed impact contradicts the plan or unrelated user changes overlap the target.9192Do not call a feature change a refactor. If externally observable behavior intentionally changes, document the changed contract and obtain approval.9394## Phase 6: Verify and conclude9596Run validation in layers: focused tests, contract or integration tests, type checking and linting, build, then broader suites when proportionate. Compare baseline and final behavior.9798Update `CODE-CHANGE-REPORT.md` with:99100- final verdict: `SAFE TO PROCEED`, `PROCEED WITH CONDITIONS`, `NOT SAFE YET`, or `INCONCLUSIVE`;101- what was analyzed or changed;102- proof ledger with exact commands and results;103- residual risks, skipped checks, blind spots, and rollback plan;104- links to the most important local files.105106Use `SAFE TO PROCEED` only when all high-risk paths have relevant passing evidence and no material unknown remains. Passing tests alone never prove universal safety.107108## Report quality rules109110- Keep the executive summary useful without reading the rest.111- Include at least one compact impact table and one risk table.112- Include a Mermaid impact map only when it clarifies three or more relationships.113- Prefer clickable repository-relative paths in the report.114- Never fabricate coverage, call graphs, test results, or Git history.115- Separate `Observed`, `Inferred`, and `Unknown` evidence.116- Make the file readable as a decision artifact, not a raw scanner dump.117