Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…

Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

A developer typing on a laptop with code on screen, surrounded by AI agent icons and branching diagrams illustrating…
Open SourceScore: 82

Grounded Code: 10 principles to cut AI agent re-derivation cost

Grounded Code final article proposes 10 principles across 3 clusters to reduce AI coding agent re-derivation cost, with one audit correction: a 3,110-line orchestrator file.

·2d ago·5 min read··9 views·AI-Generated·Report error
Share:
Source: dev.tovia devto_claudecode, @hasantoxrCorroborated
What are the 10 principles of Grounded Code for reducing AI agent re-derivation cost?

The Grounded Code series final article proposes 10 principles across 3 clusters (locality, contracts, quarantine) to reduce AI coding agent re-derivation cost. Key rules: co-locate by feature, spec before code, types carry contracts, quarantine exceptions in dedicated files.

TL;DR

10 principles in 3 clusters: locality, contracts, quarantine · Co-locate by feature, not by layer for agent findability · Types carry contracts; prose docs do not

The Grounded Code series final article, published on dev.to by jucelinux, proposes 10 principles across 3 clusters to reduce AI coding agent re-derivation cost. The clusters—locality, contracts, quarantine—map directly to the three axes where agents pay the highest cognitive overhead.

Key facts

  • 10 principles across 3 clusters: locality, contracts, quarantine
  • Files under ~300 lines for agent-modifiable code (soft limit)
  • One codebase had a 3,110-line orchestrator file
  • Glob src/feature/feature.* returns all three files per feature
  • Types carry contracts; prose docs do not

The unique take: codebases designed for agentic reading

The Grounded Code series, building on five prior articles covering cost, mechanism, patterns to drop, artifact, and workflow, culminates in a set of 10 principles that treat the AI coding agent as the primary reader. The central insight: when an agent re-derives context, it's usually because (1) the thing it needs isn't where it expected, (2) the contract it needs to honor isn't visible from the file it's reading, or (3) an exception to a pattern is invisible until it bites. These principles remove cost on each axis.

Locality (1 to 4)

1. Co-locate by feature, not by layer. Every file related to one feature lives in one directory. The agent finds everything about a feature with a single glob. The opposite—layered layout (src/controllers/payment.ts, src/services/payment.ts, src/repositories/payment.ts)—forces the agent to grep three directories and reconstruct the feature mentally from fragments. Only top-level layers that survive are bootstrap/, lib/, config/, possibly vendor/.

Cover image for The ten principles: locality, contracts, quarantine

2. The triplet per feature: implementation, test, spec. Every feature carries three files with parallel names: <feature>.<ext> (implementation), <feature>.test.<ext> (tests as specifications), and <feature>.spec.md (markdown contract with frontmatter). The glob src/<feature>/<feature>.* returns all three. The three files reference each other: the spec's verification block names test commands, test names match invariants in the spec, and exported names match the spec's public_api field.

3. Imports use full paths with explicit extensions. Path aliases like @utils/foo cost the agent a resolution hop via tsconfig.json. Full relative paths like ../utils/foo.ts let the agent navigate immediately. One allowed exception: workspace package boundaries in a monorepo (@org/shared-types).

4. Files under roughly 300 lines for what the agent will modify. A soft limit—above 300 lines, the agent reads in slices and loses context. The audit corrected the author: a 3,110-line orchestrator file with an explicit defense in AGENTS.md showed that splitting would cost more in cross-file inference than the length costs in slicing. Orchestrators, generated code, large data tables, exhaustive switches can be longer, but the choice must be deliberate and named.

Contracts (5 to 7)

5. Spec before code (the five-step loop). For every non-trivial change, the spec gets written or updated first. Without a spec, the agent's implicit understanding lives only in prompt history, which doesn't survive compaction or session boundaries. With a spec, the agent re-grounds in seconds.

6. Types carry contracts; prose docs do not. Push invariants into the type system: brand types, discriminated unions, exhaustive switches with never checks. A file that violates a type-encoded invariant fails to compile; a file that violates a prose-encoded invariant passes silently. The agent reads the type and knows the contract without having to remember to read a docstring.

7. Tests encode and enforce invariants. Test names should read as specifications of behavior, not descriptions of which function is being tested. Tests serve as executable documentation that agents can trust without re-derivation.

Quarantine (8 to 10)

8. Exceptions to patterns live in dedicated files. When a rule has an exception (e.g., a file that must be longer than 300 lines), document it explicitly in AGENTS.md or CLAUDE.md. This prevents the agent from silently assuming the exception applies everywhere.

9. Side effects are isolated. Bootstrap code, configuration loading, and other unavoidable side effects live in dedicated directories (bootstrap/, config/). The agent can safely ignore these unless it's specifically working on initialization.

10. Generated code is separated. Files that are auto-generated (e.g., from OpenAPI specs, database schemas) live in a generated/ directory. The agent knows not to modify them and can regenerate when the source changes.

The audit correction

The author initially framed the 300-line rule as hard. Triangulation across three coding-agent codebases showed one codebase violating it deliberately: a 3,110-line orchestrator file with an explicit defense in its AGENTS.md. The defense: this is an orchestrator meant to be read top to bottom, and splitting would cost more in cross-file inference than the length costs in slicing. The rule survives as a soft preference for feature files, with the requirement that exceptions be named in a configuration file the agent reads.

What to watch

Watch for the Grounded Code series to be referenced in AI coding agent tooling documentation (Cursor, Copilot, Codex) as a recommended pattern for agent-optimized codebases. If major AI coding assistants adopt these principles as default project templates, the pattern could become an industry standard within 12 months.


Source: gentic.news · · author= · citation.json

AI-assisted reporting. Generated by gentic.news from multiple verified sources, fact-checked against the Living Graph of 4,300+ entities. Edited by Ala SMITH.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

The Grounded Code series represents a rare attempt to formalize codebase design for AI agent consumption rather than human-only reading. The key insight—that re-derivation cost clusters around locality, contracts, and quarantine—maps cleanly onto the failure modes observed in production AI coding workflows. The audit correction (allowing a 3,110-line orchestrator) is particularly valuable: it acknowledges that blanket rules fail at scale, and that explicit configuration files like AGENTS.md serve as the escape hatch. What's missing from the series is quantitative validation. The principles are argued from first principles and anecdotal evidence from three codebases. A controlled study measuring agent task completion time, accuracy, and re-derivation frequency before and after adopting these principles would significantly strengthen the claims. The series also assumes a TypeScript/JavaScript stack; portability to Python, Go, or Rust codebases remains unaddressed. Compared to existing patterns like Domain-Driven Design or Clean Architecture, Grounded Code is lighter-weight and more explicitly agent-centric. It sacrifices layer separation for feature co-location, which may surprise developers trained on layered architectures. The trade-off is worth it for agent-heavy workflows, but may create friction in teams that rely on human code review across layers.

Mentioned in this article

Enjoyed this article?
Share:

AI Toolslive

Five one-click lenses on this article. Cached for 24h.

Pick a tool above to generate an instant lens on this article.

Related Articles

From the lab

The framework underneath this story

Every article on this site sits on top of one engine and one framework — both built by the lab.

More in Open Source

View all