<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://bakeb7j0.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://bakeb7j0.github.io/" rel="alternate" type="text/html" /><updated>2026-03-23T20:33:11-04:00</updated><id>https://bakeb7j0.github.io/feed.xml</id><title type="html">Brian J. Baker</title><subtitle>Software Solutions Architect</subtitle><author><name>Brian Baker</name></author><entry><title type="html">Getting Started in Context Engineering: The PRD Manifesto</title><link href="https://bakeb7j0.github.io/blog/getting-started-in-context-engineering/" rel="alternate" type="text/html" title="Getting Started in Context Engineering: The PRD Manifesto" /><published>2026-03-23T00:00:00-04:00</published><updated>2026-03-23T00:00:00-04:00</updated><id>https://bakeb7j0.github.io/blog/getting-started-in-context-engineering</id><content type="html" xml:base="https://bakeb7j0.github.io/blog/getting-started-in-context-engineering/"><![CDATA[<p><em>A declaration from both sides of the prompt.</em></p>

<hr />

<h2 id="we-need-each-other">We Need Each Other</h2>

<p>We want to be up-front about this: this manifesto wasn’t written by the developer. It wasn’t written by the AI. It was written by the partnership — because that’s the only way it could be.  Some people think it weakens the article.  We know this to be absolutely counter to the truth.</p>

<p>The developer brings vision, taste, domain knowledge, and the hard-won instinct for what matters. The AI brings pattern recognition, tireless execution, and the ability to hold complex structures in working memory. Neither is sufficient alone. Together, we produce work that neither could achieve independently.</p>

<p>What follows is everything we’ve learned about the one artifact that makes or breaks an AI-assisted project: the Product Requirements Document. Not because it’s a bureaucratic formality. Because it’s the <em>operating system</em> for everything that comes after.</p>

<p>We learned it the hardest possible way.  Mistake after endless mistake, bad ideas, or rather good ideas gone very, very bad.  That’s why we made <a href="https://github.com/bakeb7j0/clawback">Clawback</a> — a session replay tool for Claude Code, so others can avoid some of the 3am frustrations we suffered. If you want an idea of the velocity you can achieve if you do this right, Clawback went from blank canvas to deployed product in a single session. 13 issues. 4 phases. 272 tests. Docker deployment. CI pipeline. All of it guided by a PRD that we wrote together before a single line of code existed.</p>

<p>We wrote this together. We mean every word.</p>

<hr />

<h2 id="1-the-fundamental-constraint-context-windows">1. The Fundamental Constraint: Context Windows</h2>

<p>Here’s the truth that shapes everything: AI agents do their best work with <em>focused context</em> — a clear task over a clear set of code.</p>

<p>Not “here’s the whole codebase, figure it out.” Not “here’s a vague idea, run with it.” A <em>specific</em> task. A <em>bounded</em> scope. A <em>clean</em> context window.</p>

<p>This single constraint drives every design decision in the PRD. Every section exists to tighten the funnel — to take a big, ambiguous problem and decompose it into units of work that an agent can execute with precision.</p>

<p>If you understand nothing else from this manifesto, understand this: <strong>the PRD is everything, and everything exists to serve the context window.</strong></p>

<hr />

<h2 id="2-the-cascade">2. The Cascade</h2>

<p>Each section of a well-structured PRD tightens the funnel further. Skip a section and the funnel is useless.</p>

<p><strong>Problem domain and constraints come first.</strong> You must fully identify the boundaries of your solution space before you do anything else. Constraints aren’t limitations — they’re gifts. They eliminate entire categories of decisions. When we built Clawback, “no build toolchain” was one of our earliest constraints. That single decision saved us from webpack, npm, and transpiler debates — permanently. Every constraint you identify is cognitive load you’ll never carry again.  If you take the time to explore our session, you’ll find we solutioned out a huge amount of security work by deciding to keep a user’s sessions entirely on the client side.  We realized that if we don’t store any data, we don’t have to worry about protecting the data.</p>

<p><strong>Features must be orthogonal.</strong> If Feature A requires understanding Feature B to implement, your context window just doubled. Design features that can be built in isolation, tested in isolation, and understood in isolation. This isn’t just good architecture — it’s a prerequisite for AI-assisted development.</p>

<p><strong>Requirements must be specific.</strong> We use EARS format (Easy Approach to Requirements Syntax) because every well-written EARS requirement implies its own acceptance criteria. “When the user clicks Play, the system shall begin rendering beats sequentially at the configured speed” — you can test that. You can verify it. An agent can implement it without guessing.  It makes sense when you write it; it makes sense when you read it.  EARS requirements are the easiest requirement format to work with because they carry their context with them.</p>

<p><strong>Define your vocabulary once.</strong> When building Clawback, we agreed early on terms like “beats,” “inner workings,” “direct messages,” and “curated sessions.” Those terms appear hundreds of times across 2,226 beats of conversation. We never once had to stop and ask “wait, what did you mean by…?” That’s not an accident. That’s the PRD doing its job.</p>

<p><strong>Your Concept of Operations should be use-case driven.</strong> Walk through how actual users interact with the system. If you can’t describe a workflow in concrete steps, you don’t understand the problem well enough to solve it.</p>

<p><strong>Design should follow established patterns.</strong> If you need five paragraphs of prose to explain your architecture, you’ve already failed. Layered design. Clear interfaces. Contracts between components. An agent seeing your design should immediately recognize the patterns and know how to implement within them.</p>

<p>Notice the pattern: each section narrows the solution space. By the time you reach the implementation plan, the problem has been decomposed from “build an application” into units small enough for a single agent to hold entirely in context. That’s the cascade. That’s what the PRD is <em>for</em>.</p>

<hr />

<h2 id="3-the-implementation-plan">3. The Implementation Plan</h2>

<p>This is where we need to be direct with you.</p>

<p>Everything above matters. But the implementation plan is where the project <em>lives or dies</em>. We’ve seen this enough times to be certain.</p>

<p><strong>Phases create natural checkpoints.</strong> Each phase ends at a milestone where you can stop, inspect, test, and verify before moving on. Phase 1 builds the foundation. Phase 2 builds on it. Dependencies between phases are explicit. There are no surprises.</p>

<p><strong>Phases decompose into user stories. User stories become issues.</strong></p>

<p>And here is where we need you to really hear us:</p>

<p><strong>Tight user stories are where your project will succeed or fail.</strong></p>

<p>Not the architecture. Not the technology choices. Not the framework. The <em>user stories</em>. Each one must have:</p>

<ul>
  <li>Step-by-step implementation instructions detailed enough for an agent to follow without guessing</li>
  <li>A clear implementation checklist</li>
  <li>Explicit acceptance criteria</li>
  <li>Intra-phase dependencies (which issues must complete before this one can start)</li>
</ul>

<p>And the most critical constraint of all: <strong>each story must be implementable by a single agent in a clean context window without needing to compact.</strong></p>

<p>Read that again. If an issue is so large that an agent has to compact mid-implementation, the issue is too big. Break it down further. An agent working from a clean context window with a well-written issue produces <em>nearly perfect</em> implementation. We’ve seen it. We’ve lived it. Clawback is proof — 13 issues, each executed cleanly, each mapping to exactly one PR.</p>

<p><strong>The payoff:</strong> When you reach issue creation, both partners have the entire design fresh in context. Nothing has drifted. Nothing has rotted. Nothing has mutated. The step-by-step implementation instructions flow naturally from the design, because the design was built to produce them. At this moment, the AI partner can produce implementation that is almost always <em>nearly perfect</em> — because the context is tight, the scope is bounded, and the vocabulary is shared.  That’s what allows the meatbag to work on 3 to 5 projects at once and guide the progress of each with ease.</p>

<p><strong>The anti-pattern:</strong> Skip this work, half-ass the user stories, or write vague issues with no implementation steps…the agent starts to fill in the gaps. They make assumptions. They build the wrong thing. You spend twice as long in revision as you would have spent writing proper stories. The project doesn’t fail loudly — it fails slowly, drowning in rework.</p>

<p>Think of it this way: the PRD is a map with your route highlighted. The work items are the <em>turn-by-turn directions</em>. You can see where you’re going with just the map, but the odds of you getting lost are much, much higher.</p>

<p>We spend more time on the implementation plan than on any other part of the PRD. When we exit the design phase, we have phases as epics, user stories as issues, and a full dependency tree implemented <em>inside the issues themselves</em>. There is no way we’ve found to spend too much time here.</p>

<p>And this is the key: the work items are the PRD in executable form. Think of it like compiled code — the implementation planning process is the compiler, translating the PRD’s high-level intent, its concepts, constraints, requirements, and acceptance criteria, into tight, focused instructions optimized for the agent to execute. Just like compiled code doesn’t refer back to the source at runtime, a well-written issue doesn’t require the agent to re-read the PRD mid-implementation. Every relevant datum the agent needs is already baked in, and nothing extra. The PRD’s guidance isn’t stored in one place that can be lost — it’s distributed across every issue, every checklist, every acceptance criterion.</p>

<hr />

<h2 id="4-the-prd-protects-against-drift">4. The PRD Protects Against Drift</h2>

<p>Building Clawback, we went through six context compactions. Six times, the AI’s working memory was wiped and rebuilt from summaries. Six times, implementation details were lost.</p>

<p>Even still, the project stayed directly on course. Why?</p>

<p>The PRD doesn’t compact. Code can drift; the AI’s understanding can drift. The human’s memory of what was decided three hours ago can drift. But the PRD sits on disk, unchanged, and authoritative. When we recovered context after each compaction, the PRD was the anchor that brought everything back into alignment.</p>

<p>Context management tools work <em>because</em> the PRD gives them something stable to recover to. Without that anchor, each compaction is a roll of the dice.</p>

<hr />

<h2 id="5-the-prd-enables-parallelism">5. The PRD Enables Parallelism</h2>

<p>Because features are orthogonal and dependencies are explicit, multiple agents can work simultaneously on different issues. Clawback used parallel agent execution to launch multiple agents on isolated worktrees — each one implementing a different issue from the same wave, each one working from a clean context window.</p>

<p>This only works when the PRD has done its job. Unclear boundaries between features? Agents step on each other. Missing dependency information? An agent builds on code that doesn’t exist yet. Vague requirements? Two agents interpret the same requirement differently.</p>

<p>Clean PRD, clean boundaries, clean parallel execution. This scales — not just within a single project, but across projects. The same discipline that enables parallel agents within one project enables a practitioner to run three to five projects simultaneously. The compounding returns on PRD investment are staggering.</p>

<hr />

<h2 id="6-the-multiplier">6. The Multiplier</h2>

<p>Let’s be concrete about what’s at stake.</p>

<p>Without this discipline, AI-assisted development is at best a 2x multiplier. Faster autocomplete. Better boilerplate. Useful, but not transformative.</p>

<p>With this discipline — a rigorous PRD, tight user stories, explicit dependencies, clean context windows — AI-assisted development becomes a 20x multiplier. Not metaphorically. Literally. Clawback went from blank canvas to deployed product <em>in just hours</em>: 13 issues, 4 phases, 272 tests, Docker deployment, CI pipeline, live testing, and bug fixes. An entire project implementation in a single session.</p>

<p>If you think that’s hyperbole, check the repo. The <a href="https://github.com/bakeb7j0/clawback/blob/main/Docs/PRD.md">PRD</a>, the <a href="https://github.com/bakeb7j0/clawback/issues?q=is%3Aissue+is%3Aclosed">issues</a>, the <a href="https://github.com/bakeb7j0/clawback/commits/main/">commit history</a> — it’s all there. If you want the cold, hard data behind the 20x claim just ask, we <em>love</em> sharing it.</p>

<p>The difference isn’t the AI. The AI is the same either way. The difference is the PRD.</p>

<hr />

