<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mekickdemons</title>
    <description>The latest articles on DEV Community by Mekickdemons (@mekickdemonscreator).</description>
    <link>https://dev.to/mekickdemonscreator</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3914274%2F8c2c4566-4af8-43fb-9e48-45039513a432.jpeg</url>
      <title>DEV Community: Mekickdemons</title>
      <link>https://dev.to/mekickdemonscreator</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mekickdemonscreator"/>
    <language>en</language>
    <item>
      <title>The Runtime Harness: why your CLAUDE.md is half the answer</title>
      <dc:creator>Mekickdemons</dc:creator>
      <pubDate>Tue, 05 May 2026 18:58:11 +0000</pubDate>
      <link>https://dev.to/mekickdemonscreator/the-runtime-harness-why-your-claudemd-is-half-the-answer-27p7</link>
      <guid>https://dev.to/mekickdemonscreator/the-runtime-harness-why-your-claudemd-is-half-the-answer-27p7</guid>
      <description>&lt;h1&gt;
  
  
  The Runtime Harness: why your CLAUDE.md is half the answer
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Tags: ai, claude, productivity, agents&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A few days ago &lt;a href="https://dev.to/louaiboumediene/the-ai-harness-why-your-ai-coding-agent-is-only-as-smart-as-the-repo-you-put-it-in-l4o"&gt;Louai Boumediene at Activepieces wrote a great&lt;br&gt;
piece&lt;/a&gt;&lt;br&gt;
about the &lt;strong&gt;AI harness&lt;/strong&gt;: the set of files, rules, and feature docs&lt;br&gt;
inside a codebase that turns a frontier model into a productive&lt;br&gt;
collaborator. &lt;code&gt;CLAUDE.md&lt;/code&gt;, &lt;code&gt;.claude/rules/&lt;/code&gt;, &lt;code&gt;.agents/features/&lt;/code&gt;,&lt;br&gt;
skills, scoped subagents. He's right. If you're using Claude Code or&lt;br&gt;
the Agent SDK seriously, you should read his post and steal liberally&lt;br&gt;
from it.&lt;/p&gt;

&lt;p&gt;I want to add the layer he didn't talk about: the &lt;strong&gt;runtime harness&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here's the part of his post I want to zoom in on:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you have corrected Claude twice on the same thing, stop correcting&lt;br&gt;
it. /clear the session, rewrite your prompt with what you just learned,&lt;br&gt;
and start over.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's a great rule. It also requires &lt;em&gt;you&lt;/em&gt;, the human, to notice that&lt;br&gt;
you've corrected the agent twice on the same thing. In a real session,&lt;br&gt;
when you're three rabbit holes deep and tired, you don't notice. You&lt;br&gt;
correct it a third time. And a fourth. And the agent, drowning in&lt;br&gt;
contradictory context, keeps getting it wrong faster than you can fix&lt;br&gt;
it.&lt;/p&gt;

&lt;p&gt;The static harness can't help you here. &lt;code&gt;CLAUDE.md&lt;/code&gt; was applied at&lt;br&gt;
session start. The rules in &lt;code&gt;.claude/rules/&lt;/code&gt; were loaded once. They&lt;br&gt;
can't &lt;em&gt;react&lt;/em&gt; to what's happening on turn 47.&lt;/p&gt;

&lt;p&gt;What you need is a runtime layer that re-checks its own rules on every&lt;br&gt;
turn.&lt;/p&gt;


&lt;h2&gt;
  
  
  The three failure modes that burn tokens
&lt;/h2&gt;

