Skip to content

CONCEPT Cited by 1 source

Source code as agent feedback loop

Definition

Source code as agent feedback loop is the observation that merged source code becomes an LLM-based coding agent's implicit long-term memory, even across conversations that share no explicit context. Once a corrected pattern is merged to mainline, future agent sessions read the current state of the repo, see the corrected pattern, and reproduce it — without any memory transfer, dedicated AGENTS.md / CONTEXT.md file, or fine-tuning.

Canonical framing

From Anthony Shew's 2026-04-21 Turborepo post verbatim:

"The most interesting pattern I noticed during this phase was how the codebase itself served as the agent's strongest feedback mechanism. I'd point out a performance issue in code the agent was working on. We'd fix it together. Then I'd ask, 'Do you see anywhere else where we can improve in the same way?' The agent would find more instances of the same pattern across the codebase. Depending on the size of the changes, I would either add the change to the PR or write it down to do later. In places where the existing code had a sloppy pattern, the agent would write new code in the same style. Once I corrected one instance, the agent followed the correction going forward. In future conversations, without any memory or context carrying across chats, the agent would see the merged improvements in the source and stop reproducing the old patterns. Over time, I noticed the agent spontaneously writing tests when I wasn't expecting it to. I saw it creating abstractions that matched what I would have done, which wasn't happening before. I would revisit a place in the codebase where the agent had previously been ineffective, and, with no changes to model or harness, it would produce better code outputs. It turns out your own source code is the best reinforcement learning out there."

Mechanism

The agent's prompt construction (whether by Cursor, Claude Code, Aider, Codex CLI, or another harness) typically includes some combination of:

  1. The current state of files being edited.
  2. Files referenced from the conversation.
  3. Search / grep results over the codebase.
  4. In some harnesses, retrieved chunks from an index.

All of these expose the agent to the current state of the code. If an older session introduced a poor pattern and a follow-up PR corrected it, the follow-up's state of the code is what the next session's prompt sees. The agent implicitly learns "this is how things are done in this codebase" from the most recent examples.

The effect is emergent from retrieval mechanics, not from any explicit memory channel.

Three observable behaviours

  1. Pattern propagation — an agent asked "can we apply this fix anywhere else?" finds other instances of the pattern across the codebase.
  2. Cross-session style consistency — corrections adopted in one session show up in new sessions without being mentioned.
  3. Capability uplift over time — areas of the codebase where the agent previously produced worse output produce better output after the codebase's quality improves, with no model or harness change.

Implications

  • The codebase is first-class agent infrastructure. Polluted codebases train agents to write polluted code; clean codebases train agents to write clean code.
  • Fixing one instance of an anti-pattern has compound returns. The next N agent-assisted edits in that area inherit the corrected pattern.
  • Legacy technical debt has an amplified cost in an agent-assisted-engineering world. Agents that read legacy patterns and extend them re-encode the debt into new code.
  • Explicit context files are still useful (see patterns/precomputed-agent-context-files for Figma's CONTEXT.md) but they are complementary to the implicit memory in the code itself, not a substitute.

Distinction from explicit agent context

Implicit (source code) Explicit (CONTEXT.md / AGENTS.md)
Freshness Always current Can drift (concepts/context-file-freshness)
Scope Whole codebase What authors wrote down
Maintenance cost Zero (side effect of normal PRs) Explicit; easy to forget to update
Granularity File / function level Arbitrary; can be structural
Discoverability by agent Retrieval / grep mechanics Explicit file read

Both belong; the post's contribution is making the implicit channel named.

  • patterns/in-code-annotation-as-llm-guidance — Shopify's 2025-09-12 React-Native-migration-skills post canonicalises inline code comments as LLM guidance in the same codebase. Inline comments are a hybrid between implicit-source-code and explicit- context-file: they're in the code the agent reads but explicit in the author's intent to guide agent behaviour.
  • concepts/context-engineering — broader discipline of shaping what the agent sees; source code as feedback loop is the passive version.
  • concepts/encoded-domain-expertise — Meta-corpus concept; encoding invariants into the artefacts the agent consumes.

Limits

  • Requires the codebase to be mostly clean. If the dominant pattern in a codebase is wrong, the agent's implicit feedback reinforces the wrong pattern.
  • Per-session overrides aren't persistent. Telling the agent in one session "we should use pattern X from now on" doesn't persist unless a PR actually lands introducing pattern X.
  • Requires the agent to read the right files. Harnesses with no symbol-index / poor retrieval may miss the corrected examples and default to the model's pretraining priors.
  • Doesn't substitute for code review. The agent reproduces what's in the codebase — including subtly wrong patterns that happen to compile. Human review is still load-bearing.

Seen in

Last updated · 476 distilled / 1,218 read