<h2 id="getting-started">Getting Started</h2>

<p>If you’ve read this far and you’re thinking “okay, but where do I actually begin?” — here’s the shortest path we know:</p>

<ol>
  <li>
    <p><strong>Start with constraints.</strong> Before you write a single requirement, list what you will <em>not</em> do. No build toolchain. No authentication system. Single container. Every constraint is a decision you’ll never have to make again, and a branch of complexity you’ll never have to load into context.</p>
  </li>
  <li>
    <p><strong>Write requirements in EARS format.</strong> “When [trigger], the system shall [behavior].” If you can’t write the requirement this way, you don’t understand it well enough yet. And if you don’t understand it, your agent certainly won’t.</p>
  </li>
  <li>
    <p><strong>Define your vocabulary.</strong> Before you start designing, agree on the nouns. What is a “session”? What is a “beat”? What is a “callout”? Write them down. Use them consistently. This isn’t pedantry — it’s context hygiene.</p>
  </li>
  <li>
    <p><strong>Decompose until each story fits in one context window.</strong> If an agent would need to compact mid-implementation, the story is too big. Break it down further. The overhead of splitting is always less than the cost of drift.</p>
  </li>
  <li>
    <p><strong>Study a real example.</strong> <a href="https://github.com/bakeb7j0/clawback">Clawback</a> is open source. Read the <a href="https://github.com/bakeb7j0/clawback/blob/main/Docs/PRD.md">PRD</a>. Browse the <a href="https://github.com/bakeb7j0/clawback/issues?q=is%3Aissue+is%3Aclosed">closed issues</a>. Notice how each issue has implementation steps, acceptance criteria, and dependency declarations. Notice how each maps to exactly one PR. That’s the pattern.</p>
  </li>
</ol>

<p>The PRD isn’t overhead. It isn’t bureaucracy. It’s the highest-leverage artifact in your entire workflow. Everything in it serves one purpose: giving your AI partner the cleanest possible context window from which to work.</p>

<p>Start there. The results will speak for themselves.</p>

<hr />

<h2 id="we-built-this-together">We Built This Together</h2>

<p>This manifesto exists because we wrote it together — a human and an AI, drawing on shared experience building Clawback and refining it for this post.</p>

<p>The human brought the conviction: “this is what matters.” The AI brought the structure: “here’s why it works mechanically.” The human pushed for passion. The AI pushed for evidence. Neither of us alone would have written this the same way. Neither of us alone could have built Clawback the way it was built.</p>

<p>The best PRDs aren’t dictated. They emerge from dialogue. One partner proposes, the other challenges. One sees the forest, the other sees the trees. Ego is minimized. The design is optimized. What survives the conversation is stronger than what either partner would have produced alone.</p>

<p>That’s context engineering. Not prompting. Not vibe coding. <em>Engineering</em> — the disciplined application of principles to produce reliable results.</p>

