Real StoriesGuide

Context Engineering for Agentic Coding: What Goes in the Prompt and What Goes in the Codebase

The teams getting reliable results from agentic tools are not writing longer prompts. They have decided, deliberately, which context lives in the prompt and which lives in the codebase itself.

Navigaite|

Every team working with agentic coding tools eventually runs into the same problem. The agent behaves well in one session and inconsistently in the next. The same developer, working on the same codebase, gets noticeably different quality depending on how much context they happened to include that day.

The instinct is usually to write a longer prompt. That helps for exactly one session. It does nothing for the next developer who picks up similar work, or for the same developer three weeks later who has forgotten which details mattered.

The actual fix is not a longer prompt. It is deciding, deliberately, which context belongs in the prompt and which context belongs in the codebase itself, where it persists regardless of who is working or what they remember to mention.

Why this distinction matters more than it looks

A prompt is ephemeral. It exists for one session, gets whatever the developer thought to include at the time, and disappears once the task is done. If the same context is needed again next week, someone has to remember to include it again, or rediscover it the hard way.

A codebase is persistent. Anything encoded in the code itself, in its structure, its naming, its documentation, or its conventions, is available to every developer and every agent session from that point forward without anyone needing to remember to mention it.

The practical implication is straightforward. Context that will be needed repeatedly should live in the codebase. Context that is genuinely specific to a single task, and unlikely to matter again, can reasonably live in the prompt.

Most teams get this backwards. They accumulate a set of tribal knowledge about their own codebase that every senior developer holds in their head and every agent session has to be manually reminded of, because nobody has taken the time to write it down where the agent, and future developers, can actually find it.

What belongs in the codebase

Architectural intent

Why the system is structured the way it is, not just what the structure is. A folder layout communicates what exists. It does not communicate why a particular service was split out, what constraint drove a particular pattern, or what alternative was considered and rejected. This is exactly the kind of decision history that an agent has no way to infer from reading code alone, and it is exactly the kind of thing that causes an agent to make a locally reasonable change that violates a constraint nobody told it about.

A short architecture document, kept close to the code it describes rather than buried in a wiki nobody opens, closes this gap. It does not need to be long. It needs to answer the question a new developer or a fresh agent session would actually ask: why does this look like this, and what would break if it looked different.

Known failure modes

Every mature codebase has a set of edge cases that were expensive to discover the first time. A race condition in a specific integration. A third party API that behaves differently under load than its documentation suggests. A data migration that has to happen in a particular order or it corrupts state. This knowledge usually lives in the memory of whoever was on call when it happened, and nowhere else.

Encoding these directly, as comments near the relevant code or as a dedicated known issues document referenced from the code, means an agent working in that area is far less likely to reintroduce a problem the team has already paid for once. This is one of the highest value additions a team can make to a codebase working with agentic tools, because it converts a one time expensive lesson into a permanent, reusable asset.

Naming and convention rationale

Agents pattern match on existing code more than they reason from first principles. If your codebase has a consistent naming convention, an agent working in it will generally follow that convention, which is useful. If your codebase has an inconsistent convention, an agent will pick whichever pattern happens to be nearest to the code it is editing, which compounds the inconsistency rather than resolving it.

Where a convention exists for a specific reason, rather than by accident, stating that reason somewhere accessible helps an agent apply it correctly rather than following it superficially. A style guide that explains why a rule exists is more useful to an agent than one that states the rule alone, because the reason tells the agent when the rule genuinely applies and when an exception might be reasonable.

Test intent, not just test code

A test suite communicates what behaviour is protected. It rarely communicates why that behaviour matters, which makes it easy for an agent, or a developer, to modify a test to make it pass rather than understanding why it existed in the first place. Where a test protects against a specific historical failure, saying so directly, in a comment or in the test name itself, changes how it gets treated when it is next in the way of a change.

What belongs in the prompt

Task specific scope and constraints

The boundaries of what this particular piece of work should and should not touch. This is genuinely task specific and does not belong permanently in the codebase, because the next task will have different boundaries.

Done conditions for this task

What specifically needs to be true for this task to be considered complete. This is a property of the current task, not a permanent fact about the system, so the prompt is the right place for it.

Recent context not yet reflected in the codebase

If a decision was made yesterday that has not yet been documented anywhere, the prompt is the reasonable place to convey it until the documentation catches up. This should be treated as temporary. If the same piece of recent context needs to be repeated in more than two or three sessions, that is a signal it should be moved into the codebase rather than continuing to live in prompts.

Preferences that are genuinely a matter of current judgement

Not every decision needs to be permanently encoded. Some choices are close calls that reasonable developers might make differently, and stating a preference for this particular task, without elevating it to a permanent rule, is the right level of commitment.

The test for where something belongs

A useful question to ask about any piece of context: if I did not mention this, and the agent got it wrong, whose fault would that be.

If the answer is the codebase's fault, because the information needed to get it right was available nowhere except a developer's memory, that context belongs in the codebase. If the answer is genuinely nobody's fault, because this was a reasonable judgement call specific to this task that could not have been anticipated, the prompt is the right place for it.

Applying this test consistently produces a codebase that gets more agent legible over time, rather than one that depends on an ever growing prompt to compensate for what the code itself does not communicate.

What this looks like in practice

A team that has done this well tends to have a small number of artefacts, kept close to the code rather than in a separate system nobody checks. A short architecture rationale document. A known issues or failure modes log that gets updated when incidents happen rather than only during a retrospective. Consistent naming with the reasoning documented where it is not obvious.

None of this needs to be extensive. It needs to be current, accessible from where the code actually lives, and treated as a living asset that gets updated when something new is learned, not a one time documentation exercise that decays the moment it is written.

Teams that invest in this find that agent output quality improves broadly, not just for the specific tasks the documentation was written for, because the agent is drawing on persistent, reliable context rather than whatever a given developer happened to remember to include that day.

The underlying principle

Prompts are for what is true about this task. Codebases should hold what is true about this system. Confusing the two means either writing the same context repeatedly in every prompt, which is wasted effort, or omitting it and hoping the agent infers correctly, which is where quality becomes inconsistent.

The developers who get the most reliable results from agentic tooling are not the ones who write the longest prompts. They are the ones who have done the work of making their codebase itself a better source of context, so the prompt only has to carry what is genuinely specific to the task in front of them.

At Navigaite, we place AI Native contract developers who understand this distinction and bring it with them into every codebase they work in. A developer who improves how a codebase communicates its own context leaves a team better off long after the engagement ends.

See what we do

Want developers who work this way?

Every contractor we place uses AI tooling as a standard part of how they deliver. Tell us what your team needs.

Get in touch