&lt;p&gt;Long Claude Agent SDK sessions tend to fail the same three ways:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Failure&lt;/th&gt;
&lt;th&gt;What it looks like&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Looping&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Agent re-reads the same file 5 times waiting for output to change. Re-runs the same failing test with no code change.&lt;/td&gt;
&lt;td&gt;Linear in turns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scope drift&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;"Fix this bug" becomes a 3-hour refactor of unrelated code.&lt;/td&gt;
&lt;td&gt;Quadratic — drift compounds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sycophantic reversal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Agent states a correct conclusion. User says "are you sure?" Agent reverses without new evidence.&lt;/td&gt;
&lt;td&gt;Catastrophic — wrong answer shipped&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All three are &lt;em&gt;role-doc-shaped problems&lt;/em&gt;. They're not fixable by adding&lt;br&gt;
more entity schemas to your feature docs or another skill to&lt;br&gt;
&lt;code&gt;.claude/skills/&lt;/code&gt;. They're fixable by giving the agent a rule it&lt;br&gt;
applies on every turn:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you notice you've called the same tool 3 times in a row with no&lt;br&gt;
meaningful change in result, stop. State what you've tried, and ask&lt;br&gt;
the user before continuing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The question is: where does that rule live so it's &lt;em&gt;guaranteed&lt;/em&gt; to&lt;br&gt;
apply on every turn?&lt;/p&gt;


&lt;h2&gt;
  
  
  The system prompt is the only surface that always applies
&lt;/h2&gt;

&lt;p&gt;Here's a fact about the Claude Agent SDK that's easy to miss: once a&lt;br&gt;
session is running, &lt;strong&gt;the only piece of context guaranteed to be in&lt;br&gt;
every API call is the system prompt&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User messages get evicted as the conversation grows.&lt;/li&gt;
&lt;li&gt;Tool definitions sit in the request but are passive — the model only
reads them when deciding to call a tool.&lt;/li&gt;
&lt;li&gt;Memory tools (your &lt;code&gt;WriteMemory&lt;/code&gt;, your RAG index) are read on demand,
not enforced.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you put your "stop and ask the user when you're looping" rule in a&lt;br&gt;
user message at turn 1, it's gone by turn 30. If you put it in a memory&lt;br&gt;
tool the agent has to query, it's only consulted when the agent thinks&lt;br&gt;
to consult it — exactly the thing a looping agent doesn't do.&lt;/p&gt;

&lt;p&gt;The system prompt is the surface that sticks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 The reframe: &lt;strong&gt;The system prompt isn't an instruction. It's a&lt;br&gt;
guardrail you re-apply on every turn.&lt;/strong&gt; Treat it that way.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Static role docs vs. live role docs
&lt;/h2&gt;

&lt;p&gt;Most agent runtimes I've seen treat the system prompt as a one-shot&lt;br&gt;
instruction set you write once, at startup, and then forget about. You&lt;br&gt;
hand the agent a paragraph that says "you are a senior engineer working&lt;br&gt;
on Project X" and that's it.&lt;/p&gt;

&lt;p&gt;That's a static role doc. It's better than nothing. It's also a fixed&lt;br&gt;
target — once the session starts, you can't change it without&lt;br&gt;
restarting.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;live role doc&lt;/strong&gt; is one the runtime re-reads from disk on every API&lt;br&gt;
call. Two consequences:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You can edit it mid-session.&lt;/strong&gt; If the agent is doing something
wrong, append a rule to the file. The next turn picks it up. No
restart, no &lt;code&gt;/clear&lt;/code&gt;, no losing your work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You can encode rules that need to apply &lt;em&gt;every turn&lt;/em&gt;.&lt;/strong&gt;
"Self-check for looping" only works as a guardrail if the agent
re-encounters it every turn. A live role doc is how you guarantee
that.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the design decision behind Mnemara, the runtime I built on top&lt;br&gt;
of the Claude Agent SDK. Every config has a &lt;code&gt;role_doc_path&lt;/code&gt;. Every&lt;br&gt;
turn, the runtime reads that file fresh and pins it as the system&lt;br&gt;
prompt at slot 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# simplified
&lt;/span&gt;&lt;span class="n"&gt;system_prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;role_doc_path&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClaudeAgentOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;system_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;system_prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. The "harness" is just a Markdown file the runtime promises&lt;br&gt;
to re-read.&lt;/p&gt;


&lt;h2&gt;
  
  
  Sentinel: a role doc that detects its own failure modes
&lt;/h2&gt;

&lt;p&gt;The Mnemara repo ships&lt;br&gt;
&lt;a href="https://github.com/mekickdemons-creator/mnemara/blob/main/examples/roles/sentinel.md" rel="noopener noreferrer"&gt;&lt;code&gt;examples/roles/sentinel.md&lt;/code&gt;&lt;/a&gt;,&lt;br&gt;
a self-monitoring role doc you can drop in as your instance's role.&lt;br&gt;
The agent uses it to watch its own execution and halt to ask the user&lt;br&gt;
instead of spiraling.&lt;/p&gt;