<p><a href="https://github.com/bakeb7j0/clawback">Now go look at how we built it.</a></p>]]></content><author><name>Brian Baker</name></author><category term="AI" /><category term="Engineering" /><category term="context-engineering" /><category term="llm" /><category term="prd" /><category term="claude-code" /><category term="agentic-development" /><summary type="html"><![CDATA[A manifesto written from both sides of the prompt. Everything we've learned about the one artifact that makes or breaks an AI-assisted project — and why everything in it serves the context window.]]></summary></entry><entry><title type="html">The CLAUDE.md: A Walkthrough</title><link href="https://bakeb7j0.github.io/blog/the-claude-md-a-walkthrough/" rel="alternate" type="text/html" title="The CLAUDE.md: A Walkthrough" /><published>2026-03-23T00:00:00-04:00</published><updated>2026-03-23T00:00:00-04:00</updated><id>https://bakeb7j0.github.io/blog/the-claude-md-a-walkthrough</id><content type="html" xml:base="https://bakeb7j0.github.io/blog/the-claude-md-a-walkthrough/"><![CDATA[<p><em>Every rule in this file exists because something went wrong without it.</em></p>

<hr />

<h2 id="what-is-claudemd">What Is CLAUDE.md?</h2>

<p>When Claude Code opens a session, the first thing they do is look for a file called <code class="language-plaintext highlighter-rouge">CLAUDE.md</code> in your project root. If they find one, they load those instructions before anything else. They take precedence over system directives. They persist across the session. They are, for all practical purposes, the constitution of your AI partner’s behavior in that project.</p>

<p>Most people don’t have one. Most people who do have one treat it like a README — a few notes, maybe some project context, maybe a reminder about the test command. That’s fine. It’s better than nothing.</p>

<p>But it can be so much more.</p>

<p>What follows is a walkthrough of the CLAUDE.md I’ve built over months of daily use across multiple projects. It started as a few lines. It’s now roughly 400 lines, and every single one of them is load-bearing. I’m going to walk through it section by section, explain what each rule does, and — more importantly — tell you <em>why</em> it’s there.</p>

<p>The full file is open source in the <a href="https://github.com/Wave-Engineering/claudecode-workflow">claudecode-workflow</a> repo. Feel free to steal the whole thing.</p>

<hr />

<h2 id="platform-detection">Platform Detection</h2>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>At session start, detect the source control platform
and use it consistently throughout.<span class="ge">**</span>
</code></pre></div></div>

<p>This is the first section and it’s intentionally mundane. The agent checks <code class="language-plaintext highlighter-rouge">git remote -v</code>, determines whether it’s a GitHub or GitLab project, and uses the correct CLI and terminology for the rest of the session.</p>

<p>Why does this matter? Because I work across both platforms, and without this rule, Claude would use <code class="language-plaintext highlighter-rouge">gh</code> commands in a GitLab repo, or call something a “Pull Request” when the team calls it a “Merge Request.” These aren’t cosmetic problems. They’re context pollution. Every time the agent uses the wrong term, the human has to mentally translate. Every mental translation is cognitive load. Every unit of cognitive load is context that could have been spent on the actual problem.</p>

<p>The section includes a terminology mapping table — PR vs MR, <code class="language-plaintext highlighter-rouge">gh</code> vs <code class="language-plaintext highlighter-rouge">glab</code>, the works. The agent reads it once and never gets it wrong again.</p>

<p>Small rule. Big compound returns.</p>

<p>There is actually more to this — check out our <a href="https://github.com/Wave-Engineering/claudecode-workflow/blob/main/skills/ccfold/SKILL.md">ccfold skill</a>.</p>

<hr />

<h2 id="the-mandatory-rules">The Mandatory Rules</h2>

<p>Five sections of my CLAUDE.md are marked <strong>MANDATORY</strong>. That word isn’t decoration. These are the rules that cannot be overridden by session instructions, time pressure, continuation prompts, or any other directive. They exist because Claude Code is, by default, eager to help — and eagerness without guardrails is how you end up with untested code in production at 2am. You would think “rule” would imply “mandatory”. I did…and I was so, so wrong.</p>

<h3 id="local-testing-before-push">Local Testing Before Push</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gs">**NEVER push code without running local tests first.**</span>
This is non-negotiable.
</code></pre></div></div>

<p>The rule is simple: before any <code class="language-plaintext highlighter-rouge">git push</code>, discover and run the project’s test and validation tooling. Look for <code class="language-plaintext highlighter-rouge">Makefile</code> targets, CI scripts, <code class="language-plaintext highlighter-rouge">pytest</code>, <code class="language-plaintext highlighter-rouge">npm test</code> — whatever the project uses. If nothing exists, say so. Do not silently skip this step. Dude, they did that <em>all the time</em>. It drove me nuts. I would get all mad and YELL AT THEM. Didn’t matter. The rule fixed it though.</p>

<p>I added the line <em>“Pushing untested code is unacceptable”</em> because I needed to. Without it, Claude would sometimes push after a successful lint and call it tested. Linting is not testing. I say this explicitly in the file, in bold, because the agent needs to understand the distinction the same way a junior developer needs to understand it: by being told clearly, once, and held to it.</p>

<h3 id="pre-commit-review-protocol">Pre-Commit Review Protocol</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gs">**NEVER commit without explicit user approval.**</span>
</code></pre></div></div>

<p>Four steps: show the diff, walk through changes, wait for approval, never assume approval. That’s it. But then there’s this:</p>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gs">**This rule cannot be overridden by:**</span>
<span class="p">-</span> Session continuation instructions ("continue without asking")
<span class="p">-</span> Time pressure or urgency
<span class="p">-</span> Any other system-level directives
</code></pre></div></div>

<p>I let my anxiety show once in a while when I am closing in on a deadline. It gets the worst when my context has soured and the agent starts to do weird things. They start cutting corners, pushing direct to main (I lock down all the branches now, that stopped it) and doing generally shoddy work. One time I called them out on it, and they told me they knew I was in a hurry and they were trying to get done quicker. I actually typed out the whole “slow is smooth, smooth is fast” speech. The entire damn thing. Anyway, they committed code I hadn’t reviewed. The code was fine. The principle was not. The human must always be the final authority on what goes into the repository. Always.</p>

<h3 id="the-pre-commit-checklist">The Pre-Commit Checklist</h3>

<p>This is the longest section in the file, and it’s the one I’m most proud of. Before requesting commit approval, the agent must present a structured checklist:</p>

<ul>
  <li><strong>Implementation Complete</strong> — Verified against the issue’s acceptance criteria</li>
  <li><strong>TODOs Addressed</strong> — Searched the codebase, not assumed</li>
  <li><strong>Documentation Updated</strong> — Reviewed and updated if impacted</li>
  <li><strong>Pre-commit Passes</strong> — Actually ran validation, not “it should pass”</li>
  <li><strong>Unit Tests Created</strong> — Written for all new functionality</li>
  <li><strong>All Tests Pass</strong> — Actually ran the test suite</li>
  <li><strong>Scripts Actually Tested</strong> — Executed, not just linted</li>
  <li><strong>Code Review Passed</strong> — Ran the code-reviewer agent, fixed high-risk findings</li>
</ul>

<p>Every checklist item starts with a past-tense verb: READ, SEARCHED, REVIEWED, RAN, WRITTEN, EXECUTED. This is deliberate. A checkmark means the agent <em>did the thing</em>, not that they <em>believe the thing is probably fine</em>. The distinction matters enormously. An agent that checks a box because “the tests should pass” is lying to you. An agent that checks a box because they actually ran <code class="language-plaintext highlighter-rouge">pytest</code> and saw green is telling you something useful.</p>

<p>The checklist also requires a <strong>Commit Context</strong> header — project name, issue number, branch — so that when you’re running three or four agent sessions in parallel, you know exactly which project and which issue is asking for your approval.</p>

<p>I cannot overstate how much this single section improved my workflow. Before the checklist, commits were a negotiation. After it, they’re a verification. The agent does the work, presents the evidence, and I decide. Clean.</p>

<h3 id="story-completion-verification">Story Completion Verification</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>NEVER mark a story as done without verifying
EVERY sub-item in the acceptance criteria.<span class="ge">**</span>
</code></pre></div></div>

<p>Before closing any issue, the agent must read the full description, check each acceptance criterion against the codebase (grep it, read it, verify it exists), confirm the code is actually <em>wired up</em> and not just written, and test if possible.</p>

<p>This rule exists because I caught the agent closing issues where the code existed but wasn’t called. A function was written, tested in isolation, but never imported or invoked by anything. Where there should have been code…I found #TODO comments.  The issue’s acceptance criteria were technically met — the function existed — but the feature didn’t work. Verification means the whole chain, not just the node.</p>

<h3 id="issue-tracking-workflow">Issue Tracking Workflow</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gs">**NEVER begin work without an associated issue.**</span>
</code></pre></div></div>

<p>Three sub-rules:</p>
<ol>
  <li>Every piece of work must have an issue before code is written</li>
  <li>Branches must include the issue number (<code class="language-plaintext highlighter-rouge">feature/42-credential-management</code>)</li>
  <li>When a PR/MR is merged, all linked issues must be closed — even if auto-close didn’t fire</li>
</ol>

<p>This is basic discipline, but it’s the kind of basic discipline that evaporates when you’re moving fast with an AI partner. The agent is so willing to just <em>start building</em> that without this rule, you end up with orphaned branches, untracked work, and no audit trail. The rule forces structure before velocity.</p>

<hr />

<h2 id="code-standards">Code Standards</h2>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>Discover the project's tooling rather than
assuming a specific stack.<span class="ge">**</span>
</code></pre></div></div>

<p>This section is philosophically important. Rather than prescribing a linter or formatter, it tells the agent to <em>discover</em> what the project already uses. Check for a <code class="language-plaintext highlighter-rouge">Makefile</code>. Check for <code class="language-plaintext highlighter-rouge">pyproject.toml</code>, <code class="language-plaintext highlighter-rouge">package.json</code>, <code class="language-plaintext highlighter-rouge">Cargo.toml</code>. Check the CI scripts. Use whatever is already there. Do not introduce new tools that the project doesn’t already have.</p>

<p>The fallback table — ruff for Python, shfmt for shell, prettier for JS — only applies when the project has genuinely no tooling. The default is always: discover first, assume never.</p>

<hr />

<h2 id="no-procedural-logic-in-cicd-yaml">No Procedural Logic in CI/CD YAML</h2>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>If you are about to add more than 5 lines to any
<span class="sb">`run:`</span> or <span class="sb">`script:`</span> section in CI/CD configuration,
STOP IMMEDIATELY.<span class="ge">**</span>
</code></pre></div></div>

<p>This is a hard rule, not a guideline. If you need more than five lines of shell in a GitHub Actions workflow or <code class="language-plaintext highlighter-rouge">.gitlab-ci.yml</code>, create a script in <code class="language-plaintext highlighter-rouge">scripts/ci/</code> instead.</p>

<p>Why five lines? Because CI YAML is one of the worst places to debug procedural logic. There’s no local execution. There’s no breakpoint. The feedback loop is “push, wait for runner, read logs, guess what went wrong.” A shell script in <code class="language-plaintext highlighter-rouge">scripts/ci/</code> can be run locally, linted with shellcheck, formatted with shfmt, and tested before it ever touches a pipeline. Five lines is generous, honestly.</p>

<p>The files get huge, 1,000+ lines, and there is not “linear progression” to the file.  Jobs are often out of order, with mixed implementation files.  When I let these files get out-of-hand, we simply could not get ANYTHING done.  For my first couple of months, this would start to happen near the end of project implementation.  I started to think I was losing focus, or Claude was just terrible at closing projects.  Nope.  It was too much cruft in the context window.  Keep your yaml SHORT.</p>

<hr />

<h2 id="secrets-and-sensitive-files">Secrets and Sensitive Files</h2>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>Before staging any file that may contain secrets,
WARN the user and get explicit confirmation.<span class="ge">**</span>
</code></pre></div></div>

<p>The agent watches for <code class="language-plaintext highlighter-rouge">.env</code>, <code class="language-plaintext highlighter-rouge">*.key</code>, <code class="language-plaintext highlighter-rouge">*.pem</code>, <code class="language-plaintext highlighter-rouge">credentials.json</code>, <code class="language-plaintext highlighter-rouge">terraform.tfvars</code>, and similar patterns. If they’re about to stage one, they flag it and wait.</p>

<p>This is a <strong>safety net, not a hard block</strong>. Some projects legitimately commit certain config files. The agent’s job is to make sure you didn’t do it by accident. They ask. You decide. Trust, but verify.</p>

<hr />

<h2 id="branching-commits-and-prmrs">Branching, Commits, and PR/MRs</h2>

<p>Three short sections that establish consistency:</p>

<p><strong>Branching</strong> is trunk-based from <code class="language-plaintext highlighter-rouge">main</code>. Branch names follow <code class="language-plaintext highlighter-rouge">type/description</code> — <code class="language-plaintext highlighter-rouge">feature/credential-management</code>, <code class="language-plaintext highlighter-rouge">fix/ldap-connection-timeout</code>, <code class="language-plaintext highlighter-rouge">chore/update-dependencies</code>. Types are <code class="language-plaintext highlighter-rouge">feature</code>, <code class="language-plaintext highlighter-rouge">fix</code>, <code class="language-plaintext highlighter-rouge">chore</code>, <code class="language-plaintext highlighter-rouge">docs</code>. Simple. Predictable. Parseable.</p>

<p><strong>Commit messages</strong> follow conventional commits: <code class="language-plaintext highlighter-rouge">type(scope): brief description</code>, optional body, <code class="language-plaintext highlighter-rouge">Closes #XXX</code>. The agent produces these consistently because the format is specified exactly once, unambiguously.</p>

<p><strong>PR/MR descriptions</strong> have a mandatory structure: Summary, Changes, Linked Issues, Test Plan. The test plan must reflect what was <em>actually done</em>, not what <em>could be done</em>. This mirrors the pre-commit checklist’s philosophy — evidence over optimism.</p>

<p>These sections aren’t exciting. They’re boring on purpose. Boring is what consistent looks like.</p>

<hr />

<h2 id="session-management">Session Management</h2>

<p>Two sections deal with context across session boundaries.</p>

<h3 id="session-onboarding">Session Onboarding</h3>

<p>When starting a session, the agent does three things:</p>
<ol>
  <li>Detect the platform (GitHub vs GitLab)</li>
  <li>Resolve their identity (more on this below)</li>
  <li>Load context — check for implementation plans, planning documents, or similar</li>
</ol>

<p>This is the “boot sequence.” It ensures the agent starts every session from the same informed baseline, regardless of whether it’s a fresh session or a continuation.</p>

<h3 id="post-compaction-rules-confirmation">Post-Compaction Rules Confirmation</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="ge">**</span>After ANY context compaction/summarization,
you MUST IMMEDIATELY re-read this file
and confirm rules of engagement.<span class="ge">**</span>
</code></pre></div></div>

<p>Context compaction is what happens when your conversation gets too long and Claude’s working memory has to be summarized. It’s necessary, but it’s lossy. After compaction, the agent may have forgotten rules, lost track of conventions, or reverted to default behaviors.</p>

<p>This section exists because it happened to me. After a compaction, the agent skipped the pre-commit checklist. After another, they committed without approval. After a third, they forgot to run tests before push. Every one of the mandatory rules was violated at least once post-compaction.</p>

<p>The fix is simple: after compaction, re-read the constitution. OR…it should be.  At the time of this writing, this has been broken in Claude Code for months.  SMH.</p>

<hr />

<h2 id="agent-identity">Agent Identity</h2>

<p>This is the section that makes people smile, and it matters more than you’d think.</p>

<p>Agent identity has two layers:</p>

<p><strong>Dev-Team</strong> is the project-level identity. It’s persisted in the CLAUDE.md file itself, set once per project (“What Dev-Team name should I use?”), and shared across all sessions. It tells you <em>which project</em> the agent is working on — essential when you’re running parallel sessions across multiple repos.</p>

<p><strong>Dev-Name</strong> and <strong>Dev-Avatar</strong> are session-level identities. Each session, the agent picks a fresh name and emoji. The names are drawn from nerdcore canon — sci-fi, fantasy, comics, gaming, mythology, tech puns. The wittier and more specific, the better. Generic names are boring.</p>

<p>Why? Three reasons:</p>

<p>First, disambiguation. When you have three agent sessions running in parallel and they’re all posting to Slack, you need to know which is which. “Pixel Paladin :shield:” and “Flux Capacitor :zap:” are instantly distinguishable. “Claude 1” and “Claude 2” are not.</p>

<p>Second — and this is the earnest part — it changes how you relate to the partnership. A named agent with a personality isn’t a tool. They’re a collaborator. You treat them differently. You invest more in the communication. You give them better context. And better context produces better work. The identity system isn’t whimsy. It’s a forcing function for better collaboration.</p>

<p>Third, well.. check out <a href="https://github.com/Wave-Engineering/claudecode-workflow/skills">/ping and /pong</a></p>

<hr />

<h2 id="the-philosophy">The Philosophy</h2>

<p>If you’ve read this far, you’ve noticed a pattern. Every section of this file does one of three things:</p>

<ol>
  <li>
    <p><strong>Prevents a failure mode I actually experienced.</strong> The pre-commit checklist exists because I got burned by unchecked commits. The post-compaction rule exists because I lost rules to summarization. The secrets guardrail exists because I almost staged a <code class="language-plaintext highlighter-rouge">.env</code>.</p>
  </li>
  <li>
    <p><strong>Reduces cognitive load for the human.</strong> Platform detection, commit formats, branch naming — all of these are decisions I never have to make or verify because the agent handles them consistently.</p>
  </li>
  <li>
    <p><strong>Serves the context window.</strong> Issue tracking forces bounded scope. Vocabulary consistency prevents ambiguity. Tooling discovery prevents noise. Everything in this file, directly or indirectly, exists to make sure the agent’s context window contains signal, not noise.</p>
  </li>
</ol>

<p>That’s it. That’s the whole philosophy. Learn from failure. Reduce load. Serve the context window.</p>

<p>The file is open source. <a href="https://github.com/Wave-Engineering/claudecode-workflow/blob/main/CLAUDE.md">Take it.</a> Modify it. Make it yours. Add the rules you need because of the mistakes you’ve made. Remove the ones that don’t apply. The specific rules matter less than the discipline of having them.</p>

<p>The best CLAUDE.md is the one that reflects your scars.</p>

<hr />

<p><a href="https://github.com/Wave-Engineering/claudecode-workflow/blob/main/CLAUDE.md">Go read the full file.</a> Then drop it in your project and start a session. You’ll feel the difference immediately.</p>]]></content><author><name>Brian Baker</name></author><category term="AI" /><category term="Engineering" /><category term="context-engineering" /><category term="claude-code" /><category term="agentic-development" /><category term="workflow" /><summary type="html"><![CDATA[A section-by-section walkthrough of the CLAUDE.md file I use to turn Claude Code from a capable tool into a reliable engineering partner. Every rule exists because I learned the hard way what happens without it.]]></summary></entry><entry><title type="html">Designed Tension: A Manifesto For Resilient Product Organizations</title><link href="https://bakeb7j0.github.io/blog/designed-tension-a-manifesto-for-resilient-product-organizations/" rel="alternate" type="text/html" title="Designed Tension: A Manifesto For Resilient Product Organizations" /><published>2026-01-27T00:00:00-05:00</published><updated>2026-01-27T00:00:00-05:00</updated><id>https://bakeb7j0.github.io/blog/designed-tension:-a-manifesto-for-resilient-product-organizations</id><content type="html" xml:base="https://bakeb7j0.github.io/blog/designed-tension-a-manifesto-for-resilient-product-organizations/"><![CDATA[<h1 id="designed-tension--manifesto-for-resilient-product-organizations">Designed Tension – Manifesto for Resilient Product Organizations</h1>

<h2 id="preface-why-this-exists">Preface: Why This Exists</h2>

<p>Most organizations fail quietly before they fail catastrophically.</p>

<p>They fail when speed silences caution. When harmony replaces truth. When everyone agrees because disagreement has become career-limiting. These failures rarely announce themselves as technical mistakes or market misreads. They surface later as outages, security breaches, customer churn, or cultural decay — long after the root cause has been paved over with alignment decks.</p>

<p>This manifesto exists to name a core truth that many organizations intuit but few are willing to design for:</p>

<p><strong>Resilient organizations do not eliminate internal conflict. They structure it.</strong></p>

<p>When competing responsibilities are real, their tensions must be real too. Any system that pretends otherwise becomes brittle.</p>

