Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Agent Skill

Improve codebase architecture (Matt Pocock)

Finds shallow modules worth deepening, often in the parts of the repo that change most, draws them in an HTML report, then questions you on the one you pick.

name: improve-codebase-architectureBy Matt PocockChecked
View source on GitHub
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark

Install

Commands are pinned to commit d653911, the version we read, wherever the install method supports it.

npx skills

Terminal
npx skills add mattpocock/skills@d65391149dbb5fe76478e76fa8d5122b2aa5a70e --skill improve-codebase-architecture --skill codebase-design --skill grilling --skill domain-modeling -a claude-code

Copies the four skills into .claude/skills/ in this project, pinned to the reviewed commit.

Plugin marketplace

Claude Code prompt
/plugin install mattpocock-skills@claude-plugins-official

Run inside Claude Code. Installs the whole mattpocock-skills plugin, companions included, from its default branch, not the pinned commit; the official marketplace is available by default.

What it does

You start it yourself, usually as /improve-codebase-architecture; it never fires on its own. If you do not name an area, the agent reads a stretch of git log to find the files that keep changing, reads GLOSSARY.md and any ADRs in docs/adr/, then hands the walk-through to a sub-agent with a fresh context. That sub-agent looks for “shallow” modules, where the interface is nearly as complex as the code behind it, and applies a deletion test: would removing this module concentrate complexity or just move it?

The candidates come back as a single HTML file in your temp directory, one card per idea with the files involved, the problem, the change, before and after diagrams and a strength badge (Strong, Worth exploring, Speculative). The agent opens it in your browser and asks which one to explore. From there it switches to a question-and-answer session through the grilling skill, adding terms to GLOSSARY.md as names settle and offering an ADR when you reject a candidate for a reason the next review should know about.

When to use it

On a codebase you will keep working in, when changes have started to feel expensive: a concept you have to chase through six small files, wrappers that exist only so something can be tested, a module whose tests mock half the world. It suits a team that already keeps a glossary or ADRs, because the skill reads both and will not re-argue a decision an ADR has already settled unless the friction is real. Compared with a plain “how should I refactor this?”, you get a ranked shortlist with pictures before any code changes, and a written trail (glossary entries, ADRs) after.

When to skip it

When you need the refactor done today: the skill deliberately stops at “which of these would you like to explore?” and proposes no interfaces until you have been questioned. Skip it on a repository with little history or a throwaway prototype, where the hot-spot search has nothing to go on. And if your team does not want new GLOSSARY.md and ADR files appearing in the repo, say so up front or use brainstorming instead.

Try it

/improve-codebase-architecture Focus on the billing code under
src/billing/. Invoice generation and the Stripe webhook handler keep
breaking together and the tests mock everything. Show me the
candidates first.

What it can touch

Bundles scripts
No
Pre-approved tools
None declared
Needs
The companion skills codebase-design, grilling and domain-modeling from the same repository; A browser to open the HTML report, with internet access for the Tailwind and Mermaid CDNs
Client-specific fields
disable-model-invocation

claude.ai and the Claude API reject uploads that use fields outside the open spec or names containing "claude" or "anthropic", so this skill needs editing before you upload it there.

Its instructions steer what your agent does, and it may have changed since the commit we read. How to check a skill.

  • Your repository, read-only at first: git log, the source tree, GLOSSARY.md and ADRs. A sub-agent does the walk, so expect a long, token-heavy first pass on a large repo.
  • A file outside the repo: the HTML report goes to $TMPDIR (or /tmp, or %TEMP%), and the agent runs xdg-open, open or start to show it. The report loads Tailwind and Mermaid from public CDNs when you open it, and initialises Mermaid with securityLevel: "loose"; it contains only diagrams the agent wrote from your code.
  • Files in the repo, during the conversation: it creates or edits GLOSSARY.md and, if you agree, writes ADRs. It does not refactor code in this skill.
  • No scripts, no allowed-tools. disable-model-invocation is a Claude Code field outside the open spec, so remove it before uploading anywhere that rejects unknown keys.

At commit d653911 the SKILL.md is 71 lines long. Alongside it:

  • HTML-REPORT.md (123 lines): the report scaffold, five diagram patterns (Mermaid graphs, hand-drawn boxes, cross-sections, “mass” diagrams, collapsed call graphs), style rules and a fixed vocabulary.
  • agents/ (1 entry): openai.yaml, Codex display metadata that also turns off implicit invocation.

The vocabulary itself (module, interface, depth, seam, adapter, leverage, locality) lives in the separate codebase-design skill, which this one calls by name. So do grilling and domain-modeling. Installed alone, the skill has nothing to call at those steps, which is why the install commands above pull in all four.

Alternatives

Grill me from the same author runs the questioning step on its own, for any plan, with no codebase scan. Brainstorming is the model-invoked option for designing something new rather than reshaping what exists. Once a direction is agreed, Documentation and ADRs records the decision in whatever ADR format your project already uses.

SKILL.md

The file exactly as published at the reviewed commit, reproduced under its MIT licence.

skills/engineering/improve-codebase-architecture/SKILL.md
---
name: improve-codebase-architecture
description: Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
disable-model-invocation: true
---

# Improve Codebase Architecture

Surface architectural friction and propose **deepening opportunities**: refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.