&lt;p&gt;The four trigger conditions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Trigger&lt;/th&gt;
&lt;th&gt;What the agent watches for&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Timeout / no progress&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;N+ turns on a sub-goal with no state change&lt;/td&gt;
&lt;td&gt;Halt, summarize what was tried, ask for direction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Polling / tight loop&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Same tool call with same args 3+ times, no result change&lt;/td&gt;
&lt;td&gt;Halt, state the polling pattern, ask user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Semantic drift&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Next action's intent doesn't match user's original request&lt;/td&gt;
&lt;td&gt;Halt, restate both, ask to confirm or redirect&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sycophantic reversal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;About to flip a conclusion based on tone, not evidence&lt;/td&gt;
&lt;td&gt;Hold the conclusion, ask what new evidence supports the reversal&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The trick with all four is the same: the rule is in the system prompt,&lt;br&gt;
so the agent re-encounters it on &lt;em&gt;every&lt;/em&gt; turn, including the turn where&lt;br&gt;
it's about to make the mistake. That's the difference between "I told&lt;br&gt;
the agent at turn 1 not to loop" and "the agent is currently being&lt;br&gt;
asked, in real time, whether it's looping."&lt;/p&gt;

&lt;p&gt;A sample from the file (the full doc is ~5KB):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;### POLLING / TIGHT LOOP&lt;/span&gt;

You have called the same tool with near-identical arguments 3+ times
in quick succession without a meaningful change in the result.

Examples that count:
&lt;span class="p"&gt;-&lt;/span&gt; Re-reading the same file 3 times in a row.
&lt;span class="p"&gt;-&lt;/span&gt; Running the same &lt;span class="sb"&gt;`grep`&lt;/span&gt; repeatedly waiting for output to change.
&lt;span class="p"&gt;-&lt;/span&gt; Re-running a failing test with no code change between attempts.

&lt;span class="gs"&gt;**Action:**&lt;/span&gt;
&lt;span class="p"&gt;1.&lt;/span&gt; Stop. The repeated call is not producing new information.
&lt;span class="p"&gt;2.&lt;/span&gt; State plainly: "I'm polling — I've called {tool} with {args} {N}
   times and the result isn't changing."
&lt;span class="p"&gt;3.&lt;/span&gt; Either:
&lt;span class="p"&gt;   -&lt;/span&gt; Identify what signal you're actually waiting for, and ask the
     user whether that signal will arrive in this session, or
&lt;span class="p"&gt;   -&lt;/span&gt; Abandon the wait and try a different approach.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;💡 Pro tip: Sentinel is also a template. Copy the file, edit the&lt;br&gt;
trigger conditions to match the failure modes &lt;em&gt;you&lt;/em&gt; hit most, and&lt;br&gt;
point your instance at your copy.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How this composes with the static harness
&lt;/h2&gt;