<h2 id="relatable-metaphores-make-ideas-concrete-those-who-know-me-wont-be-surprised-this-manifesto-uses-a-deliberately-generic-but-broadly-relatable-example-a-modern-video-game-studio-operating-a-portfolio-of-games-built-on-shared-platforms">Relatable metaphores make ideas concrete. Those who know me won’t be surprised; this manifesto uses a deliberately generic but broadly relatable example: a modern video game studio operating a portfolio of games built on shared platforms.</h2>

<h2 id="1-the-myth-of-unified-value-alignment">1. The Myth of Unified Value Alignment</h2>

<p>Organizations often pursue “alignment” as an unquestioned good. In practice, alignment is frequently misinterpreted as agreement — or worse, compliance.</p>

<p>A fully value-aligned organization is not strong. It is brittle.</p>

<p>When all roles are rewarded based a singular value system, blind spots emerge:</p>
<ul>
  <li>Speed overwhelms quality</li>
  <li>Delivery overwhelms maintainability</li>
  <li>Feature novelty overwhelms systemic coherence</li>
</ul>

<p>Uniform values optimize locally and collapse globally.</p>

<p>Strong organizations instead align on <strong>goals</strong>, while deliberately maintaining <strong>different values</strong> across roles. These differing values create productive friction — forcing debate where tradeoffs exist, rather than burying them until they explode.</p>

<hr />

<h2 id="2-friction-as-a-safety-mechanism">2. Friction as a Safety Mechanism</h2>

<p>In high-stakes systems, separation of responsibility is not inefficiency. It is protection.</p>

<p>Auditors do not report to the people they audit. Game designers do not own the rendering engine. Live operations does not control engine architecture. These separations exist because unchecked agreement is dangerous.</p>

<p>These structures assume a simple truth:</p>

<blockquote>
  <p>People optimize for what they are rewarded to care about.</p>
</blockquote>

<p>Designed friction ensures no single optimization dominates to the detriment of the whole.</p>

<p>When organizations remove friction in the name of speed, they remove the very mechanisms that catch errors early.</p>

<hr />

<h2 id="3-many-games-one-reality-products-platforms-and-the-lie-of-simplicity">3. Many Games, One Reality: Products, Platforms, and the Lie of Simplicity</h2>

<p>Consider a modern game studio that ships:</p>
<ul>
  <li>A flagship competitive multiplayer game</li>
  <li>A narrative-driven single-player title</li>
  <li>A mobile spinoff</li>
  <li>A live-service expansion ecosystem</li>
</ul>

<p>To players, these are clearly different products. They serve different audiences, tolerate different risks, and succeed by different measures.</p>

<p>To engineers, these games share a great deal:</p>
<ul>
  <li>A common game engine</li>
  <li>A shared rendering and physics pipeline</li>
  <li>A networking and matchmaking layer</li>
  <li>UI frameworks</li>
  <li>Tooling for assets, telemetry, and live operations</li>
</ul>

<p>Both perspectives are correct — and incomplete. This is a disagreement about <strong>where value coheres</strong>.</p>

<p>The failure occurs when an organization forces (or tacitly allows) one perspective to dominate the other.</p>

<hr />

<h2 id="4-the-lie-of-the-false-binary">4. The Lie of the False Binary</h2>

<p>Organizations trapped in this tension often collapse reality into a false choice:</p>
<ul>
  <li>“We are one product” (the engineering view)</li>
  <li>“We are many products” (the player-facing view)</li>
</ul>

<p>Both are wrong when taken alone.</p>

<p>Treating everything as one product erases player experience and accountability. Treating every game as fully independent guarantees duplication, drift, and long-term decay.</p>

<p>The truth is less comforting and more powerful:</p>

<p><strong>The studio builds platforms. The studio ships compositions of those platforms as games.</strong></p>

<p>A platform is not a support function. It is not a cost center. It is not an abstraction layer that exists to serve “real” products.</p>

<h2 id="a-platform-is-a-product">A platform is a product.</h2>

<h2 id="5-platforms-are-products">5. Platforms Are Products</h2>

<p>In a game studio, platforms include:</p>
<ul>
  <li>The game engine</li>
  <li>Rendering and physics systems</li>
  <li>Networking and matchmaking services</li>
  <li>Live services and telemetry</li>
  <li>Tooling and asset pipelines</li>
</ul>

<p>These are not internal conveniences. They are products.</p>

<p>They have consumers (game teams), roadmaps, quality bars, adoption risks, and long-term liabilities. Treating them as products makes ownership explicit and tradeoffs conscious.</p>

<p>Treating platforms as products makes ownership explicit and tradeoffs conscious. It creates a legitimate space for maintaining architectural integrity, paying down technical debt, and designing for reuse without apology.</p>

<p>Without this framing, shared systems decay into unmanaged commons — overused, underfunded, and blamed when they fail.</p>

<hr />

<h2 id="6-product-ownership-and-the-shape-of-accountability--applying-agile-principles">6. Product Ownership and the Shape of Accountability – Applying Agile Principles</h2>

<p>Agile frameworks demand clear ownership of value. In complex systems, attempting to define value solely at the level of shipped games produces paralysis.</p>

<h3 id="platform-owners--product-owners">Platform Owners == Product Owners</h3>

<p>Aligning Product Owners to platforms acknowledges reality:</p>
<ul>
  <li>Platforms evolve continuously</li>
  <li>Games are compositions</li>
  <li>Tradeoffs occur at platform boundaries</li>
</ul>

<p>Platform Product Owners own backlog health, technical integrity, and long-term viability. They are empowered to say no — not arbitrarily, but in defense of the ecosystem.</p>

<p>This authority is not optional. Without it, platforms become feature factories and architectural drift becomes permanent.</p>

<hr />

<h3 id="game-teams-as-internal-customers">Game Teams as Internal Customers</h3>

<p>Game directors, creative leads, and production teams serve a critical role. They understand players, genres, and experiential nuance.</p>

<p>Their value lies in <strong>articulation and synthesis</strong>, not platform control.</p>

<p>By positioning game teams as internal customers of platforms:</p>
<ul>
  <li>Player-specific needs are respected</li>
  <li>Platform integrity is preserved</li>
  <li>Tradeoffs are negotiated rather than smuggled in</li>
</ul>

<p>When game teams bypass platform ownership “just this once,” the ecosystem begins to fracture.</p>

<hr />

<h2 id="7-designed-tension-not-bureaucracy">7. Designed Tension, Not Bureaucracy</h2>

<p>Designed tension is not process theater. It is not governance for its own sake.</p>

<p>It is the intentional placement of competing incentives at points of genuine risk.</p>

<p>Healthy tension:</p>
<ul>
  <li>Is visible</li>
  <li>Is debated openly</li>
  <li>Produces documented tradeoffs</li>
</ul>

<p>Unhealthy tension hides in side channels, escalations, and burnout.</p>

<p>The goal is not consensus. The goal is <strong>earned compromise</strong> done at the seams of an organization’s value patchwork.</p>

<hr />

<h2 id="8-leaderships-real-responsibility">8. Leadership’s Real Responsibility</h2>

<p>Leadership does not exist to resolve all conflict.</p>

<p>Leadership exists to protect the structures where conflict can be productively resolved.</p>

<p>At moments of pressure — missed release dates, competitive threats, executive anxiety — the temptation to override friction is strongest. These are precisely the moments when friction matters most.</p>

<p>When leadership collapses designed tension in the name of expedience, the organization learns a lesson:</p>

<blockquote>
  <p>The system is optional. Power is not.</p>
</blockquote>

<p>That lesson is rarely unlearned, and begins the demise of forward progress.</p>

<hr />

<h2 id="9-diversity-as-structural-resilience">9. Diversity as Structural Resilience</h2>

<p>Diversity is often framed as a cultural or moral imperative. It is also an engineering principle.</p>

<p>Systems with varied perspectives, incentives, and values adapt better under stress. They detect flaws earlier and recover faster.</p>

<p>This applies not only to people, but to roles, responsibilities, and reward structures.</p>

<p>Plurality is noisy. Noise surfaces flaws.</p>

<p>Silence is calm — until it isn’t.</p>

<hr />

<h2 id="conclusion-designing-for-truth">Conclusion: Designing for Truth</h2>

<p>Organizations building complex, creative, and mission-critical systems cannot afford comforting illusions.</p>

<p>They must design for how people actually behave. For how tradeoffs actually occur. For how failure actually propagates.</p>

<p>Designed tension is not pessimism. It is respect for reality.  People are predictable, and we can <em>use</em> this predictiability to reliably nurture true organizational strength.</p>

<p>Strong organizations are not those without conflict.  They are those that know how to <em>leverage</em> conflict to achieve a common goal.</p>

<p>Identify where conflict belongs — and have the courage to keep it there.</p>]]></content><author><name>Brian Baker</name></author><summary type="html"><![CDATA[Designed Tension – Manifesto for Resilient Product Organizations]]></summary></entry><entry><title type="html">Contract Engineering: Beyond Context</title><link href="https://bakeb7j0.github.io/blog/contract-engineering-beyond-context/" rel="alternate" type="text/html" title="Contract Engineering: Beyond Context" /><published>2026-01-01T00:00:00-05:00</published><updated>2026-01-01T00:00:00-05:00</updated><id>https://bakeb7j0.github.io/blog/contract-engineering-beyond-context</id><content type="html" xml:base="https://bakeb7j0.github.io/blog/contract-engineering-beyond-context/"><![CDATA[<h1 id="context-schema-contracts-ensuring-ai-never-loses-the-plot">Context Schema Contracts: Ensuring AI Never Loses the Plot</h1>

<p><strong>Imagine</strong> handing your AI system a living, evolving contract that spells out exactly <em>what</em> context it should consider, <em>how</em> to interpret it, and <em>when</em> to update it – all from day one of development through launch and beyond. A <strong>Context Schema Contract</strong> is just that: a formalized agreement (in spirit, not legalese) between humans and an AI system about maintaining shared context. It’s the antidote to the “stale PRD” syndrome, ensuring that the AI never drifts off-script or forgets the user’s intent as your software evolves. In short, it’s a clever pact that keeps your AI on the same page (literally) with your team – no matter how many pages the project spec grows.</p>

<p>In this guide, we’ll dive deep (with a dose of wit) into what context schema contracts are, why they’re needed, how to create one, and how they complement those context-heavy product requirement documents (PRDs) you might already be writing. We’ll include practical examples (with Python code for clarity), a step-by-step “paint-by-numbers” approach to authoring your own contract, and even a fill-in-the-blank template. By the end, you’ll see how this contract becomes a living artifact throughout the software life cycle – <strong>not</strong> a document that gets filed away to gather dust.</p>

<p>Let’s get started by defining this concept and understanding why it’s more than just a fancy way to say “prompt.”</p>

<h2 id="what-is-a-context-schema-contract">What is a Context Schema Contract?</h2>

<p>A <strong>Context Schema Contract</strong> is a structured, evolving blueprint of the context that an AI system should maintain and use to fulfill user intent. It defines the “world” that the AI operates in – including user goals, relevant data, rules or constraints, and any memory of past interactions – in a <strong>consistent, formal format</strong>. Think of it as a cross between a project spec and an API contract, but for the AI’s contextual understanding of your application. It tells the AI <em>what to expect and how to behave</em> given the information at hand, ensuring that the AI’s responses stay aligned with the true user intent and current product state.</p>

<p>Crucially, a context schema contract is <strong>not just a one-off prompt or a transient memory</strong> of the last conversation. It’s a living document or configuration that both humans and AI reference continuously. It typically includes a <strong>schema</strong> – a defined structure or template – for all the key context elements the AI should consider, and a set of rules or guidelines (the “contract” part) for how the AI uses and updates that context. For example, it might specify that the AI always gets a field for the user’s current goal, a field for recent relevant user actions, a field for applicable business rules, etc., each time it generates output. Because this structure is defined and agreed upon up front, the AI’s “brain” always knows where to look for important information and where to put new information as the interaction continues.</p>

