Teaching an AI to understand a codebase without endless prompting

How a documentation scaffold stopped the constant re-prompting and got an AI coding assistant to follow a Laravel project's patterns, naming and rules.

Updated 5 min read

// experimental: AI tooling changes weekly. Treat this as a starting point.

An AI coding assistant follows a codebase’s patterns once it gets the documentation a new developer would: the architecture, the conventions, the domain terms and the rules that mustn’t break. I built a scaffold that generates that documentation from a short project brief, and it ended most of my re-prompting.

AI coding assistants such as Claude, Copilot and Cursor are now common, and the results are often mediocre.

The usual experience goes like this. You paste in some code, ask for a feature, and get back something that works: it compiles and the tests pass. But it doesn’t fit. The patterns and the naming are wrong, and it solves a problem you didn’t quite have, in a style that doesn’t match your codebase.

So you prompt again, and explain the context again:

> Actually, we use repositories here, not direct Eloquent calls.
> Actually, this needs to work with our tenant scoping.
> Actually, read the existing code first.

You do that again in every session.

I was building an enterprise Laravel application, with multi-tenancy, complex domain logic and hundreds of tests, where the architecture had to stay consistent. Every AI suggestion that ignored the project’s patterns was technical debt in waiting.

I needed something better than prompting my way through every session.


Onboarding the AI like a new developer

By default, Claude starts each conversation without your project’s history. It doesn’t know your architecture decisions or naming conventions, or that you spent three weeks getting tenant isolation right and would rather it stayed that way.

Note, October 2026: Claude Code can load project instructions from a CLAUDE.md file and keep notes between sessions, so it no longer starts every conversation completely from zero.

Partway through the project, I started treating the AI like a senior developer joining it.

When a person joins, you don’t expect them to guess how the codebase works. You give them documentation, architecture diagrams and a glossary of domain terms, and you explain the critical rules: the things that will break production if they get them wrong.

So I wrote the same for the AI:

/CLAUDE.md        # critical rules, code patterns, glossary
/PROGRESS.md      # what's built, what's blocked, what's next
/docs/features/   # specs for each feature
/docs/decisions/  # architecture decision records

Then a bigger problem appeared. I’d need this for every project, and writing 14 connected documentation files from scratch each time wasn’t realistic.

So I wrote a scaffold, a template that generates all of it from a short project brief, and called it PROJECT_SCAFFOLD.


What PROJECT_SCAFFOLD does

The scaffold is a single Markdown file. You fill in Part 1, with your tech stack, constraints, domain context, first milestone and a glossary of terms. Then you run one command:

cat PROJECT_SCAFFOLD.md | claude -p

Claude reads your brief and writes documentation specific to the project, based on what you told it.

Out comes a complete project structure:

├── CLAUDE.md                    # master context file
├── PROGRESS.md                  # living project tracker
├── .claude/
│   └── skills/                  # reusable task patterns
└── docs/
    ├── spec/                    # data models, multi-tenancy rules
    ├── features/                # user stories, edge cases
    ├── decisions/               # architecture decision records
    ├── conventions/             # testing, security checklists
    └── troubleshooting.md       # the mistakes you're about to make

The scaffold also knows about platforms. Tell it you’re building a Shopify app, and it adds webhook HMAC verification patterns, Billing API state machine documentation and GDPR compliance checklists. For a Laravel SaaS application, it adds warnings about multi-tenancy scope leakage, rules for tenant context in queued jobs and foreign key validation patterns. The AI then knows how the project works before it writes any code.


What changed

The effect was immediate. Suggestions followed the existing patterns instead of inventing new ones, and the suggestions that worked but broke the architecture dropped off.

When Claude knows your Stock model uses a BelongsToTenant trait, it stops suggesting raw Eloquent queries that bypass tenant scoping. When it knows your API uses form request validation with specific foreign key rules, it writes code that matches.

The scaffold enforces consistency in ways that prompting can’t. A glossary means Claude uses the right terms:

# Without scaffold
"User", "Merchant", "Account", "Client"  # depending on mood

# With scaffold
"Dealer"  # every time, because it's in the glossary

Critical rules with code examples mean the same patterns appear everywhere.

The code got better and I re-prompted less. Reviewing AI suggestions took less effort, because I wasn’t constantly catching breaks in the architecture.

The AI could always do this. It needed the context first.


Where it goes next

The scaffold is a snapshot of what worked on this project with the AI tools of early 2026, and it’s still changing.

As models get better at keeping context between sessions, some of this may become unnecessary, and the documentation will change as AI agents work more on their own. A scaffold that suits a 15-phase enterprise Laravel build may also be too much for a weekend side project.

You can re-explain your architecture and catch the same mistakes in every session, or teach the AI how your project works once, at the start. The scaffold is one way to do that, and there will be others.


Better documentation

I now write better documentation for Claude than I ever wrote for colleagues, which I didn’t expect.

Every critical rule has a code example, every architectural decision has its reason written down, and every domain term has a definition. It’s the documentation I always meant to write and never got round to.

Perhaps AI forces a level of detail that people muddle through without. Or perhaps I needed a machine to make documentation feel worth the effort.

Either way, the codebase is cleaner, the AI is useful, and I’ve become a developer who writes things down.

The scaffold is on GitHub if you want to see how it works.

I’ve written more about prompt engineering and AI code generation in my AI series, and about overnight AI refactors in Ralph loop gotchas.

I use the scaffold on the Laravel and Shopify projects I take on.

Published , updated .

Related posts