Skip to content

Architecture analysis and system design with Claude Code

Claude Code supports architecture work in plan mode, where it reads the codebase but cannot edit files until a plan is approved. It maps dependencies, compares design options against patterns the code already uses, drafts architecture decision records (ADRs), and plans phased migrations. Its output is a hypothesis that a dependency tool and a citation audit confirm.

Your team has a week to decide whether to split the order service out of the monolith. There are twelve Slack threads and no written proposal, and nobody has mapped what actually calls what. This page is for the developer or tech lead who owns that decision and needs a grounded proposal by Friday, one whose claims can be checked without reading 400 files.

What you’ll walk away with from architecture analysis in Claude Code

Section titled “What you’ll walk away with from architecture analysis in Claude Code”
  • A session setup (plan mode, effort level, model) that keeps architecture analysis read-only and thorough.
  • Six copy-paste prompts: map the system, reconcile the map with a dependency tool, compare options, write the ADR, audit the evidence, and plan the migration.
  • A verification table that tells you which check proves each kind of claim and who signs off.
  • A way to turn the decision into a CI rule, so later agent sessions cannot quietly erode it.

How do you set up a Claude Code session for architecture work?

Section titled “How do you set up a Claude Code session for architecture work?”

Architecture analysis should change nothing until a person has agreed with it. Plan mode enforces that: Claude reads files and runs only approved commands, and edits stay blocked until you accept a plan.

  1. Start the session in plan mode at a higher effort level. In your terminal, run:

    Terminal window
    claude --permission-mode plan --effort high

    In a session that is already running, press Shift+Tab to cycle permission modes until plan mode is active, or type /plan followed by the question. --effort accepts low, medium, high, xhigh and max (checked against claude --help, v2.1.283).

  2. Keep the default model and tune effort first. Claude Opus 5.5 is the Claude Code default on every paid plan from v2.1.280 (the latest release channel), and it runs at medium effort by default. For a trade-off analysis, raise effort with /effort high or /effort xhigh before you change model. Switch to Claude Fable 5.1 (/model fable) only for the longest, hardest analyses, and only when your own comparison says Opus at higher effort falls short. Versions and prices live on the models hub; deep reasoning and effort levels explains the effort trade-off.

  3. Scope the question. Name the directories, services or flows that matter. An unscoped “analyse our architecture” on a large repository fills the context window with files that do not bear on the decision. For an unfamiliar codebase, run the codebase analysis workflow first; this page assumes you already know your way around.

  4. Put the tool-checkable facts on disk before you ask for opinions. The next section shows how.

Map the current architecture with evidence you can check

Section titled “Map the current architecture with evidence you can check”

Ask for a map in which every claim cites a file and line. Citations are what make the map auditable: a claim without one is a guess.

A language model counts imports badly and misses dynamic wiring, so treat the dependency part of that map as a draft. A static analysis tool computes the same graph deterministically. For a JavaScript or TypeScript codebase, run these in your terminal (checked on 2026-09-26 with dependency-cruiser 18.4.0 and madge 8.0.0):

Terminal window
mkdir -p docs/architecture
# Afferent (Ca) and efferent (Ce) coupling and instability per module and folder
npx dependency-cruiser@18.4.0 src --no-config --output-type metrics > docs/architecture/metrics.txt
# Circular dependencies
npx madge@8.0.0 --circular src > docs/architecture/cycles.txt
# The whole graph as a Mermaid flowchart
npx dependency-cruiser@18.4.0 src --no-config --output-type mermaid -f docs/architecture/deps.mmd

For Python, import-linter plays the same role (pip install import-linter, then lint-imports against the contracts in your config; checked at 2.15 on PyPI); the fitness functions guide has configurations for TypeScript, Python and Java. Then make Claude reconcile its map with the tool output:

Every disagreement between the two is either a runtime link, which you now know about, or an error in the map, which you have removed. That list is worth more than either input alone. When the corrected map reads right, approve saving it (or press Shift+Tab to leave plan mode) and have Claude write it to docs/architecture/current.md; the audit later on this page reads it from there.

Compare design options against your own code

Section titled “Compare design options against your own code”

A generic comparison of microservices, a modular monolith and event-driven designs is available anywhere. The useful comparison measures each option against your call graph, your team, and the patterns the codebase already demonstrates. Give Claude the constraints it cannot see.

The last instruction matters most. The fact that would change the recommendation is the thing to verify before the meeting, and it is usually cheaper to check than the whole analysis. Explore is one of Claude Code’s built-in subagents; to give a subagent your own instructions or tool limits, see custom subagents.

Do not use agent effort estimates as commitments. The agent sees the code that changes, not your review queue, your deploy windows or the edge cases that surface in staging. Ask for the list of changes and size it with the team.

Record the decision as an ADR an agent can follow

Section titled “Record the decision as an ADR an agent can follow”

An ADR written for humans explains why. An ADR that agents follow also states the rule in a form a tool can check, and names the check. Write it after the team has decided, not before; the ADR records a human decision, it does not make one. The canonical ADR format and the machine-checkable constraint pattern are in architecture decisions agents can follow.