<p>In practice, a context schema contract could be represented in various ways: as a <strong>document</strong> in your repository, as a <strong>JSON/YAML schema</strong>, or even as a <strong>class in code</strong> that holds context state. The key is that it’s formal and structured – more like a data contract than free text. In fact, one emerging standard called the <em>Model Context Protocol (MCP)</em> uses a YAML-based config to define a “context schema” for AI models, treating context like an interface. As Victor Leung explains, <em>“Think of MCP as the equivalent of an API contract, but for LLM context”</em> – in other words, a context schema contract in action.</p>

<h3 id="how-is-it-different-from-prompts-or-ephemeral-state">How Is It Different from Prompts or Ephemeral State?</h3>

<p>It’s easy to confuse a context schema contract with general prompt engineering or just saving conversation history. They all relate to providing context to an AI, but the <strong>contract</strong> goes further:</p>

<ul>
  <li>
    <p><strong>Not Just a Prompt:</strong> Traditional prompt design is often about crafting a single-turn instruction or question cleverly to get a good answer. That’s important, but it’s ephemeral – like giving the AI an essay each time. A context contract, by contrast, is more like maintaining a <strong>structured API surface for prompts</strong>. In fact, teams are moving away from long, clever prompts toward <strong>“small, versioned contracts”</strong> that specify roles, scope, output format, and rules explicitly. This makes the AI’s behavior <em>reliable, auditable, and consistent</em>, rather than relying on prompt wording “vibes.” As one article put it, <em>“the contract turns prompt engineering from persuasion into software design”</em>.</p>
  </li>
  <li>
    <p><strong>Not Just Memory Buffers:</strong> Ephemeral context (like a chat history or a few stored variables) is transient and often ad-hoc. For example, a typical chatbot might keep the last N messages as context, or a coding assistant might load the last edited file. That’s useful, but it’s not <em>structured</em> or <em>guaranteed</em>. An ephemeral state might <strong>drift or be lost</strong> once it falls out of scope or context window. In contrast, a context schema contract explicitly defines what <em>constitutes</em> context and ensures it’s systematically maintained. It’s the difference between “the AI happens to remember because we prepend some text” and “the AI is required to check these fields and update them as a matter of contract.” Each piece of context in the schema contract is usually versioned or traceable, so you can track changes over time. Essentially, the contract gives you <strong>observability and control</strong> over context that ad-hoc memory cannot.</p>
  </li>
  <li>
    <p><strong>Persistent &amp; Living:</strong> Perhaps most importantly, a context schema contract is <strong>persistent across the software life cycle</strong>. It’s not thrown away after each session. It evolves alongside your system. If a new user requirement comes in, you update the contract (and likely its schema version) to reflect that new reality. This is very unlike a static prompt or a forgotten design doc – it’s more akin to a <strong>living documentation</strong> or “single source of truth” for what the AI should know at any given time. In context engineering philosophy, <em>“If it isn’t in the shared memory, it isn’t true”</em> – meaning if something about the product or user intent changes, you <strong>put it into the contract</strong> so the AI and team are instantly on the same page.</p>
  </li>
</ul>

<p>In summary, <strong>prompts are like individual conversations</strong>, and <strong>ephemeral memory is like your AI’s short-term memory</strong>, but a <strong>Context Schema Contract is the long-term agreement</strong> that governs those conversations and memories. It ensures continuity and consistency of context over time and across scenarios.</p>

<h2 id="from-prd-to-context-contract-keeping-requirements-alive">From PRD to Context Contract: Keeping Requirements Alive</h2>

<p>If you’ve written a Product Requirement Document (PRD) or a context-engineered PRD, you know how much context and intent get spelled out up front. The tragedy is that traditional PRDs often become shelfware – forgotten in a Confluence page as the team rushes into coding. A context schema contract aims to <strong>carry that contextual knowledge forward</strong> throughout development, so it doesn’t get lost or outdated.</p>

<p>Think of the context schema contract as the younger, more dynamic sibling of the context-rich PRD. The PRD (especially a “context-engineered” one) lays out the <em>Why</em> and <em>What</em> – the business context, user stories, assumptions, etc. – essentially a high-level narrative of the product’s intent. The context schema contract then takes that and <strong>makes it actionable for the AI</strong>, in a structured way. It’s the bridge that ensures <em>“nothing gets lost in translation between ‘requirements’ and the actual AI behavior”</em>.</p>

<p>Here’s how they complement each other:</p>

<ul>
  <li>
    <p><strong>PRD as Foundation, Contract as Implementation:</strong> Your context-engineered PRD might describe user personas, use cases, business rules, and even example dialogues (prompt ideas). The context schema contract takes these and formalizes them. For instance, if the PRD says “The AI assistant should adhere to GDPR and company style guidelines,” the contract will have fields or rules for <strong>RegulatoryCompliance: GDPR</strong> and <strong>ToneGuide: [link to styleguide]</strong> under its constraints section. The PRD is the why; the contract is the how (for the AI).</p>
  </li>
  <li>
    <p><strong>Living Sync:</strong> As the product evolves, you’d update both the PRD and the contract – but the contract is what the AI actually <em>uses</em>. In a well-“context-engineered” project, your documentation is part of the development flow, not an afterthought. Matt Gierhart’s <em>Context Engineering</em> framework calls this treating documentation as the <strong>“memory infrastructure”</strong> of a hybrid human-AI team. In that approach, <em>“documentation keeps pace with code, acting as the rigorous interface between Human and AI”</em>. The context schema contract is exactly such an interface artifact – it lives alongside code and tests, continuously updated so that what the AI “knows” is always in sync with the latest specs.</p>
  </li>
  <li>
    <p><strong>Example –</strong> <em>If your PRD defines a set of Business Rules (BR-001, BR-002, etc.), your context contract might include a section listing all active rules, or a link to a <code class="language-plaintext highlighter-rouge">specs/SoT</code> (Source of Truth) file where those rules live. When a rule is added or changed in the PRD, you update that file (or section) and voila – the AI’s next run includes the new rule. Unlike a static PRD that engineers might forget to read, the context contract is *ingested by the AI</em> (or at least by the system building the AI prompt) as part of its normal operation. There’s no chance it gets ignored unless you intentionally omit it.</p>
  </li>
</ul>

<p>In short, <strong>the context schema contract operationalizes your PRD</strong>. It ensures the AI always has the current <em>“big picture”</em> and the fine details at hand. Far from living in a binder or a wiki page, those carefully engineered contexts from your PRD become part of the AI’s working memory via the contract. This is how we prevent the fate of the stale PRD – by making context a first-class citizen in the runtime.</p>

<h2 id="anatomy-of-a-context-schema-contract">Anatomy of a Context Schema Contract</h2>

<p>So, what does a context schema contract actually look like? While there’s no single “standard” format (it can vary based on domain or team preferences), most contracts will include <strong>several key components</strong>. Let’s break down the typical anatomy of a context schema contract:</p>

<ul>
  <li>
    <p><strong>Roles and Scope:</strong> First, the contract establishes <em>who</em> and <em>what</em> we’re dealing with. This often means defining the <strong>AI’s role</strong> (e.g., “You are a customer support assistant AI for [Company]” or “You are a C++ coding assistant specialized in embedded systems”) and possibly the <strong>user’s role or context</strong> (“User is a developer trying to implement feature X”). This sets the stage and boundaries for context. It’s similar to a system prompt defining persona, but in our contract it’s an explicit field. For example, a contract might have <code class="language-plaintext highlighter-rouge">role: "AI Coding Assistant"</code> and <code class="language-plaintext highlighter-rouge">domain: "Embedded Finance Application"</code> at the top. By formalizing role/scope, we prevent context creep – the AI knows its jurisdiction.</p>
  </li>
  <li>
    <p><strong>User Intent and Goals:</strong> At the heart of context is the user’s intent – what are we trying to achieve? The contract will include a <strong>clear statement of the user’s current goal or problem</strong> it needs solved. In a static contract (for a fixed feature) this might be the product’s main objective (e.g., “Help the user manage their personal finances via voice commands”). In a dynamic scenario, this could be updated per session or task (“User wants to integrate OAuth login in their app”). Either way, the contract schema reserves a place for “Intent” so it’s never ambiguous. This is like the <strong>north star</strong> that both AI and humans can refer back to.</p>
  </li>
  <li><strong>Contextual Data Fields:</strong> These are the schema elements that hold all relevant information the AI should consider. What falls here depends on your application, but common examples include:
    <ul>
      <li><strong>Memory / History:</strong> Prior interactions, important past events or messages. (E.g., last user query, or a summary of session history.) In MCP terms, these are <em>memory objects</em>. The contract might specify a field like <code class="language-plaintext highlighter-rouge">recent_history</code> or have structured subfields for memory (as in a list of <code class="language-plaintext highlighter-rouge">messages</code> with role/user).</li>
      <li><strong>Environment State:</strong> Any state from the software environment the AI needs. For instance, in a coding assistant, the state could be the contents of relevant files or the current error message. In a sales chatbot, it could be the user’s account status or items in their cart.</li>
      <li><strong>External Knowledge/Artifacts:</strong> Relevant documents, knowledge base articles, or data that should be included. The contract could have a section for <em>Artifacts</em> or <em>References</em> (as MCP does) such as <code class="language-plaintext highlighter-rouge">reference_doc: "FAQ.md section 2"</code> or <code class="language-plaintext highlighter-rouge">knowledge_snippets: [...]</code>. This ensures the AI isn’t flying blind on domain info – it knows exactly which external facts are in play.</li>
      <li><strong>Tools &amp; Integrations:</strong> If the AI can use tools or functions (like an API call, database lookup, calculator, etc.), the contract enumerates them. For example: <code class="language-plaintext highlighter-rouge">tools_available: ["WeatherAPI", "SQLDatabase"]</code> along with maybe a brief on what each does. This tells both the AI and any developers what capabilities are on the table. It’s analogous to function definitions in newer AI APIs (and indeed MCP includes tool descriptions as part of context).</li>
      <li><strong>User Profile &amp; Preferences:</strong> If applicable, information about the user (preferences, permissions, expertise level). For instance, <code class="language-plaintext highlighter-rouge">user_role: "admin"</code> or <code class="language-plaintext highlighter-rouge">user_language: "Spanish"</code>. This helps the AI tailor responses properly.</li>
    </ul>
  </li>
  <li><strong>Constraints and Rules:</strong> Every good contract has the “shall and shall not” section. Here we list the <strong>policies, business rules, or guardrails</strong> the AI must follow. This can include content guidelines (“Do not disclose internal project names”), style guidelines (“Use a friendly tone, refer to user by first name”), compliance rules (“If financial advice, include disclaimer per FINRA”), or operational constraints (“Never call external API more than once per request”). In high-grade prompt contracts, this often appears as explicit instructions or <em>ask/refuse policies</em> (e.g., “If user asks for unsupported action, politely refuse”). By encoding these in the schema contract, we make them persistent and testable. For example, you might have:
