/re-arch:re-arch-guardrailsfrom re-arch
Generates architecture enforcement guardrails including agent rules, CI fitness functions, ADRs, and review checklists. Use after choosing a target architecture or when AI agents put code in wrong places.
Ships in re-arch. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
A refactoring that is not enforced erodes within months, faster with AI agents generating code from whatever examples they find. Guardrails make the target explicit for agents and humans, check it in the agent's own loop, and make it mechanical in CI.
.re-arch/options.json (decision.chosen), .re-arch/domains.json, .re-arch/plan.json (phases tell when each rule must reach zero), .re-arch/findings.json (each rule prevents a finding), .re-arch/scan.json (ecosystems, graph sources, current violations), .re-arch/meta.json. Retained option missing: ask, or take the recommended one and say so.
Use this tree so teams and the report always find the same thing:
.re-arch/guardrails/
README.md where each file goes in the repo, in which order to adopt them
AGENTS.md root rules (or AGENTS.section.md to merge into an existing file)
domains/<domain>/AGENTS.md only for domains whose target style differs from the root
skills/<project>-architecture/SKILL.md
hooks/ agent hook configs (Claude Code settings snippet, others)
checks/ native tool configs (.dependency-cruiser.cjs, deptrac.yaml, ArchitectureTests.cs...)
tools/re-arch/ check_architecture.py + scanner modules + architecture-rules.json + re-arch-baseline.json
ci/ CI job snippet
adr/0001-target-architecture.md
review-checklist.md
And .re-arch/guardrails.json listing rules and files (schema below).
Based on references/agent-rules.md. Concrete and short: where each kind of code goes (a table: "HTTP entry point -> src/app/api/<domain>/route.ts, thin, calls the domain service"), what is forbidden (with the reason in one clause), naming, one reference implementation per pattern by file path (the cleanest existing example, or the one created in plan phase 1), and the command to run before finishing. Agents follow examples more than prose: point to files.
AGENTS.md at the repo root is read by most agents (Codex, Cursor, Copilot, Gemini, Claude Code through an @AGENTS.md line in CLAUDE.md). Nested AGENTS.md files apply to their folder and the closest one wins: when the options give a domain its own style (clean architecture for orders, plain layering elsewhere), put the domain-specific rules in src/<domain>/AGENTS.md instead of conditionals in the root file. If the repo already has these files, produce a section to merge, never a replacement.
skills/<project>-architecture/SKILL.md, installed by the team in .claude/skills/ (or the agent's equivalent) so any feature request triggers it: decision table for placing new code, step-by-step recipe for adding a use case in the target style, the checklist to run before proposing a change, links to the reference implementations. Description pushy enough to trigger on any feature work in the repo.
For the detected ecosystems, from references/fitness-functions.md: native tool config and/or the generic checker. The generic checker works for every supported language and is the default for C/C++:
scripts/check_architecture.py, scan.py, precise.py, di.py, insights.py, ts_resolve.js, php_refs.php into tools/re-arch/;architecture-rules.json (schema at the top of the script). A file belongs to the first layer whose globs match (specific layers first); a layer absent from allow may import anything (list every layer, [] for "nothing outside itself"); forbid_patterns covers rules that are not imports (framework helpers like auth(), request(), process.env, static facades); why gives the reason shown to humans and agents, per layer or rule kind;check_architecture.py architecture-rules.json --baseline-write re-arch-baseline.json once, then CI runs --baseline re-arch-baseline.json. Existing violations are tolerated, every new one fails from day one, fixed ones leave the baseline with --baseline-update (it only shrinks). A warn-only period lets new debt pile up unnoticed. Native tools have the same mechanism (ArchUnit FreezingArchRule, deptrac baseline, dependency-cruiser --ignore-known): use it.Test what you write:
guardrails.json that the native config was not executed, with the command the team should run first;CI catches violations after the push; a hook catches them in the agent's own turn, while it still has the context to fix them. For Claude Code, write hooks/claude-settings.json to merge into .claude/settings.json:
{
"hooks": {
"Stop": [{"hooks": [{"type": "command", "command": "python3 \"$CLAUDE_PROJECT_DIR/tools/re-arch/check_architecture.py\" \"$CLAUDE_PROJECT_DIR/tools/re-arch/architecture-rules.json\" --root \"$CLAUDE_PROJECT_DIR\" --baseline \"$CLAUDE_PROJECT_DIR/tools/re-arch/re-arch-baseline.json\" --changed-only --hook"}]}]
}
}
--hook prints the violations in an agent-oriented format on stderr and exits 2, which sends Claude back to fix them; on a second Stop in a row (stop_hook_active) it reports without blocking, so the agent cannot loop. For large repositories where the scan takes more than a few seconds, keep it on Stop only (not PostToolUse). For other agents, check their current hook documentation; when unsure, put the same command in AGENTS.md as the last step before finishing, and say in README.md that it is an instruction, not an enforced hook.
The job that runs the checks with the baseline (GitHub Actions, GitLab CI or what the repo uses; follow existing CI config).
adr/0001-target-architecture.md using references/adr-template.md: context, decision drivers (the quality scenarios of options.json), considered options (including rejected styles), decision outcome, consequences, and Confirmation: how compliance is checked, naming the rule ids of the fitness functions. Status proposed if decision.by is assumed, accepted if the team chose.
review-checklist.md: 8 to 12 questions for human code review in the target architecture, derived from the findings (each item prevents a finding from coming back), including how to review AI-generated changes.
Copy .re-arch/architecture.md (Mermaid domain map and context view written by re-arch-report) to docs/architecture.md in the plan, so the diagram lives in the repository and is refreshed at each audit.
If .re-arch/okf/ exists (or once re-arch-report has run), add to README.md the step "copy .re-arch/okf/ to docs/architecture/okf/" and point to it from the root AGENTS.md ("architecture knowledge: docs/architecture/okf/index.md, start with system.md and the domain you are changing"): agents get the domain map, the rules with their reason and the intended oddities as small linked files instead of a long report. Re-copy it after each re-audit (its log.md carries the history). It is safe to commit: to_okf.py leaves out authors, the pitch and security findings.
.re-arch/guardrails.json{
"target": "O2",
"adoption": "frozen baseline (re-arch-baseline.json), new violations fail from day one",
"rules": [{"id": "R1", "rule": "Domain code never imports Prisma or Next.js", "prevents": ["F1"], // same ids as plan.json rules_needed and the rules file "enforced_by": "dependency-cruiser rule domain-is-pure",
"mode": "baseline, must reach 0 at end of P2", "current_violations": 14, "tested": "native tool run"}],
"hooks": [{"agent": "Claude Code", "event": "Stop", "file": "guardrails/hooks/claude-settings.json"}],
"files": [{"path": "guardrails/AGENTS.md", "purpose": "Architecture rules for AI coding agents"}]
}
tested: native tool run, generic checker run, fixture only, not run (say why).
prevents); a purely preventive rule protecting the target structure has prevents: [] and a one-line reason.guardrails.json with enforced_by: "ci step <name>".src/modules/orders/pricing.ts" works better than an abstract principle.why in the rules file): agents and humans apply rules better when they know what they protect, and are less tempted to silence them..re-arch/guardrails/, with instructions for where each file goes.List the produced files with one line each, the number of current violations per rule, and the adoption order (baseline, CI job, hook, AGENTS.md).
references/adr-template.md (opens in a new tab)references/agent-rules.md (opens in a new tab)references/fitness-functions.md (opens in a new tab)scripts/check_architecture.py (opens in a new tab)scripts/di.py (opens in a new tab)scripts/insights.py (opens in a new tab)scripts/php_refs.php (opens in a new tab)scripts/precise.py (opens in a new tab)scripts/scan.py (opens in a new tab)scripts/ts_resolve.js (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
10 skills in this plugin
/re-arch-academyProduces training material to upskill a development team on the architecture and practices of a refactoring - a learning path ordered by the refactoring plan, modules anchored in the team's own code (before/after taken from their repository, katas extracted from real files, exercises, review checklists), curated references, for juniors and seniors. Use when a team must learn clean architecture, hexagonal, DDD, layering, testing legacy code or refactoring techniques, when a tech lead wants onboarding or workshop material about their codebase's target architecture, when developers who vibe-code need to learn craftsmanship basics, or as the training step of an architecture audit. Part of the re-arch suite; reads .re-arch/findings.json, options.json and plan.json./re-arch-auditUse this skill whenever someone questions the overall structure or health of an existing codebase and wants a verdict and a way forward, not a single code fix. This covers "is our repo/workspace/solution well structured?", layer or dependency leaks (domain code depending on the DB or framework), and projects, crates or modules nobody can untangle. It also covers an inherited legacy monolith or a vibe-coded/AI-generated app that is getting hard to change, rewrite vs incremental cleanup, tech debt assessment, refactoring roadmaps, and justifying the investment to a CTO, management or board. Also use it for team architecture rules and re-audits. Produces an evidence-based audit (domain map, weaknesses with file references, sized options from light fixes to modular monolith, hexagonal or CQRS, phased plan, management pitch, CI and AI guardrails, HTML report). JS/TS, PHP/Laravel/Symfony, .NET, Java/Kotlin, C/C++, Go, Rust. Not for one PR review, one-function refactor, security audit or cloud diagram.npx claudepluginhub gregorybabonaux/re-arch --plugin re-archOther plugins' skills for the same job