Leave plan mode before you send this prompt, or approve the plan Claude proposes for it, because it writes files. The CLAUDE.md line puts the decision into every future session’s context. The dependency rule catches the sessions that ignore it.

How do you verify the analysis without reading every file?

Section titled “How do you verify the analysis without reading every file?”

Nobody should read the 400 files the agent read. You check the claims with the cheapest instrument that can prove each kind, and a named person signs off on the decision.

Claim in the outputHow it is checkedWho signs off
“Module X imports Y”, cycles, coupling numbersdependency-cruiser or madge output, reconciled as shown aboveThe developer who ran the tools
“This flow goes through file F at line L”A fresh-session citation audit (prompt below)The developer, from the audit report
Runtime wiring (DI, plugins, config routing)A trace or a test that exercises the path; logs from stagingThe owner of that subsystem
“Option A is cheaper to reverse than B”The team’s own judgement, informed by the list of changesThe tech lead, in the ADR review
“The boundary holds after the change”The dependency rule failing CI on a violating importCI, on every pull request

Run the audit in a new session (claude --permission-mode plan), not in the one that wrote the documents. A session that wrote a claim tends to confirm it. Anything marked NOT SUPPORTED goes back to the authoring session, or out of the document. The ADR is merged only after the tech lead approves it in an ordinary pull request review, with the audit report attached. The general practice of accepting evidence instead of reading diffs is described in reading evidence instead of code.

With the decision recorded, ask for a plan in which every phase ships on its own and has a check that proves it worked.

Hand the approved phases to feature planning or execute them with the refactoring workflow. To keep the dependency rule ratcheting tighter as phases land, use the baseline and --ignore-known pattern from the fitness functions guide.

Architecture documents written by hand go stale. Split the document in two. The deterministic part (deps.mmd, metrics.txt, cycles.txt) is regenerated by the commands above in CI on every merge (madge 8.0.0 exits with code 1 when it finds a cycle, so the step fails the build; append || true when you only want the report), so it always matches the static import graph. The narrative part is short, written by Claude from those files, and re-audited only when the graph changes materially. To regenerate the narrative on a schedule, a Claude Code routine can open a pull request with the refreshed text for a human to approve.

A minimal GitHub Actions workflow for the deterministic part runs the same pinned commands after every merge to main and uploads the three files as a build artifact. The if: always() keeps the upload when madge fails the job on a cycle, so you still get the report that explains the failure. To keep the files in the repository instead, replace the upload step with one that commits docs/architecture/ back to the branch, and raise that job to contents: write; it runs only pinned tools on main, never an agent or pull request code.

.github/workflows/architecture-docs.yml
name: architecture-docs
on:
push:
branches: [main]
permissions:
contents: read
jobs:
graph:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
- name: Regenerate the dependency graph
run: |
mkdir -p docs/architecture
npx dependency-cruiser@18.4.0 src --no-config --output-type metrics > docs/architecture/metrics.txt
npx dependency-cruiser@18.4.0 src --no-config --output-type mermaid -f docs/architecture/deps.mmd
npx madge@8.0.0 --circular src > docs/architecture/cycles.txt
- uses: actions/upload-artifact@v7
if: always()
with:
name: architecture-docs
path: docs/architecture/*

What breaks when Claude Code analyses architecture?

Section titled “What breaks when Claude Code analyses architecture?”

The map misses runtime wiring. Static reading does not see dependency injection containers, plugin registries or config-driven routing. Recovery: point Claude at the registration code (“service registrations are in src/container.ts; resolve concrete implementations from there”) and confirm the critical paths with a test or a staging trace.

Citations point at the wrong lines or files that do not exist. Recovery: run the citation audit in a fresh session, and delete any claim that stays unsupported. If more than a few citations fail, re-run the map with a narrower scope; a map that wide was built from summaries, not from reads.

The recommendation does not fit your team. The agent favours what is technically clean and does not know that nobody has run the broker it recommends. Recovery: state team experience and operational limits in the prompt, and ask it to prefer patterns the codebase already demonstrates.

The coupling report flags everything. Every codebase has coupling. Recovery: ask for the five modules with the highest combination of instability and dependents, with one change per module that fits in a day.

The context fills up on a large repository. Answers get vaguer and early findings are forgotten. Recovery: split the analysis by subsystem, use Explore subagents so each exploration runs in its own context, and write intermediate findings to files the next step reads.

The decision erodes after the ADR merges. Later sessions, human or agent, import across the boundary because nothing stops them. Recovery: the dependency rule in CI, plus the CLAUDE.md pointer. Long-term drift and the thresholds that should lower an agent’s autonomy are covered in keeping an agent-written codebase healthy.

Where to go next after the architecture analysis

Section titled “Where to go next after the architecture analysis”

Working in another tool? The same workflow in Codex is in system design with Codex, and in Cursor in system design with Cursor Agent. The rest of this stage is in the Claude Code planning overview.