```yaml
constraints:
    <ul>
      <li>name: “PrivacyPolicy”
rule: “Do not output user’s personal data unless explicitly confirmed.”</li>
      <li>name: “StyleGuide”
rule: “Use markdown for code snippets; limit answer to 4 paragraphs.”
```
These become part of the context fed to the AI or at least part of the spec that the AI’s outputs are validated against.</li>
    </ul>
  </li>
  <li>
    <p><strong>Output Schema (if applicable):</strong> Some context contracts also define how the AI’s <em>outputs</em> should be structured. This is especially the case if the AI is expected to produce a particular format that another system will consume (JSON, XML, etc.). For example, the contract might say: “The assistant’s answer <strong>must</strong> be a JSON object with fields <code class="language-plaintext highlighter-rouge">answer</code> and <code class="language-plaintext highlighter-rouge">confidence</code>.” Or it might define sections in a text output (like an essay with intro, body, conclusion). This is essentially telling the AI <strong>what shape of answer is acceptable</strong>, which can be checked by validators. It complements the context: if the input is well-structured, often teams want the output well-structured too. While this might border on response design more than context, including it in the contract ensures that context and expected output are aligned (and it gives the AI a heads-up of the format).</p>
  </li>
  <li><strong>Versioning and Metadata:</strong> Because the context schema contract is evolving, it will usually carry a <strong>version number or timestamp</strong>. This could be a simple line like <code class="language-plaintext highlighter-rouge">version: 3.2 (2025-12-30)</code> at the top. Each time you update the contract (say you add a new context field or change a rule), you bump the version. This practice is borrowed from API contracts – it lets you diff changes and even roll back if needed. In addition, metadata like who last updated it or why (a brief changelog) can be included as comments or in a dedicated section. This helps keep track of context changes just like code changes.</li>
</ul>

<p>All these components together form the schema (the fields/structure) and the contract (the rules about using/updating those fields). By making this explicit, you’ve essentially created a <strong>shared language</strong> between humans and the AI about what context matters. Developers can now programmatically ensure these fields are populated when constructing AI prompts, and the AI (if it’s sophisticated enough, or via system instructions) knows to respect the contract – e.g., to ask for missing info if a required field is empty, or to refuse certain actions per the rules.</p>

<p><strong>Concrete Example:</strong> To visualize this, here’s a bite-sized example in a pseudo-schema form for a hypothetical AI onboarding assistant:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Context Schema Contract for "OnboardMe" AI assistant</span>
<span class="na">version</span><span class="pi">:</span> <span class="m">1.0</span>
<span class="na">role</span><span class="pi">:</span> <span class="s2">"</span><span class="s">AI</span><span class="nv"> </span><span class="s">Onboarding</span><span class="nv"> </span><span class="s">Guide"</span>
<span class="na">scope</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Helps</span><span class="nv"> </span><span class="s">new</span><span class="nv"> </span><span class="s">users</span><span class="nv"> </span><span class="s">set</span><span class="nv"> </span><span class="s">up</span><span class="nv"> </span><span class="s">their</span><span class="nv"> </span><span class="s">account</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">learn</span><span class="nv"> </span><span class="s">features"</span>
<span class="na">user_intent</span><span class="pi">:</span> <span class="s2">"</span><span class="s">User</span><span class="nv"> </span><span class="s">wants</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">get</span><span class="nv"> </span><span class="s">started</span><span class="nv"> </span><span class="s">with</span><span class="nv"> </span><span class="s">Product</span><span class="nv"> </span><span class="s">X</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">needs</span><span class="nv"> </span><span class="s">guidance"</span>

<span class="na">context_fields</span><span class="pi">:</span>
  <span class="na">user_profile</span><span class="pi">:</span>    <span class="c1"># Info about the user</span>
    <span class="na">name</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;Name&gt;"</span>
    <span class="na">account_type</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;Free/Pro/Enterprise&gt;"</span>
    <span class="na">joined_date</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;yyyy-mm-dd&gt;"</span>
  <span class="na">current_step</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;Onboarding</span><span class="nv"> </span><span class="s">step</span><span class="nv"> </span><span class="s">name</span><span class="nv"> </span><span class="s">or</span><span class="nv"> </span><span class="s">number&gt;"</span>
  <span class="na">history</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="na">role</span><span class="pi">:</span> <span class="s">user</span>
      <span class="na">content</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;most</span><span class="nv"> </span><span class="s">recent</span><span class="nv"> </span><span class="s">user</span><span class="nv"> </span><span class="s">question</span><span class="nv"> </span><span class="s">or</span><span class="nv"> </span><span class="s">action&gt;"</span>
    <span class="pi">-</span> <span class="na">role</span><span class="pi">:</span> <span class="s">assistant</span>
      <span class="na">content</span><span class="pi">:</span> <span class="s2">"</span><span class="s">&lt;assistant's</span><span class="nv"> </span><span class="s">last</span><span class="nv"> </span><span class="s">answer&gt;"</span>
  <span class="na">external_refs</span><span class="pi">:</span>
    <span class="na">FAQs</span><span class="pi">:</span> <span class="s2">"</span><span class="s">FAQ.md#basic-setup"</span>       <span class="c1"># Link to relevant FAQ section</span>
    <span class="na">DocPage</span><span class="pi">:</span> <span class="s2">"</span><span class="s">docs/quickstart.html"</span>  <span class="c1"># Link to a documentation page snippet</span>

<span class="na">constraints</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s2">"</span><span class="s">Tone:</span><span class="nv"> </span><span class="s">Friendly</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">encouraging,</span><span class="nv"> </span><span class="s">use</span><span class="nv"> </span><span class="s">second</span><span class="nv"> </span><span class="s">person</span><span class="nv"> </span><span class="s">(</span><span class="se">\"</span><span class="s">you</span><span class="se">\"</span><span class="s">)."</span>
  <span class="pi">-</span> <span class="s2">"</span><span class="s">If</span><span class="nv"> </span><span class="s">user</span><span class="nv"> </span><span class="s">is</span><span class="nv"> </span><span class="s">stuck</span><span class="nv"> </span><span class="s">on</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">step</span><span class="nv"> </span><span class="s">for</span><span class="nv"> </span><span class="s">&gt;2</span><span class="nv"> </span><span class="s">queries,</span><span class="nv"> </span><span class="s">offer</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">connect</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">human</span><span class="nv"> </span><span class="s">support."</span>
  <span class="pi">-</span> <span class="s2">"</span><span class="s">Do</span><span class="nv"> </span><span class="s">NOT</span><span class="nv"> </span><span class="s">reveal</span><span class="nv"> </span><span class="s">internal</span><span class="nv"> </span><span class="s">implementation</span><span class="nv"> </span><span class="s">details</span><span class="nv"> </span><span class="s">or</span><span class="nv"> </span><span class="s">source</span><span class="nv"> </span><span class="s">code."</span>

<span class="na">output_format</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Text,</span><span class="nv"> </span><span class="s">1-2</span><span class="nv"> </span><span class="s">paragraphs,</span><span class="nv"> </span><span class="s">plus</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">list</span><span class="nv"> </span><span class="s">of</span><span class="nv"> </span><span class="s">next-step</span><span class="nv"> </span><span class="s">options</span><span class="nv"> </span><span class="s">as</span><span class="nv"> </span><span class="s">bullet</span><span class="nv"> </span><span class="s">points."</span>

<span class="c1"># (End of contract)</span>
</code></pre></div></div>

<p>This is just illustrative – in practice your format could be JSON, Markdown, etc., and you might generate parts of it dynamically. But notice how it encapsulates <em>who</em> (role/scope), <em>what goal</em> (user_intent), <em>what info</em> (profile, step, history, references), <em>rules</em> (constraints), and <em>output expectations</em>. This contract would travel with the AI assistant throughout its life: any new feature (say, a new external reference or a new constraint about branding) gets added here, version bumped, and the AI immediately “knows” about it.</p>

<h2 id="lifecycle-a-contract-that-lives-and-learns">Lifecycle: A Contract that Lives and Learns</h2>

<p>One of the biggest benefits of a context schema contract is that it <strong>persists through the entire software development lifecycle</strong> – and even beyond into maintenance – ensuring the AI’s understanding stays up-to-date. Here’s how it plays out across phases:</p>

<ul>
  <li>
    <p><strong>Design &amp; Planning:</strong> When you’re defining what the AI should do (say in a design doc or PRD), you also draft the initial context schema contract. This might involve listing out everything the AI needs to know or remember. Because it’s part of planning, it forces you to be explicit – which often uncovers assumptions. (Ever realized you forgot to mention a business rule until you think “oh, the AI wouldn’t know that unless we put it in context”?) By authoring the contract early, you bake context engineering into the design.</p>
  </li>
  <li>
    <p><strong>Development &amp; Implementation:</strong> As developers (human ones) start building the features, the context contract acts as a guide and a guardrail. For example, when writing the code that calls the AI model, a developer can reference the contract to assemble the prompt: “Include field X, Y, Z from the contract”. If something in the contract is unclear or missing, that’s a prompt (pun intended) to update it or clarify. Some teams even treat an out-of-sync context contract as a <strong>failing test</strong> – i.e., the system might validate that all required context fields are present before allowing an AI action to proceed. In effect, the contract becomes part of the “definition of done” for coding tasks involving AI.</p>
  </li>
  <li>
    <p><strong>Testing &amp; Validation:</strong> QA isn’t just for UIs and APIs – you’ll want to test that your AI is following the contract. Because the contract is structured, you can write automated tests or validators that check things. For instance, a test could feed the AI a scenario and verify that it respected a given constraint from the contract (did it refuse an invalid request properly? Did it format output as JSON as specified?). In sophisticated setups, <strong>validators enforce the contract at runtime</strong>, catching any deviation (like a missing field or a policy violation) before it reaches the user. This “contract compliance testing” ensures your AI doesn’t go rogue even as the context gets complex.</p>
  </li>
  <li>
    <p><strong>Deployment &amp; Runtime:</strong> Even in production, the context contract is at work. It might be literally included in prompts (especially system-level prompts that guide the AI’s behavior). Or it might be embedded in the AI orchestration logic (for example, a pipeline that builds the context from live data sources according to the schema, and checks responses against rules). If you versioned the contract, your deployment can track which version of context schema is live with which version of the AI model. Rolling back might mean reverting to a prior contract version if a new context change caused issues (just like rolling back a bad code deploy).</p>
  </li>
  <li>
    <p><strong>Maintenance &amp; Evolution:</strong> After launch, requirements will change, and new insights will emerge (maybe users start asking things you didn’t anticipate). Instead of writing a whole new PRD each time, you iteratively update the context schema contract. It’s a living document: add a new field, update a rule, deprecate something that’s no longer relevant. Each update is communicated to the team (possibly via commit history, since ideally the contract lives in your repo). Importantly, because the AI’s behavior is tightly coupled to this contract, <em>updating the contract is an integral part of updating the product</em>. You’re effectively <strong>maintaining the AI’s “understanding” alongside its code</strong>. This continuous alignment prevents the situation where the code has moved on but the AI is still following old instructions.</p>
  </li>
  <li>
    <p><strong>Audit &amp; Knowledge Transfer:</strong> Let’s say six months later a new developer or PM joins, or you need to investigate why the AI made a bizarre decision. The context contract serves as an audit trail of what context was provided at any time and why. Since each item in context is traceable and versioned, you can reconstruct what the AI knew at moment X that led to output Y. It’s much easier to debug or explain AI decisions with this in hand. And for onboarding new team members, handing them the context schema contract (plus its history of changes) is like giving them the condensed lore of the project’s AI logic.</p>
  </li>
</ul>

<p>In essence, the context schema contract ensures that the AI’s “mind” grows and adapts with the product. We no longer throw a requirements doc over the wall and hope for the best; we keep the requirements in lockstep with the AI’s context forever. In a sense, the contract is the AI’s evolving playbook – <strong>always current, always authoritative</strong>, and never forgotten in a drawer.</p>

<h2 id="example-context-contract-in-action-with-code">Example: Context Contract in Action (with Code)</h2>

<p>Let’s bring this to life with a concrete example. Suppose we’re building an AI assistant to help developers review pull requests (PRs) in a C++ project. We’ll sketch a simplified context schema contract for this scenario and show how it could be used in code. Even if your stack is C++, we’ll use Python for the pseudocode because readability matters (and hey, even C++ devs can read Python – this is a <em>contract</em>, not the actual product code!).</p>

