Talk to Your Agent About the Structure

You do not need to know your codebase’s architecture to improve it. Maybe an agent wrote most of the code, maybe you inherited it — either way, with the Claude Code plugin installed, the agent can look the structure up instead of guessing it from a handful of files.

This guide is a set of questions to ask, in the order that works best: first understand, then find the problems, then fix one at a time, then keep it clean. Every prompt works as written — copy it into a session in your project.

Start Without Knowing Anything

Ask in plain language. The agent queries TangleGuard for the real components and dependencies, so you do not have to use the right terms to get a correct answer.

Explain how this codebase is organised, as if I have never seen it.
What are the main parts and what does each one do?

A good answer names the parts (TangleGuard calls them packages and modules), says roughly how big each is, and describes which part uses which. If the answer is a list of files the agent happened to read, ask it to check the architecture with TangleGuard.

When a word is unfamiliar, ask. The agent explains it with your own code as the example:

What is a layer? Which layers does this codebase have, if any?

See It Yourself

Text only goes so far. Ask for the graph and the agent writes an interactive page you open in your browser — nothing is uploaded.

Show me the dependency graph of this codebase.

Use it to check the agent’s explanation against what you see. If one part has arrows going to almost everything, that is worth a question:

Why does so much depend on this package? Is that a problem?

Find the Problems

Two kinds of problems are worth asking about first.

A circular dependency is a group of parts that all depend on each other, directly or through a detour. You cannot change, test or understand one without the others — and agents get lost in them just as people do.

Are there circular dependencies in this codebase?
Explain each one in a sentence.

A rule violation is a dependency your architecture does not allow — for example shared code that imports from one specific feature. These only exist once rules are defined; see the last section for that.

A long list of findings is not a plan. Ask for a ranking, and for the reasoning behind it:

Which of these matters most, and why? Which ones can I ignore for now?

Decide Before Anything Changes

Before you agree to a fix, ask what it costs and what it touches. TangleGuard ranks which dependency in a cycle is the cheapest to remove and knows what else relies on a component — the agent can give you both as facts.

For the most important cycle: which dependency is the cheapest to cut?
Show me the imports that cause it, and what else would be affected.
Do not change any code yet.

The last line matters. Without it, many agents start editing right away, and you lose the chance to say no.

Fix One Thing, Then Verify

Ask for one fix per request. A small change is easy to review and easy to undo; five tangles fixed in one go is neither.

Break that cycle with the smallest change that works.
Afterwards, check that the cycle is gone and that no new one appeared.

Asking for the check is not distrust — it is the difference between “I refactored it” and a result TangleGuard confirmed. See Eliminate Tangles for what happens underneath.

Keep It That Way

Structure erodes one reasonable-looking change at a time. Two habits prevent most of it.

Ask where new code belongs before it is written:

I want to add CSV export. Where does that code belong in this structure,
and which existing parts should it be allowed to use?

And ask what a session changed before you commit:

Show me what this session changed structurally.

The agent shows TangleGuard’s output as it is: new dependencies between parts, added and removed components. A new dependency you did not expect is the moment to ask “why was that needed?” — see Review Structural Changes.

Habits That Get Better Results

  • Ask for evidence. “Show me the file and line” turns a claim into something you can check. TangleGuard has the exact import behind every dependency.
  • Ask why, not only what. “Why is this a problem?” gives you the judgement you need for the next decision.
  • Separate looking from changing. Understand first, with “do not change any code yet”. Change second.
  • Keep requests small. One cycle, one moved file, one new feature. Verify, commit, continue.
  • Ask about the structure, not the files. “What depends on this?” has an exact answer. “Read through the code and tell me what you think” does not.

Go Further

Once you know what your structure is, you can decide what it should be. With a target architecture — layers, and rules for which layer may use which — the agent is checked against it on every change, and violations become a concrete to-do list.

How far is this codebase from a layered architecture?
Propose layers and show me what would violate them.