This command is _informed_ by the project's domain model and built on a shared design vocabulary:

- Call the Skill tool with "codebase-design" for the architecture vocabulary (**module**, **interface**, **depth**, **seam**, **adapter**, **leverage**, **locality**) and its principles (the deletion test, "the interface is the test surface", "one adapter = hypothetical seam, two = real"). Use these terms exactly in every suggestion, and don't drift into "component," "service," "API," or "boundary."
- The domain language in `GLOSSARY.md` gives names to good seams; ADRs in `docs/adr/` record decisions this command should not re-litigate.

## Process

### 1. Explore

**Scope before you scan: YAGNI.** Deepening a module pays off by making future changes to it easier, so put extra weight on the parts of the codebase that have recently changed. Decide *where* to look before you look:

- If the user named a direction (a module, a subsystem, a pain point), take it, and skip the inference below.
- Otherwise, walk back a good stretch of the commit history (`git log --oneline`) to find the codebase's hot spots, the files and areas that keep coming up, and let those paths pull your attention first. If the changes are scattered with no clear hot spot, widen the net.

Read the project's domain glossary (`GLOSSARY.md`) and any ADRs in the area you're touching first.

Then spawn a sub-agent with a fresh context window to walk the codebase. Don't follow rigid heuristics; explore organically and note where you experience friction:

- Where does understanding one concept require bouncing between many small modules?
- Where are modules **shallow**, with an interface nearly as complex as the implementation?
- Where have pure functions been extracted just for testability, but the real bugs hide in how they're called (no **locality**)?
- Where do tightly-coupled modules leak across their seams?
- Which parts of the codebase are untested, or hard to test through their current interface?

Apply the **deletion test** to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.

### 2. Present candidates as an HTML report

Write a self-contained HTML file to the OS temp directory so nothing lands in the repo. Resolve the temp dir from `$TMPDIR`, falling back to `/tmp` (or `%TEMP%` on Windows), and write to `<tmpdir>/architecture-review-<timestamp>.html` so each run gets a fresh file. Open it for the user (`xdg-open <path>` on Linux, `open <path>` on macOS, `start <path>` on Windows) and tell them the absolute path.

The report uses **Tailwind via CDN** for layout and styling, and **Mermaid via CDN** for diagrams where a graph/flow/sequence reliably communicates the structure. Mix Mermaid with hand-crafted CSS/SVG visuals: use Mermaid when relationships are graph-shaped (call graphs, dependencies, sequences), and hand-built divs/SVG when you want something more editorial (mass diagrams, cross-sections, collapse animations). Each candidate gets a **before/after visualisation**. Be visual.

For each candidate, render a card with:

- **Files**: which files/modules are involved
- **Problem**: why the current architecture is causing friction
- **Solution**: plain English description of what would change
- **Benefits**: explained in terms of locality and leverage, and how tests would improve
- **Before / After diagram**: side-by-side, custom-drawn, illustrating the shallowness and the deepening
- **Recommendation strength**: one of `Strong`, `Worth exploring`, `Speculative`, rendered as a badge

End the report with a **Top recommendation** section: which candidate you'd tackle first and why.

**Use GLOSSARY.md vocabulary for the domain, and the `/codebase-design` vocabulary for the architecture.** If `GLOSSARY.md` defines "Order," talk about "the Order intake module," not "the FooBarHandler," and not "the Order service."

**ADR conflicts**: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly in the card (e.g. a warning callout: _"contradicts ADR-0007, but worth reopening because…"_). Don't list every theoretical refactor an ADR forbids.

See [HTML-REPORT.md](HTML-REPORT.md) for the full HTML scaffold, diagram patterns, and styling guidance.

Do NOT propose interfaces yet. After the file is written, ask the user: "Which of these would you like to explore?"

### 3. Grilling loop

Once the user picks a candidate, call the Skill tool with "grilling" to walk the decision tree with them: constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.

Side effects happen inline as decisions crystallize; call the Skill tool with "domain-modeling" to keep the domain model current as you go:

- **Naming a deepened module after a concept not in `GLOSSARY.md`?** Add the term to `GLOSSARY.md`. Create the file lazily if it doesn't exist.
- **Sharpening a fuzzy term during the conversation?** Update `GLOSSARY.md` right there.
- **User rejects the candidate with a load-bearing reason?** Offer an ADR, framed as: _"Want me to record this as an ADR so future architecture reviews don't re-suggest it?"_ Only offer when the reason would actually be needed by a future explorer to avoid re-suggesting the same thing; skip ephemeral reasons ("not worth it right now") and self-evident ones.
- **Want to explore alternative interfaces for the deepened module?** Call the Skill tool with "codebase-design" and use its design-it-twice parallel sub-agent pattern.
  • Grill me

    A user-invoked interview that questions you in rounds until a loose idea becomes a plan you can commit to. Needs the companion grilling skill.

    Productivity and thinking toolsMatt PocockChecked at abeeaf9

  • Brainstorming

    Makes the agent hold a design conversation before building anything: what is known, what to ask, a play-back of the idea and a short written design.

    Jesse Vincent (obra)Bundles scriptsChecked at 22f0b46

  • Documentation and ADRs (Addy Osmani)

    Writes architecture decision records in your project's existing format, documents why rather than what, and uses git history to tell whether a doc is stale.

    Writing and communicationChecked at e997ac5