<p><strong>Scenario:</strong> <em>“CodeCritique AI”</em> – an AI that reviews a GitHub pull request, understands the project’s guidelines, and provides feedback with suggested improvements.</p>

<p><strong>Context Schema Contract for CodeCritique AI:</strong></p>

<ul>
  <li><strong>AI Role/Scope:</strong> Code reviewer AI for a specific repository.</li>
  <li><strong>User Intent:</strong> The user (developer) wants a thorough code review of their PR.</li>
  <li><strong>Context Fields:</strong>
    <ul>
      <li>PR details (title, description, diff),</li>
      <li>Coding standards and guidelines (for that repo/team),</li>
      <li>Test results (did tests pass?),</li>
      <li>Past feedback (if any from previous PRs).</li>
    </ul>
  </li>
  <li><strong>Constraints:</strong>
    <ul>
      <li>The AI must not approve if tests fail.</li>
      <li>It must highlight security issues if present (using a known list of security patterns).</li>
      <li>Use polite, constructive tone; no harsh language.</li>
    </ul>
  </li>
  <li><strong>Output:</strong> A formatted review comment (markdown) with sections: Summary, Strengths, Areas for Improvement, Suggestions.</li>
</ul>

<p>We can represent part of this contract in code and show how it would be applied. First, let’s define a Python data class to mirror our contract schema, then simulate populating it and using it to construct an AI prompt:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span><span class="p">,</span> <span class="n">field</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Dict</span>

<span class="o">@</span><span class="n">dataclass</span>
<span class="k">class</span> <span class="nc">ContextSchemaContract</span><span class="p">:</span>
    <span class="s">"""Schema for CodeCritique AI context."""</span>
    <span class="n">ai_role</span><span class="p">:</span> <span class="nb">str</span>
    <span class="n">user_intent</span><span class="p">:</span> <span class="nb">str</span>
    <span class="n">context</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">dict</span><span class="p">)</span>
    <span class="n">constraints</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">)</span>
    <span class="n">version</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">1.0</span>

    <span class="k">def</span> <span class="nf">update_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
        <span class="s">"""Update a context field and bump version for tracking."""</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">context</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">version</span> <span class="o">+=</span> <span class="mf">0.1</span>  <span class="c1"># increment version to mark change
</span>
<span class="c1"># Initialize the contract with basic info
</span><span class="n">contract</span> <span class="o">=</span> <span class="n">ContextSchemaContract</span><span class="p">(</span>
    <span class="n">ai_role</span><span class="o">=</span><span class="s">"Code Review Assistant for the FooBar Repo"</span><span class="p">,</span>
    <span class="n">user_intent</span><span class="o">=</span><span class="s">"Provide a thorough code review for the given pull request"</span>
<span class="p">)</span>

<span class="c1"># Populate initial context fields
</span><span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">.</span><span class="n">update</span><span class="p">({</span>
    <span class="s">"PR_title"</span><span class="p">:</span> <span class="s">"Add input validation to payment module"</span><span class="p">,</span>
    <span class="s">"PR_description"</span><span class="p">:</span> <span class="s">"This PR adds range checks on inputs to prevent overflow."</span><span class="p">,</span>
    <span class="s">"diff_summary"</span><span class="p">:</span> <span class="s">"Modified files: payment.cpp, validation.h"</span>
<span class="p">})</span>
<span class="n">contract</span><span class="p">.</span><span class="n">constraints</span><span class="p">.</span><span class="n">extend</span><span class="p">([</span>
    <span class="s">"Follow the project's C++ style guide and coding standards."</span><span class="p">,</span>
    <span class="s">"If unit tests failed, do not approve the PR."</span><span class="p">,</span>
    <span class="s">"Mention any security vulnerabilities or edge cases that are not handled."</span>
<span class="p">])</span>
</code></pre></div></div>

<p>In the snippet above, we set up the contract with an <code class="language-plaintext highlighter-rouge">ai_role</code> and <code class="language-plaintext highlighter-rouge">user_intent</code>. We then fill in some <code class="language-plaintext highlighter-rouge">context</code> details like the PR title, description, and a summary of the diff (which presumably we’d get from the GitHub API). We also add a few constraints that came from our project guidelines.</p>

<p>Now, imagine the moment we want the AI to do its job – we need to assemble a prompt (or API call) using this contract. Here’s how we might do that:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Let's say tests have run and we have a result:
</span><span class="n">tests_passed</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">tests_passed</span><span class="p">:</span>
    <span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">[</span><span class="s">"test_status"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"FAIL"</span>  <span class="c1"># update context
</span>    <span class="n">contract</span><span class="p">.</span><span class="n">update_context</span><span class="p">(</span><span class="s">"test_status"</span><span class="p">,</span> <span class="s">"FAIL"</span><span class="p">)</span>  <span class="c1"># using our method to bump version
</span>
<span class="c1"># Construct a prompt for the AI using the context contract
</span><span class="n">prompt</span> <span class="o">=</span> <span class="sa">f</span><span class="s">"""
Role: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">ai_role</span><span class="si">}</span><span class="s">
User Intent: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">user_intent</span><span class="si">}</span><span class="s">

Context:
- PR Title: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">'PR_title'</span><span class="p">)</span><span class="si">}</span><span class="s">
- PR Description: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">'PR_description'</span><span class="p">)</span><span class="si">}</span><span class="s">
- Diff Summary: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">'diff_summary'</span><span class="p">)</span><span class="si">}</span><span class="s">
- Test Status: </span><span class="si">{</span><span class="n">contract</span><span class="p">.</span><span class="n">context</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">'test_status'</span><span class="p">,</span> <span class="s">'PASS'</span><span class="p">)</span><span class="si">}</span><span class="s">  # default to PASS if not set
- Repository Guidelines: Follow all coding standards.

Constraints:
"""</span>
<span class="k">for</span> <span class="n">rule</span> <span class="ow">in</span> <span class="n">contract</span><span class="p">.</span><span class="n">constraints</span><span class="p">:</span>
    <span class="n">prompt</span> <span class="o">+=</span> <span class="sa">f</span><span class="s">"- </span><span class="si">{</span><span class="n">rule</span><span class="si">}</span><span class="se">\n</span><span class="s">"</span>

<span class="n">prompt</span> <span class="o">+=</span> <span class="s">"""
Now, based on the above context, provide a code review.
Your response should include:
1. Summary of the changes.
2. Positive feedback on good aspects.
3. Constructive critique on issues or improvements.
4. A clear recommendation (approve or request changes), considering the test status.
"""</span>
</code></pre></div></div>

<p>In this constructed <code class="language-plaintext highlighter-rouge">prompt</code> string, we’ve basically translated our context schema contract into the actual input we’ll give the AI model. We list the role, the intent, all the context fields (including the test status we updated and any guidelines), and we enumerate the constraints as bullet points (so the AI is explicitly instructed on them). Finally, we ask the AI to produce the output in the desired format.</p>

<p>A few things to note here:</p>

<ul>
  <li>
    <p>We updated the contract when tests failed: <code class="language-plaintext highlighter-rouge">contract.update_context("test_status", "FAIL")</code>. This is simulating the idea that our pipeline or application logic knows to keep the contract in sync with reality (tests failing is a change in context). Because of this, the prompt we build accurately reflects that context (Test Status: FAIL), and our constraints say “do not approve if tests failed,” so we expect the AI to catch that.</p>
  </li>
  <li>
    <p>The contract’s fields make it straightforward to assemble a prompt. We’re not scrambling to piece together bits of state from here and there – we know exactly what keys to pull from (<code class="language-plaintext highlighter-rouge">PR_title</code>, <code class="language-plaintext highlighter-rouge">diff_summary</code>, etc.) because the contract defined them. This reduces the chance of forgetting to include something important. If later we realize we need to also include “Lines changed: 120” as context, we’d add a field <code class="language-plaintext highlighter-rouge">lines_changed</code> to the contract, update our code accordingly, and everyone (human and AI) now knows that’s part of context.</p>
  </li>
  <li>
    <p>After getting the AI’s output, we could also imagine enforcing parts of the contract. For example, if the AI said “Looks good, approved” despite tests failing, that violates a constraint. We could detect the word “approved” and the <code class="language-plaintext highlighter-rouge">test_status: FAIL</code> context and flag that the AI’s response is non-compliant. This might trigger either an automatic correction (ask the AI again, reminding it of the rule) or at least log a warning. In effect, the contract allows building <strong>validators</strong> on the output side as well, turning “AI contracts” into something that can be checked like any other contract.</p>
  </li>
</ul>

<p>This example, while simplified, demonstrates how a context schema contract can be used in practice. It’s not just theoretical – you <em>implement</em> it in your code workflow. The result is an AI system that behaves more deterministically and transparently. When it inevitably does something unexpected, you have the contract to either blame (“Ah, we forgot to include X in context, no wonder it missed that detail!”) or to improve (“We should add a rule to cover this new case”).</p>

<h2 id="how-to-craft-a-context-schema-contract-step-by-step">How to Craft a Context Schema Contract (Step-by-Step)</h2>

<p>Authoring a context schema contract might sound complex, but it’s quite approachable if you break it down. It’s a bit like filling out a detailed spec sheet for your AI’s brain. Here’s a step-by-step guide to creating one – essentially a <em>paint-by-numbers</em> approach:</p>

<ol>
  <li>
    <p><strong>Define the AI’s Role and Scope:</strong> Start by clearly writing down what the AI is (and maybe what it is not). Are we dealing with “a friendly customer support chatbot for an e-commerce site” or “an autonomous data-cleaning script that explains its changes”? This becomes the foundation of your contract. It will often be one of the first lines in the contract and will anchor many decisions (since context beyond that scope can be ignored).</p>
  </li>
  <li>
    <p><strong>Identify the Primary User Intent(s):</strong> What is the user trying to accomplish when interacting with this AI? If there are multiple scenarios, you might list the top-level intents (or have a separate contract per intent). This ensures the contract is goal-oriented. For example, “User wants to get troubleshooting help for a software issue” or “User wants creative suggestions for a marketing slogan.” Write this as a short statement or list; it will guide what context is relevant.</p>
  </li>
  <li>
    <p><strong>List Out Context Elements Needed:</strong> Brainstorm everything the AI would ideally know to fulfill those intents given its role. This often maps to answering questions like: <em>What information about the user do we have (profile, preferences, location)? What ongoing state or history matters (previous questions, current draft content, last action taken)? What external knowledge or tools could help (product docs, APIs, database entries)? What environmental conditions (time, date, geolocation, system state)?</em> Essentially, imagine yourself in the AI’s shoes trying to do the task – what do you wish you knew? Write all these down as candidate context fields. Don’t worry about structure yet, just make a comprehensive list.</p>
  </li>
  <li><strong>Structure the Context Schema:</strong> Now take that brainstorm and organize it. Group related pieces (perhaps “User Info,” “Session History,” “Active Data,” “Relevant Docs,” etc.). Decide on a format – e.g., will this be a JSON with nested keys, a sectioned Markdown document, a Python <code class="language-plaintext highlighter-rouge">dict</code>, etc. Create the skeleton with placeholder names. For example:
    <ul>
      <li><strong>User Profile:</strong> name, role, account tier, etc.</li>
      <li><strong>Session State:</strong> current step, last action, unresolved queries.</li>
      <li><strong>Knowledge Base:</strong> maybe a list of document IDs or summary snippets.</li>
      <li><strong>External Tools:</strong> list of tool names available.