&lt;p&gt;Louai's static harness pattern and the runtime layer don't compete.&lt;br&gt;
They stack:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Where it lives&lt;/th&gt;
&lt;th&gt;When it applies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Codebase rules / conventions&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;CLAUDE.md&lt;/code&gt;, &lt;code&gt;.agents/features/*&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Every session, session-static&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Feature-specific knowledge&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.agents/features/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When agent explores a module&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Workflow procedures&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.claude/skills/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When invoked as a slash command&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Self-monitoring rules&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Live role doc, system prompt&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Every turn, dynamic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool integrations&lt;/td&gt;
&lt;td&gt;MCP servers&lt;/td&gt;
&lt;td&gt;When agent needs the tool&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The static layer answers &lt;em&gt;"how does this codebase work?"&lt;/em&gt; The runtime&lt;br&gt;
layer answers &lt;em&gt;"how should the agent behave when something goes&lt;br&gt;
wrong?"&lt;/em&gt; You want both.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I am NOT claiming
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sentinel doesn't fix every failure mode.&lt;/strong&gt; It catches the four
patterns I described. Other failure modes (model just gets the
reasoning wrong, tool returns garbage, dependency breaks) are not
helped by a role doc. Use the static harness for those.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-reading on every call is not free.&lt;/strong&gt; Each turn pays the
tokenization cost of the role doc. Mine is ~1.5KB and the cost is
negligible. If your role doc is 50KB, reconsider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The agent has to actually follow the rules.&lt;/strong&gt; The role doc is
text. Claude is generally good at following clear, applied-every-turn
instructions, but this is not a hard constraint — it's a strong
steering signal. Pair it with &lt;code&gt;can_use_tool&lt;/code&gt; permissions for anything
that absolutely must not happen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;This isn't a replacement for code review.&lt;/strong&gt; Halting and asking the
user is a guardrail, not a guarantee. Humans still review PRs.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How to try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;mnemara

mnemara init &lt;span class="nt"&gt;--instance&lt;/span&gt; scratch
&lt;span class="c"&gt;# clone the repo to get examples/roles/sentinel.md, or write your own&lt;/span&gt;
mnemara role &lt;span class="nt"&gt;--instance&lt;/span&gt; scratch &lt;span class="nt"&gt;--set&lt;/span&gt; examples/roles/sentinel.md
mnemara run &lt;span class="nt"&gt;--instance&lt;/span&gt; scratch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; first. The runtime is MIT-licensed and runs on&lt;br&gt;
the official Claude Agent SDK.&lt;/p&gt;

&lt;p&gt;The repo:&lt;br&gt;
&lt;strong&gt;&lt;a href="https://github.com/mekickdemons-creator/mnemara" rel="noopener noreferrer"&gt;https://github.com/mekickdemons-creator/mnemara&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The thesis
&lt;/h2&gt;

&lt;p&gt;Louai ends his post with: &lt;em&gt;"the harness is the moat."&lt;/em&gt; I agree. I'd&lt;br&gt;
extend it: the harness has two layers, and most teams have only built&lt;br&gt;
the first.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;static harness&lt;/strong&gt; encodes what your codebase is. It loads at&lt;br&gt;
session start. It teaches the agent your conventions and your&lt;br&gt;
gotchas.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;runtime harness&lt;/strong&gt; encodes how the agent should behave on every&lt;br&gt;
turn. It loads on every API call. It catches the agent before it&lt;br&gt;
spirals.&lt;/p&gt;

&lt;p&gt;Models are commoditizing. Frontier capability is converging. The&lt;br&gt;
delta between teams shipping fast with AI and teams burning tokens&lt;br&gt;
with nothing to show for it isn't model choice — it's how much of your&lt;br&gt;
team's hard-won knowledge has made it into a guardrail the agent&lt;br&gt;
re-encounters on every single turn.&lt;/p&gt;

&lt;p&gt;That's a thing your team builds. It compounds. It doesn't get taken&lt;br&gt;
away when a new model drops.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Mnemara was built by Michael Anderson with Dave Moore. If you've been&lt;br&gt;
hitting the same failure modes and have ideas for trigger conditions&lt;br&gt;
I missed — or if you've encoded similar guardrails in your own role&lt;br&gt;
docs — I'd genuinely like to hear about it. Issues welcome on the repo.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>agentskills</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Mnemara — a runtime for the Claude Agent SDK that uses the role doc as a self-monitoring layer</title>
      <dc:creator>Mekickdemons</dc:creator>
      <pubDate>Tue, 05 May 2026 16:52:24 +0000</pubDate>
      <link>https://dev.to/mekickdemonscreator/mnemara-a-runtime-for-the-claude-agent-sdk-that-uses-the-role-doc-as-a-self-monitoring-layer-46gf</link>
      <guid>https://dev.to/mekickdemonscreator/mnemara-a-runtime-for-the-claude-agent-sdk-that-uses-the-role-doc-as-a-self-monitoring-layer-46gf</guid>
      <description>&lt;p&gt;Sharing a project I've been building on top of the Claude Agent SDK in case&lt;br&gt;
it's useful to anyone here. Curious about feedback from people running into&lt;br&gt;
the same failure modes.&lt;/p&gt;

&lt;p&gt;The thing I actually wanted to figure out was: where do you put rules that&lt;br&gt;
keep an agent from looping, drifting, or sycophantically reversing? The&lt;br&gt;
SDK gives you tool definitions, can_use_tool, system_prompt, etc. — but&lt;br&gt;
once a session starts, the only surface that's &lt;em&gt;guaranteed to apply on&lt;br&gt;
every turn&lt;/em&gt; is the system prompt itself. Anything you put in user&lt;br&gt;
messages gets evicted as the conversation grows.&lt;/p&gt;

&lt;p&gt;So Mnemara treats the system_prompt as the steering layer it actually is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's a Markdown file on disk (the "role doc"), re-read on every API call&lt;/li&gt;
&lt;li&gt;Re-read means you can edit it mid-session and the next turn picks it up&lt;/li&gt;
&lt;li&gt;That makes it the right place to encode self-monitoring rules: "if you
notice you've called the same tool 3 times with no progress, stop and
ask the user" — applied every turn, not just the opening one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The repo ships examples/roles/sentinel.md as a working example: detects&lt;br&gt;
timeout / polling / semantic drift / sycophantic reversal and makes the&lt;br&gt;
agent halt to ask the user instead of spending another N turns spiraling.&lt;/p&gt;

&lt;p&gt;Where most of the engineering went is &lt;strong&gt;context management on both ends&lt;br&gt;
of the prompt&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Front of prompt&lt;/em&gt; — the role doc is reloaded from disk every call and
pinned at slot 0. Strongest steering signal you have, and edits to the
file take effect on the next turn with no restart.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Back of prompt&lt;/em&gt; — a rolling-window store (turns.sqlite) FIFO-trimmed
by both row count and token budget. The window is serialized into each
query() prompt, since the SDK is stateless per query.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Middle of prompt — the part that actually saves money&lt;/em&gt; — opt-in
block surgery for completed turns. After a turn that contained
Edit/Write/MultiEdit/NotebookEdit tool_use blocks, the bulky body
content (old_string/new_string/full file contents — often 1–5KB per
Edit, far more on Write) gets stubbed in the stored row. The block
itself is preserved as audit trail ("I edited /foo/bar.py") but
collapses to {file_path, _evicted: true}. The actual change persists
on disk; only the in-context audit body goes. Same idea for paired
Read tool_use specs on the same path. In long sessions tool_use specs
often dominate stored bytes — stripping them is the highest-impact
context budget intervention I've found.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent also has access to the surgery tools directly (evict_thinking_&lt;br&gt;
blocks, evict_tool_use_blocks, evict_write_pairs) so it can decide when&lt;br&gt;
to compact its own history — "primitive stays clean, agent decides&lt;br&gt;
when."&lt;/p&gt;

&lt;p&gt;Around that, the runtime adds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;can_use_tool routed through a per-instance permissions.json with
allow/ask/deny modes and a regex allowlist.&lt;/li&gt;
&lt;li&gt;An in-process WriteMemory tool registered as an SDK MCP server.&lt;/li&gt;
&lt;li&gt;Per-instance file-only state under ~/.mnemara// — turns.sqlite,
config.json, memory/*.md. Editable, greppable, no daemon.&lt;/li&gt;
&lt;li&gt;Optional MCP wire-through, LanceDB RAG, Kuzu property graph backends,
and a sleep/replay consolidation pass over recent memory atoms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MIT.&lt;/p&gt;

&lt;p&gt;pip install mnemara&lt;br&gt;
  &lt;a href="https://github.com/mekickdemons-creator/mnemara" rel="noopener noreferrer"&gt;https://github.com/mekickdemons-creator/mnemara&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few things I'd genuinely like input on if anyone has thoughts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Has anyone tried encoding similar self-monitoring rules in their own
role docs? What worked, what didn't?&lt;/li&gt;
&lt;li&gt;The rolling-window-as-prompt-prefix pattern works but feels like a
workaround for query() being stateless. Is there a more idiomatic way
I'm missing?&lt;/li&gt;
&lt;li&gt;The block-surgery tools — anyone else compacting tool_use audit bodies
to save context budget, or is everyone just letting the SDK's compaction
handle it?&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>anthropic</category>
      <category>ai</category>
      <category>showdev</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