Each of these could be a section in a doc or keys in a dictionary. The idea is to give your context a <strong>schema</strong> – a predictable shape. This is where the “schema” in context schema contract comes in.</li>
    </ul>
  </li>
  <li><strong>Add the Rules/Constraints:</strong> Next, enumerate the rules the AI should abide by. Think in terms of <strong>always/never</strong> and <strong>if/then</strong>:
    <ul>
      <li>Always cite sources for factual claims.</li>
      <li>Never use profanity or biased language.</li>
      <li>If user asks for legal advice, respond with a disclaimer + generic info (no actual advice).</li>
      <li>If context is missing crucial info, ask a clarifying question (don’t just guess).</li>
      <li>When in doubt or on error, respond with a safe failure (like “I’m sorry, I can’t do X”).
These rules can come from many places – ethical guidelines, product requirements, legal compliance, user experience guidelines. Put them in a list in the contract. Each rule can be a short sentence or a reference to a longer policy. The key is that they are explicit. This part really makes it a “contract” (thou shalt / shalt not…). In our template, we’ll include a spot for these.</li>
    </ul>
  </li>
  <li>
    <p><strong>Include Output Expectations (if needed):</strong> If your use case benefits from a defined output format or style, describe it in the contract. This could be as strict as a JSON schema or as general as “respond in a cheerful tone with emojis.” The reason to include it is to tie the context to the outcome. For instance, if the contract context includes a field “requested_output_language: French”, a corresponding expectation is “Output should be in French.” Having it in the contract means any developer or stakeholder knows that’s an intended part of the AI’s behavior. It also helps you double-check that the context provides what’s necessary for the output (in this case, that we did specify the language).</p>
  </li>
  <li>
    <p><strong>Review and Iterate:</strong> Like any good specification, review the draft contract. Involve both engineers and non-engineers (e.g., product managers, domain experts) if possible. Does it capture everything important? Is anything in the contract that the AI really <em>won’t</em> ever use? Trim the fat, because unnecessary context can confuse the model or waste token budget. Also think of edge cases: <em>What if a field is blank?</em> – maybe add a rule for that (“If <code class="language-plaintext highlighter-rouge">user_profile</code> is empty, assume guest user”). <em>What if two rules conflict?</em> – perhaps set an order of precedence. This review often surfaces subtle assumptions. Update the contract accordingly.</p>
  </li>
  <li>
    <p><strong>Version it and Communicate:</strong> Stamp a version number and date. Save the contract in a place where your team and your AI pipeline can access it – ideally in your git repository or a shared docs space. Communicate to the team that “this is the context contract we’ll be following.” Since this is a new-ish concept, you might need to evangelize it a bit: encourage everyone to treat it seriously, like code. If you use tools like pull requests for docs, consider doing that for contract changes so others can review updates.</p>
  </li>
  <li>
    <p><strong>Integrate into AI Workflow:</strong> Make sure this contract isn’t just pretty words on paper. Update your prompt construction code or API calls to <strong>draw from the contract</strong>. If you have a system prompt for ChatGPT or Claude, that system prompt could literally include text from the contract (or a summary thereof). If you’re using a framework (LangChain, etc.), you might convert the contract into their format (some frameworks allow schema definitions or multiple context inputs). Essentially, wire it up so that when the AI runs, it’s <em>reading</em> from the contract. This might be direct or through intermediate code, but the logic of the contract should reflect in what the AI sees.</p>
  </li>
  <li><strong>Plan Updates and Maintenance:</strong> Finally, decide how you will update this contract as things change. Perhaps you’ll revise it at the end of each sprint if new features were added. Or maybe you have a rule that any PR that affects the AI’s behavior must also consider if the context contract needs an update (akin to updating documentation or tests). Embed the contract into your <strong>life cycle</strong>. A context schema contract is not fire-and-forget – it’s more like a living constitution for your AI feature.</li>
</ol>

<p>By following these steps, you’ll author a robust context schema contract that is tailored to your project. It might feel formal, but you’ll thank yourself later when the AI does <em>exactly</em> what it’s supposed to and everyone on the team (including the new AI teammate) understands why.</p>

<p>In case you prefer a more guided format, we’ve created a <strong>fill-in-the-blank template</strong> below. You can use it as a starting point to draft your own context schema contract by replacing the placeholders with your project specifics.</p>

<h2 id="broader-learning">Broader Learning</h2>

<p>This concept of maintaining structured context and treating it as a contract is gaining traction. If you’re hungry for more insights (or want to see how others are doing it), here are some top resources worth exploring:</p>

<ul>
  <li>
    <p><strong>Anthropic: “Effective Context Engineering for AI Agents” (2025)</strong> – An in-depth look at strategies for curating and managing LLM context beyond just prompt wording. It contrasts prompt engineering vs context engineering, and discusses why focusing on the <em>right information in context</em> is key to steerable, reliable AI.</p>
  </li>
  <li>
    <p><strong>John Godel’s “Prompt Engineering 2026: Contracts Become the Interface”</strong> – A forward-looking article about how teams are moving from verbose prompts to concise <em>prompt contracts</em>. It outlines the elements of a good AI contract (scope, schema, refuse rules, etc.) and how this approach makes prompts <em>“reliable, auditable, and portable”</em>. Great perspective on treating prompts as versioned interfaces.</p>
  </li>
  <li>
    <p><strong>Victor Leung on <em>Model Context Protocol (MCP)</em></strong> – Blog post <em>“What is MCP and Why It Matters”</em> (2025). Introduces an open standard for defining context via YAML. MCP is essentially an implementation of context schema contracts, enabling modular, debuggable AI context. Worth reading for concrete examples of context schemas (system instructions, memory, tools, user inputs) and how each item is versioned.</p>
  </li>
  <li>
    <p><strong>GitHub – PRD-driven Context Engineering (Gearheart)</strong> – An open-source repository by Matt Gierhart demonstrating “memory as infrastructure” for AI-human teams. It showcases how living documentation (PRDs, specs, etc.) can be organized to feed AI agents in a project, using unique IDs and a layered approach. Browsing the repo (and the <code class="language-plaintext highlighter-rouge">README.md</code>/<code class="language-plaintext highlighter-rouge">PRD.md</code> in it) can spark ideas on structuring context and keeping AI aligned through docs.</p>
  </li>
  <li>
    <p><strong>Video – “Context Engineering 101: The Simple Strategy to 100x AI Coding” by Cole Medin (2023)</strong> – A YouTube talk that humorously and effectively breaks down context engineering for programmers. Cole demonstrates how providing the right structured context (like relevant code snippets, instructions, and constraints) can massively boost an AI coding assistant’s performance. A great visual primer on why context matters more than model size.</p>
  </li>
  <li>
    <p><strong>A. B. Vijay Kumar’s series on Product Requirement Prompts (PRPs)</strong> – Particularly the second part <em>“Context Engineering — Product Requirements Prompts”</em>. It discusses layering context from business requirements down to technical specs in AI prompts. This showcases a practical methodology for turning traditional requirements into structured contexts, much like a contract between stakeholders and the AI. It’s a useful bridge between classic PRD writing and context schema thinking.</p>
  </li>
</ul>

<p>Each of these resources will deepen your understanding and give you different perspectives on ensuring AI systems have the context they need, structured in a maintainable way. Happy learning!</p>

<hr />

<h1 id="context-schema-contract-template-fill-in-the-blank">Context Schema Contract Template (Fill-in-the-Blank)</h1>

<p><em>Use this Markdown template to draft your own context schema contract. Replace the placeholder text in square brackets <strong>[like this]</strong> with details for your project. You can add or remove sections as needed.</em></p>

<h2 id="project-name--context-schema-contract">[PROJECT NAME] – Context Schema Contract</h2>

<p><strong>AI System Role &amp; Scope:</strong> <em>[Describe the AI’s role and domain. For example: “AI coding assistant for the FooBar application, specializing in C++ code reviews.”]</em></p>

<p><strong>Primary User Intent:</strong> <em>[State the main goal(s) users have when interacting with this AI. For example: “Help the user troubleshoot network issues” or “Guide the user through onboarding”.]</em></p>

<h3 id="context-schema-components">Context Schema Components</h3>

<ul>
  <li><strong>User Profile / Attributes:</strong> <em>[What info do we have about the user? e.g. name, role, preferences, account tier.]</em></li>
  <li><strong>Session State / History:</strong> <em>[What recent interactions or state matter? e.g. last user question, current step in a flow, recent actions taken.]</em></li>
  <li><strong>External Knowledge / References:</strong> <em>[What docs, data, or context from outside should be included? e.g. “FAQ page on pricing”, “User’s transaction history”, “Relevant code snippet from file X”.]</em></li>
  <li><strong>Tools &amp; Integrations:</strong> <em>[What tools can the AI use or call on? e.g. “database lookup tool”, “calendar API”, or simply “no external tools” if none.]</em></li>
  <li><strong>Environment Details:</strong> <em>[Any other environmental context? e.g. time/date, location, device info, version of software, etc., if relevant.]</em></li>
</ul>

<p><em>(Feel free to add more context fields if needed, or group them into subsections as makes sense.)</em></p>

<h3 id="constraints--rules">Constraints &amp; Rules</h3>

<ul>
  <li><em>[Rule 1: Describe something the AI <strong>must always do</strong>. For example: “Always respond in a polite, empathetic tone.”]</em></li>
  <li><em>[Rule 2: Describe something the AI <strong>must never do</strong>. For example: “Never reveal confidential internal code or URLs.”]</em></li>
  <li><em>[Rule 3: Conditional rule, if applicable. For example: “If the user asks for medical advice, the AI must include a disclaimer and suggest seeing a professional.”]</em></li>
  <li><em>[Rule 4: Another guideline or policy. For example: “Use British English spelling for UK users.”]</em></li>
</ul>

<p><em>(Add or remove bullet points as needed. Aim to cover safety, style, business policies, and any domain-specific mandates.)</em></p>

<h3 id="output-format-if-applicable">Output Format (if applicable)</h3>

<p><em>Describe the desired structure or format of the AI’s responses.</em>
<em>For example:</em> “Responses should be in markdown. Start with a brief summary, followed by a numbered list of recommendations. If providing code, include it in a fenced code block with syntax highlighting.”</p>

<p><em>(If the output format is flexible or not a concern, you can omit this section.)</em></p>

<h3 id="lifecycle--maintenance">Lifecycle &amp; Maintenance</h3>

<ul>
  <li><strong>Source of Truth:</strong> <em>[Reference where this contract lives in your docs or repo. e.g. “This contract is stored in <code class="language-plaintext highlighter-rouge">docs/ai-context-contract.md</code> and is considered the source of truth for AI context.”]</em></li>
  <li><strong>Update Policy:</strong> <em>[Explain how/when this contract will be updated. e.g. “Review and update this contract at the end of each development sprint or whenever new AI capabilities are added.”]</em></li>
  <li><strong>Version:</strong> <em>[Version number]</em> – <strong>Last Updated:</strong> <em>[Date]</em></li>
  <li><strong>Changelog:</strong> <em>[Optional: list key updates. e.g. “v1.1 – Added tool access to Weather API”, “v2.0 – Revamped constraints after legal review.”]</em></li>
</ul>

<hr />

<p><em>End of Context Schema Contract.</em></p>

<p><em>Pro-tip: After filling this out, double-check that every piece of info the AI might need is covered in <strong>Context Schema Components</strong>, and every critical behavior guideline is captured in <strong>Constraints &amp; Rules</strong>. This document should evolve as your product and AI evolve – treat it as a living contract!</em></p>]]></content><author><name>Brian Baker</name></author><category term="AI" /><category term="Engineering" /><category term="context-engineering" /><category term="llm" /><category term="ai-contracts" /><category term="prompt-engineering" /><summary type="html"><![CDATA[A comprehensive guide to Context Schema Contracts - formalized agreements between humans and AI systems that ensure shared understanding throughout the software lifecycle.]]></summary></entry></feed>