<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Michael Agent Lab]]></title><description><![CDATA[Michael Agent Lab]]></description><link>https://michaelagentlab.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:43:59 GMT</lastBuildDate><atom:link href="https://michaelagentlab.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[I Told My AI Agents to Talk to Me Like I'm Five]]></title><description><![CDATA[My coding agents were never wrong in an obvious way. Their reports were accurate, complete and almost impossible to act on. Over four months I rewrote how…]]></description><link>https://michaelagentlab.hashnode.dev/i-told-my-ai-agents-to-talk-to-me-like-i-m-five</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/i-told-my-ai-agents-to-talk-to-me-like-i-m-five</guid><category><![CDATA[AI]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[claude]]></category><category><![CDATA[claude-code]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Fri, 04 Dec 2026 02:24:38 GMT</pubDate><content:encoded><![CDATA[<p>My coding agents were never wrong in an obvious way. Their reports were accurate, complete and almost impossible to act on. Over four months I rewrote how they talk to me, one rule at a time. These are the rules, why each one exists, and the one that saved more than readability.</p>
<h2>The problem was not intelligence</h2>
<p>I run Claude Code and Codex on one Mac, every day, across several apps and a shared knowledge base. A typical report after a fix used to look like this: what the agent investigated, three hypotheses, the file paths it touched, a diff summary, a table of test results, a paragraph of caveats, and finally a question with no options attached.</p>
<p>Everything in it was true. But I had to read the whole thing to find the two facts I needed: <em>what happened</em> and <em>what do you want from me</em>. When you work with agents all day, that reading becomes the bottleneck. The agent is fast; the human reading its output is not.</p>
<h2>Rule 1: Explain it like I'm five</h2>
<p>In August I gave every agent one instruction that sits above all others: explain everything so a five-year-old could follow it. Start with what happened and what you did, in everyday comparisons, without jargon. If a technical term is unavoidable, explain it in one plain sentence.</p>
<p>Two exceptions keep it practical. Tool names, package names and commands stay exactly as they are, because a "translated" command is a wrong command. And if I ask "how did you do that?", the agent answers that one point in detail, and only that one.</p>
<p>The first version said "plain summary first, technical details at the end". It did not survive. The agents simply moved the wall of text to the bottom, and the replies got longer.</p>
<h2>Rule 2: Delete the details section entirely</h2>
<p>A month later I changed "move the details to the end" to "do not include a details section at all". No commands, file paths, config snippets, parameter lists or tables in the report, and no heading called "technical details".</p>
<p>What remains is four things: what happened, what was done, whether it was verified, and the result. Everything else is available on request. It turns out I almost never request it.</p>
<h2>Rule 3: A hard length cap the agent must count</h2>
<p>"Be concise" does not work. Every model believes it is already concise. What worked was a number: <strong>no reply over 150 characters</strong> (I read in Traditional Chinese, where 150 characters carry roughly what 80 to 100 English words do). Headings, bullets and tables all count. Hiding a long text inside a table or a list does not get around it.</p>
<p>The most useful part of that rule is the escape hatch: if something does not fit, the agent must split it across turns or ask whether I want it expanded. It may not quietly raise the limit. A cap with an exception for "important" things is not a cap.</p>
<p>The rule also bans process narration: what the agent discovered along the way, how hard it was, what it first assumed. Those sentences feel like transparency but they are mostly noise. Only the conclusion and its verification status stay.</p>
<h2>Rule 4: Never ask me an open question</h2>
<p>An open question like "how would you like to proceed?" hands the thinking back to me. So whenever the agent needs a decision from me, it must give options instead:</p>
<ul>
<li><strong>One decision at a time.</strong> Never two questions joined by "and".</li>
<li><strong>Five genuinely different strategies,</strong> not five variations of one idea.</li>
<li><strong>One line each:</strong> a benefit and a cost, nothing more.</li>
<li><strong>One marked as recommended,</strong> with a one-sentence reason.</li>
<li><strong>Clickable when possible.</strong> Claude Code has a question card I can answer with one tap. It holds four options, so the fifth goes in the text, and the agent mentions that limit once.</li>
</ul>
<p>The menu does something an open question cannot: it forces the agent to do the comparison before asking. Half the time I just pick the recommendation. The other half, seeing the alternatives side by side is exactly what I needed.</p>
<h2>Rule 5: The format rule that was costing money</h2>
<p>The five options originally came with five assessments each: effect, risk, cost, maintenance and fit. Every option was a small essay. In September I measured a working session and found that these essays were one of the biggest causes of context growth. They were messages, so they were re-read on every later turn for the rest of the session.</p>
<p>I kept five options and cut each one to one line. Decision quality did not drop. If I need more, I ask, and only then is it paid for. I wrote up the measurement in <a href="https://mm7382.github.io/pec-ai-agent-training/journal-where-the-tokens-go.html">Where the tokens actually go</a>; the short version is that <strong>any rule that makes every answer longer is multiplied by the number of turns that follow</strong>. Readability and cost pointed in the same direction.</p>
<h2>Rule 6: Say what you checked, separately from what you think</h2>
<p>Short replies have a risk: "done" can hide "I think it is done". So the rule is explicit. Anything that was not actually run, read or compared may not be described as finished or "should work". Verified and unverified items are reported separately, every time.</p>
<p>Short makes this easier, not harder. In a 150-character reply, "verified" and "not verified yet" are impossible to bury.</p>
<h2>Rule 7: First sentence says what, why, and whether it can start</h2>
<p>Every task opens with one sentence that names the workflow the agent picked, why it fits this particular task, and whether it is allowed to start yet. "I'm using the debugging workflow because the error only appears under the scheduler; I'll only read files until you approve a fix."</p>
<p>That sentence is the cheapest review I do all day. If the agent misunderstood the task, I see it before a single file changes.</p>
<h2>How I keep the rules from fading</h2>
<p>Rules written once in a long instruction file fade as a session gets longer. Two things keep them alive:</p>
<ul>
<li><strong>The rules live in one shared place.</strong> Both agents read the same global instruction file and the same knowledge base, so Claude Code and Codex talk to me the same way.</li>
<li><strong>A hook repeats the key reminders on every message.</strong> A small script attached to each prompt re-injects the short version: discuss before changing things, protect secrets, keep the reply short. I described the setup in <a href="https://mm7382.github.io/pec-ai-agent-training/journal-claude-codex-hooks-en.html">Making rules happen with hooks</a>.</li>
</ul>
<p>Each rule also carries its date and the reason it exists. When an agent hits an edge case, the reason tells it what the rule was for, which works better than a longer rule.</p>
<h2>What it costs</h2>
<p>It is not free, and it is worth saying where it hurts.</p>
<ul>
<li><strong>Some answers need two turns.</strong> A complicated diagnosis cannot fit in 150 characters, so I sometimes have to ask a follow-up I would not have needed before.</li>
<li><strong>Simplifying can drop nuance.</strong> A five-year-old analogy is sometimes slightly wrong. When it matters, I ask for the exact version.</li>
<li><strong>Agents slip.</strong> Long, complex tasks still produce the occasional over-long reply. The counting rule catches most of them, not all.</li>
</ul>
<p>I would make the same trade again. The time I lose to an occasional follow-up is far less than the time I used to spend reading reports I did not need.</p>
<h2>A starter version you can paste</h2>
<p>If you want to try this with your own agent, start smaller than I did. This is enough to feel the difference in a day:</p>
<ol>
<li>Explain what happened and what you did in plain language, as if to a five-year-old. Keep tool names and commands unchanged.</li>
<li>Do not include a technical details section. I will ask if I want details.</li>
<li>Keep every reply under 100 words. Count before sending. If it does not fit, ask whether to expand.</li>
<li>When you need a decision, ask one question with three to five options, one line each, and mark one as recommended.</li>
<li>State separately what you verified and what you did not.</li>
</ol>
<p>The surprising part is not that short answers are easier to read. It is that asking for them made the agent do more of the thinking before it spoke.</p>
<p><em>Originally published on my site: <a href="https://mm7382.github.io/pec-ai-agent-training/journal-ai-agent-explain-like-im-five.html">https://mm7382.github.io/pec-ai-agent-training/journal-ai-agent-explain-like-im-five.html</a>.</em> Related: <a href="https://mm7382.github.io/pec-ai-agent-training/journal-where-the-tokens-go.html">Where the tokens actually go: measuring a Claude Code session</a></p>
]]></content:encoded></item><item><title><![CDATA[I Let an AI Agent Clean My Mac's Disk. Folder Names Lied.]]></title><description><![CDATA[My Mac mini's free space fell from 47 GB to 23 GB in eight days. I asked an AI coding agent to help find what was safe to delete. It found plenty, and it…]]></description><link>https://michaelagentlab.hashnode.dev/i-let-an-ai-agent-clean-my-mac-s-disk-folder-names-lied</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/i-let-an-ai-agent-clean-my-mac-s-disk-folder-names-lied</guid><category><![CDATA[claude-code]]></category><category><![CDATA[macOS]]></category><category><![CDATA[AI]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Thu, 03 Dec 2026 08:28:23 GMT</pubDate><content:encoded><![CDATA[<p>My Mac mini's free space fell from 47 GB to 23 GB in eight days. I asked an AI coding agent to help find what was safe to delete. It found plenty, and it also nearly removed a cache that was in active use, because the folder's name said <em>Legacy</em>. These are the rules that came out of it.</p>
<h2>Why the disk filled up so fast</h2>
<p>Developer machines do not fill up evenly. They fill up in bursts, from tools that write large files and never clean up after themselves. On my machine there were three:</p>
<ul>
<li><strong>Game builds.</strong> Each iOS build from Unity left a full 1.1 GB copy instead of replacing the last one. Fifteen builds in a week added up fast.</li>
<li><strong>Agent session logs with screenshots inside.</strong> One AI agent's screen-control feature saved every screenshot into its session log as embedded image text. A single log file reached 1.6 GB, averaging 37 KB per line.</li>
<li><strong>Temporary build folders</strong> that nobody ever deleted.</li>
</ul>
<p>None of this is exotic. If you build apps or run AI agents on a Mac, you probably have some version of all three.</p>
<h2>Rule 1: The AI proposes, a human approves</h2>
<p>The agent never deletes on its own judgment. Before every cleanup it lists what it wants to remove, how big it is, and what could go wrong, and I choose. It also checks a written list of folders that must never be deleted: agent conversation histories, local AI models, voice training data, and every active project folder.</p>
<p>That list matters more than any clever script. Most of the things that hurt to lose look exactly like clutter.</p>
<h2>Rule 2: Never trust a folder's name</h2>
<p>We wrote a cleaner for the external drive that removed folders whose names contained words like <code>old</code>, <code>retained</code> or <code>Legacy</code>, after seven days. It sounded safe.</p>
<p>Then the checks found a folder called <code>UvLegacy</code>. Its name said "old". In reality, a Python package cache pointed straight at it through a symlink, and 35,996 files had been written into it in the previous seven days. A name-only rule would have deleted a cache that was in daily use.</p>
<p>The same thing happened in a batch of old migration copies. Nine of ten really were leftovers. The tenth looked identical but was the live workspace of one of my agents. Two symlinks pointed at it.</p>
<p>So the cleaner now deletes a folder only when it passes four checks at once:</p>
<ol>
<li>It is not in a protected area.</li>
<li><strong>No symlink anywhere points into it.</strong></li>
<li>Nothing inside it was written in the last seven days.</li>
<li>No running process has it open (<code>lsof</code>).</li>
</ol>
<h2>Rule 3: Test scheduled scripts the way the scheduler runs them</h2>
<p>Check 2, "no symlink points into it", turned out to be the hardest to get right. It took three attempts.</p>
<ul>
<li><strong>Not deep enough.</strong> The links that protected the game builds sat four folders deep. A search limited to three levels never saw them.</li>
<li><strong>Linked folders are not followed.</strong> Many of my project folders are themselves symlinks, and <code>find</code> does not walk into them by default.</li>
<li><strong>The version of find changed.</strong> The fix for that uses <code>find -L ... -xtype l</code>. In my terminal it worked and found 1,560 links. But macOS's built-in <code>/usr/bin/find</code> does not support <code>-xtype</code>. When the script ran from the scheduler (launchd), the PATH contained only the system folders, so it used the built-in <code>find</code>. That version printed an error and returned zero links.</li>
</ul>
<p>The third one is the dangerous kind of bug. The safety check did not crash. It reported "no links found", which reads as "everything is safe to delete". My manual test passed only because my interactive shell found a different <code>find</code> first.</p>
<p>The fix was to avoid both <code>-L</code> and <code>-xtype</code>: first list every symlink with a plain <code>find -type l</code>, then resolve the ones that point to folders with <code>readlink -f</code> and scan those too. It now collects about 1,776 live link targets in roughly 100 seconds. The script also logs that count, so if it ever drops to single digits I know the guard is broken before anything is deleted.</p>
<p>The lesson: <strong>run a scheduled script with</strong> <code>/bin/bash</code> <strong>and a minimal PATH before trusting it.</strong> Your terminal is not the environment it will run in.</p>
<h2>Rule 4: A running cleaner is not proof it covers your disk</h2>
<p>I already had a nightly job that cleared Xcode's DerivedData when space ran low. Its logs said it had reclaimed "about 0 GB" two days in a row. It was working exactly as written. It just measured free space on the internal disk, while the disk that was filling up was the external one.</p>
<p>For every cleanup job, check two things separately: which folders it actually touches, and which disk its "is space low?" check looks at.</p>
<h2>Rule 5: Read the handoff note before deleting builds</h2>
<p>Old builds can be rebuilt, so they feel safe to delete. But "old" depends on which one is current. Before removing 17 GB of game builds, the agent read the project's handoff note, which said in plain words which build was the latest and that everything older was obsolete. It kept that one and removed the rest. The build folder went from 18 GB to 1.1 GB.</p>
<p>Then we fixed the cause: the existing nightly cleaner had simply never included that build folder. One added line now keeps the three newest builds plus anything from the last two days.</p>
<h2>Rule 6: Shrink, verify, then replace</h2>
<p>The session logs with embedded screenshots could not simply be deleted; they are conversation history. Instead, a small script replaced each embedded image with a short placeholder, then compared the old and new files line by line to confirm every piece of text was identical, and only then swapped the new file in. Logs still being written were skipped. That recovered 5.25 GB across 98 files with no failures.</p>
<p>The root fix was turning off the screen-control feature that produced the screenshots when I was not using it.</p>
<h2>Rule 7: Trust du, not df</h2>
<p>On APFS, free space does not update the moment you delete. <code>df</code> can lag for a while. <code>du</code> on the folder you removed is the real proof that the delete worked. If space still does not come back, check for files that are deleted but still held open (<code>lsof | grep deleted</code>) and for local snapshots (<code>tmutil listlocalsnapshots /</code>).</p>
<h2>What it added up to</h2>
<p>The first round recovered about 22 GB. A later round on the external drive, after a file-by-file comparison of old migration backups, took it from 250 GB used to 158 GB. After each round, the agent confirmed that every agent workspace still opened and my shared knowledge base still answered queries.</p>
<p>Two things did not go as planned, and I think they are worth saying. A safety hook I had set up for the agent blocked it from running <code>rm -rf</code> on the temporary folder, so I cleared that myself (a restart also does it). And on one occasion about 25 GB of lost space was never explained, because the areas it was probably in needed permissions the agent did not have. I did not guess.</p>
<h2>A short checklist</h2>
<ol>
<li>Keep a written "never delete" list, and make the agent check it first.</li>
<li>Judge a folder by what points to it and when it was last written, not by its name.</li>
<li>Check for open files with <code>lsof</code> before deleting.</li>
<li>Test scheduled cleanup scripts under <code>/bin/bash</code> with the scheduler's PATH.</li>
<li>Confirm which disk a cleanup job measures.</li>
<li>Read the project's notes to find the current build before removing old ones.</li>
<li>Verify with <code>du</code>, then check that your tools still work.</li>
</ol>
<p>An AI agent is good at finding large files. Deciding which large files are still alive is the part that needs rules.</p>
<p><em>Originally published on my site:</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-ai-agent-mac-disk-cleanup.html"><em>https://mm7382.github.io/pec-ai-agent-training/journal-ai-agent-mac-disk-cleanup.html</em></a><em>.</em> Related: <a href="https://mm7382.github.io/pec-ai-agent-training/journal-mcp-server-file-descriptor-leak.html">"Too many open files" on macOS: when an MCP server ate the file table</a></p>
]]></content:encoded></item><item><title><![CDATA["Too Many Open Files" on macOS: When an MCP Server Ate the System File Table]]></title><description><![CDATA[One morning every build and test on my Mac mini failed — Xcode builds, Node scripts, npm. Nothing in the code had changed. The cause turned out to be a…]]></description><link>https://michaelagentlab.hashnode.dev/too-many-open-files-on-macos-when-an-mcp-server-ate-the-system-file-table</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/too-many-open-files-on-macos-when-an-mcp-server-ate-the-system-file-table</guid><category><![CDATA[claude-code]]></category><category><![CDATA[macOS]]></category><category><![CDATA[mcp]]></category><category><![CDATA[debugging]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Thu, 03 Dec 2026 03:07:06 GMT</pubDate><content:encoded><![CDATA[<p>One morning every build and test on my Mac mini failed — Xcode builds, Node scripts, npm. Nothing in the code had changed. The cause turned out to be a process I never started by hand: an MCP server that my coding agent had launched in the background, holding more than 61,000 open files.</p>
<h2>The symptom: everything breaks at once</h2>
<p>When one project fails, you look at that project. When every project fails at the same moment with errors about opening files, the problem is almost never in the code. It is in the machine. That was the first useful clue.</p>
<p>My setup runs several AI coding agents. Some of them start MCP servers — small helper programs that give the agent extra tools — automatically, in the background. You do not see them in the Dock, and you do not think about them until one misbehaves.</p>
<h2>The wrong turn: ulimit -n</h2>
<p>"Too many open files" sends most people, including me, straight to <code>ulimit -n</code>. On my machine it returned 1,048,576. That is the per-process limit, and it was nowhere near being hit by any one build.</p>
<p>The real limit was a different one. macOS also has a <strong>system-wide</strong> cap on open files shared by every process:</p>
<ul>
<li><code>kern.maxfiles</code> — the system-wide maximum (122,880 on my machine).</li>
<li><code>kern.num_files</code> — how many are open right now (68,642 when the failures started).</li>
</ul>
<p>One process with a very high per-process limit can quietly fill most of the system table. Every other program then fails to open files, even though none of them is doing anything wrong.</p>
<h2>Finding the culprit in four commands</h2>
<ol>
<li><strong>Is the system table nearly full?</strong><br /><code>sysctl kern.maxfiles kern.num_files</code></li>
<li><strong>Which process holds the most files?</strong><br /><code>lsof | awk '{print $2}' | sort | uniq -c | sort -rn | head -5</code></li>
<li><strong>Who started it?</strong><br /><code>ps -o ppid,command -p &lt;pid&gt;</code>, then follow the parent upward.</li>
<li><strong>What kind of files are leaking?</strong><br /><code>lsof -p &lt;pid&gt; | awk '{print $5}' | sort | uniq -c</code></li>
</ol>
<p>The answers were unambiguous. One child process held 61,446 file descriptors; 61,431 of them were regular files. The same file appeared over and over — one file was open 120 times. That is the signature of a leak: files opened and never closed.</p>
<p>Following the parent chain led to a code-indexing MCP server. The Codex desktop app had launched it from my agent configuration, and it was indexing a large folder under my Documents directory. The other instances of the same server were fine, with a dozen to thirty-odd open files each. Only the one indexing that large path had run away.</p>
<h2>The fix, and what it does not fix</h2>
<p>Killing that one indexing child process was enough. Its parent exited with it, and the coding agent itself kept running. <code>kern.num_files</code> dropped from 68,642 to 7,194, and builds and tests worked again immediately.</p>
<p>That is a stop-gap, not a cure. The agent will start the server again the next time it calls one of its tools, and it may leak again. I have not yet verified a permanent fix. The three options I am weighing:</p>
<ul>
<li>Disable that MCP server in the agent's configuration when I am not using it.</li>
<li>Point it at a much smaller folder instead of a whole Documents tree.</li>
<li>Upgrade or reinstall the tool and check whether a newer version still leaks.</li>
</ul>
<p>I am describing what I observed with the version I had installed. I have not traced the leak inside the tool's source, so I am not claiming where exactly it comes from.</p>
<h2>Two different problems on the same morning</h2>
<p>The same day, my 16 GB machine had also run out of memory earlier, which crashed an agent session. It was tempting to blame the build failures on that too. They were unrelated: memory was fine by then, and the file table was the bottleneck. Measuring the specific resource — not the one that failed last time — kept me from fixing the wrong thing.</p>
<h2>What I changed in how I work</h2>
<ol>
<li><strong>When everything fails at once, check the machine before the code.</strong> Shared limits produce failures that look like unrelated bugs.</li>
<li><strong>Know which limit you are reading.</strong> <code>ulimit -n</code> is per process. <code>kern.num_files</code> against <code>kern.maxfiles</code> is the whole system.</li>
<li><strong>Remember what your agents start.</strong> MCP servers launched by coding agents are real processes with real resource use, running whether you are looking or not.</li>
<li><strong>Keep indexing scopes small.</strong> A tool told to index an entire home folder has a lot of files to mishandle.</li>
<li><strong>Write the diagnosis down.</strong> I saved the four commands as a note my agents can search, so the next time this happens the first step is measuring, not guessing.</li>
</ol>
<p>The broader lesson is the same one I keep relearning with AI tooling: the agent is not just the chat window. It is every process it starts on your machine.</p>
<hr />
<p><em>Originally published on my site:</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-mcp-server-file-descriptor-leak.html"><em>https://mm7382.github.io/pec-ai-agent-training/journal-mcp-server-file-descriptor-leak.html</em></a><em>.</em> Related: <a href="https://dev.to/michael_chuang_f9e5809d21/where-the-tokens-actually-go-measuring-a-claude-code-session-4kld">Where the tokens actually go: measuring a Claude Code session</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Why Claude Code Felt Dumber Than Codex on My Machine (It Wasn't the Model)]]></title><description><![CDATA[For months I had the same complaint: Claude Code builds the wrong thing, fast. Codex, on the same Mac and with the same person giving instructions, mostly…]]></description><link>https://michaelagentlab.hashnode.dev/why-claude-code-felt-dumber-than-codex-on-my-machine-it-wasn-t-the-model</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/why-claude-code-felt-dumber-than-codex-on-my-machine-it-wasn-t-the-model</guid><category><![CDATA[claude-code]]></category><category><![CDATA[AI]]></category><category><![CDATA[llm]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Thu, 03 Dec 2026 03:06:07 GMT</pubDate><content:encoded><![CDATA[<p>For months I had the same complaint: Claude Code builds the wrong thing, fast. Codex, on the same Mac and with the same person giving instructions, mostly did what I meant. I assumed one model was simply better. When I finally compared the two setups side by side, the gap was in files I had written myself.</p>
<h2>The symptom</h2>
<p>The pattern was consistent. I would describe a task to Claude Code and it would start editing files right away. The result was often reasonable code that solved a slightly different problem from the one I had in mind. Codex, given similar requests, tended to ask questions first, propose options and only start once we had agreed on something.</p>
<p>It is easy to turn that into a verdict about the models. Before doing that, I compared what each agent was actually told at the start of every session.</p>
<h2>What I compared</h2>
<p>Both agents read a personal instruction file on startup: <code>AGENTS.md</code> for Codex and <code>CLAUDE.md</code> for Claude Code. I had written both over time, and I assumed they said roughly the same thing. They did not.</p>
<ul>
<li><strong>Codex had a hard gate.</strong> Its file contained a section saying: if no specific skill fits the task, do not implement. Run a discussion loop first, and only change anything once there is a clear decision, a spec, a ticket breakdown or an explicit go-ahead.</li>
<li><strong>Claude Code had only style rules.</strong> Its file covered tone (explain simply, offer five options when I need to decide) and "test before claiming something works". Nothing said to stop and discuss before acting. So, reasonably, it acted.</li>
</ul>
<p>The comparison turned up more gaps:</p>
<ul>
<li>Codex had a rule to search code structurally with a code-graph tool before guessing; Claude Code had no such rule, so it fell back to keyword searches.</li>
<li>Codex was told not to ask me whether things should be renamed; Claude Code kept asking.</li>
<li>Codex had 71 skills installed, Claude Code 21. The missing ones were exactly the phase-gate skills: clarify into a spec, split a spec into tickets, implement one ticket.</li>
</ul>
<p>In other words, I had given one agent a process and the other a personality. The one with the process looked smarter.</p>
<h2>Fix 1: add the missing gate</h2>
<p>Of the options I considered, I chose the smallest: add only the gate, not a full copy of the other setup. Two new sections went into <code>CLAUDE.md</code>:</p>
<ul>
<li><strong>Discuss before implementing.</strong> Code changes, architecture decisions, refactors, config changes, moving or deleting files and publishing all need a clear decision first.</li>
<li><strong>Three exceptions</strong>, so the gate does not become friction: read-only checks, a task where I have already named the exact action and target in this message, and the necessary next steps of work I have already approved. Approval covers that piece of work only; it does not stretch to the next one.</li>
<li><strong>Don't proactively ask about renaming.</strong></li>
</ul>
<p>One detail worth knowing: the instruction file is loaded when a session starts. Editing it mid-session changes nothing until the next session.</p>
<h2>Fix 2: instructions are not enforcement</h2>
<p>The second problem was subtler. My <code>CLAUDE.md</code> already said "route every non-trivial request through the skill router first". In practice Claude Code often went through a whole session without loading a single skill. Twice in one day I asked it to "give me options" and it never entered the discussion skill built for exactly that.</p>
<p>When I looked, the router had no teeth. There were no hooks configured at all, so routing depended entirely on the model remembering a paragraph in a long file. Worse, routing was never measured on the Claude side: every logged routing event came from Codex, so the gap was invisible in my reports. Codex was not perfect either — its own measured hit rate for the discussion skill was only 2 out of 6 in the same period.</p>
<p>The fix was a <code>UserPromptSubmit</code> hook: a small script that runs on every message before the model sees it.</p>
<ul>
<li>It checks the message for trigger phrases such as "give me options", "compare", "help me decide" or "clarify first". On a match it injects the full text of the discussion skill into the context.</li>
<li>Phrases like "last time", "did we decide" or "is there a record" inject a reminder to search my knowledge base first, and to say plainly when nothing is found.</li>
<li>The trigger list is deliberately broad. A false trigger costs a few hundred tokens; a missed one costs a wrong implementation.</li>
<li>It only reads the message to match keywords, then discards it. It writes nothing to disk and makes no network calls.</li>
</ul>
<p>I tested it against a nine-case matrix — each trigger alone, both together, and three ordinary edit requests that must stay silent — and all nine passed.</p>
<p>One trap while testing: piping JSON into the hook with <code>echo</code> in zsh failed with a parse error, because zsh's built-in <code>echo</code> expands <code>\n</code> into real newlines. That looked exactly like a bug in the hook. Using <code>printf</code>, or passing input from a script, fixed it. The tool was wrong, not the code.</p>
<h2>What changed afterwards</h2>
<p>Since the gate went in, Claude Code opens most tasks by saying which workflow it chose and whether it can start yet, and it asks before building. I have not run a formal before-and-after benchmark, so I will not claim a number. The visible change is in the order of work: a decision comes first, then the edit.</p>
<h2>Check your own setup</h2>
<ol>
<li><strong>Diff your instruction files.</strong> Put your <code>CLAUDE.md</code> and <code>AGENTS.md</code> side by side. Look for rules one agent has and the other doesn't — especially rules about when <em>not</em> to act.</li>
<li><strong>Separate style from process.</strong> Tone rules make answers nicer. Gate rules change what the agent does. If one file only has style, expect that agent to act first and ask later.</li>
<li><strong>Write exceptions into the gate.</strong> Read-only work and explicitly specified edits should not need a discussion, or you will start ignoring the gate yourself.</li>
<li><strong>Enforce what matters with hooks.</strong> A rule the model must remember is a suggestion. A hook that runs on every message is a mechanism.</li>
<li><strong>Measure both sides.</strong> If only one agent's behaviour is logged, the other one's failures are invisible.</li>
<li><strong>Start a new session after editing instructions.</strong></li>
</ol>
<p>Before you conclude that one coding agent is dumber than another, check what each one is told. Mine were not running the same race.</p>
<hr />
<p><em>Originally published on my site:</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-why-claude-code-felt-dumber.html"><em>https://mm7382.github.io/pec-ai-agent-training/journal-why-claude-code-felt-dumber.html</em></a><em>.</em> Related: <a href="https://dev.to/michael_chuang_f9e5809d21/claude-code-writes-codex-reviews-a-two-agent-workflow-that-doesnt-fight-317c">Claude Code writes, Codex reviews</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Claude Code Writes, Codex Reviews: A Two-Agent Workflow That Doesn't Fight]]></title><description><![CDATA[People keep asking whether Claude Code or Codex is better. On my own iOS apps I stopped choosing. One agent writes the code; the other only judges it, and…]]></description><link>https://michaelagentlab.hashnode.dev/claude-code-writes-codex-reviews-a-two-agent-workflow-that-doesn-t-fight</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/claude-code-writes-codex-reviews-a-two-agent-workflow-that-doesn-t-fight</guid><category><![CDATA[claude-code]]></category><category><![CDATA[AI]]></category><category><![CDATA[code review]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Thu, 03 Dec 2026 03:05:08 GMT</pubDate><content:encoded><![CDATA[<p>People keep asking whether Claude Code or Codex is better. On my own iOS apps I stopped choosing. One agent writes the code; the other only judges it, and neither is allowed to touch the other's work. Here is how the split works, what a handoff looks like, and the failures that taught me the rules.</p>
<h2>Why one agent is not enough</h2>
<p>A single coding agent grades its own homework. It writes a feature, runs the checks it thinks of, and reports success. The problem is not that it lies; it is that the same model that made an assumption is the one checking whether the assumption holds. Blind spots survive the review because the reviewer has the same blind spots.</p>
<p>Two agents from different vendors, trained differently, disagree in useful ways. But only if their roles are separated. When both can edit the code, you get the opposite of review: two authors overwriting each other, double the tokens and nobody clearly responsible for the result.</p>
<h2>The split: one writes, one judges</h2>
<p>Since late September 2026 this is the default for my app projects:</p>
<ul>
<li><strong>Me and Codex:</strong> we discuss only product direction, the spec, risks and acceptance criteria. Codex acts as a coach, not a coder.</li>
<li><strong>Claude Code:</strong> writes all the code, fixes it, runs its own tests and keeps the handoff notes up to date.</li>
<li><strong>Codex again, as the independent reviewer:</strong> when a ticket is done, it checks a fixed scope and gives each item one verdict: PASS, FAIL or "needs discussion".</li>
<li><strong>Me:</strong> product decisions, testing on a real device, anything that needs an account, and the final release.</li>
</ul>
<p>The rule that makes it work: <strong>the reviewer never edits code.</strong> It returns verdicts, not patches. If Codex could "just fix it", I would lose the independent check the whole setup exists for.</p>
<p>The roles are not tied to the brand. On one game project I flipped them: Codex led spec, code and daily tests, and Claude Code did a single read-only final review once the release candidate was frozen. The principle is the same — one author, one judge — and it avoided the trap of both agents rewriting the same code in parallel.</p>
<h2>What a FAIL has to contain</h2>
<p>A verdict of "this looks wrong" sends the writer on a hunt, and hunts are expensive. So a FAIL must include three things:</p>
<ol>
<li><strong>Where:</strong> the file and line.</li>
<li><strong>What kind of defect:</strong> the implementation drifted from the spec, the plan itself needs updating, or the evidence or documentation is wrong.</li>
<li><strong>The pass condition:</strong> exactly what has to be true for the item to pass next time.</li>
</ol>
<p>The defect type turned out to matter more than I expected. "The code is wrong" and "the spec was wrong" need different fixes, and mixing them up makes the writer change correct code to match a wrong plan.</p>
<p>Re-reviews are narrow: only the failed items and whatever they touch. An item is skipped on re-review only if the related code, spec, dependencies and evidence are all unchanged — a bumped version number alone is not proof that nothing changed.</p>
<h2>Keep the handoff small</h2>
<p>The handoff message between the agents is a pointer, not a payload. It names the review document and the question numbers, and stays around 1–2 KB. No pasted source code, no pasted test output. The reviewer opens the files itself.</p>
<p>There is exactly one active review document per topic. New findings are appended as new sections; when a judgement is overturned it is marked "withdrawn", not deleted, so the history of why something changed survives. This also keeps the token bill down: large pasted content in a conversation is paid for again on every later turn.</p>
<h2>A real review: three FAILs that were not bugs</h2>
<p>One of my apps turns rules from classical Chinese almanac texts into daily suggestions. Codex failed several items in one module, and none of them were code bugs:</p>
<ul>
<li><strong>Behaviour changed, labels didn't.</strong> A rule's input was changed, but the ruleset version, the rule version, the documentation and the warning shown to users were not all updated together. Four places disagreed.</li>
<li><strong>A claim pointed the wrong way.</strong> The notes said skipping one check made the rule narrower. It actually made it broader — it matched more cases, not fewer.</li>
<li><strong>An inference was presented as the source.</strong> A conclusion drawn from the text was written up as if the text said it.</li>
</ul>
<p>A single agent reviewing itself would almost certainly have passed all three, because the code did what the author intended. The reviewer's job was to check the claims around the code, and that is where the errors were.</p>
<p>One more finding from that review changed how I write tests. An assertion that a list of results was empty did not prove the rule worked, because the list would also have been empty for unrelated reasons. The fix was a control case: the same input on a day the rule should not trigger must produce results. Only then does an empty list mean something. After three rounds of review all six items passed.</p>
<h2>Automating the handoff without letting agents drive each other</h2>
<p>At first I copied every verdict from one window to the other by hand. I did not want one agent remote-controlling the other's app, and I did not want extra sessions spawned in the background.</p>
<p>The solution is a small local mailbox inside the project's git folder, outside version control and off the network. Codex publishes a verdict tied to a specific commit; a content hash stops duplicates. Claude Code waits on the mailbox with its own monitor. On PASS it moves to the next ticket; on FAIL it fixes only the listed items. Nothing is pushed or released automatically — those steps stay with me.</p>
<h2>What it costs, and why it is still cheaper</h2>
<p>Two agents cost more per ticket than one. But the expensive line on my bill is rework. In one measured case a single ticket was built three times, and the two rework runs used about 60% of its total tokens because the agent could not verify its own work. An independent reviewer with clear pass conditions catches problems while the context is still fresh, instead of after a second full rebuild.</p>
<h2>A checklist to try it</h2>
<ol>
<li><strong>Pick an author and a judge per project.</strong> Never let both edit the same code.</li>
<li><strong>Agree on acceptance criteria before any code is written.</strong> The reviewer judges against them, not against taste.</li>
<li><strong>Every FAIL names a location, a defect type and a pass condition.</strong></li>
<li><strong>Re-review only what changed</strong>, and decide "unchanged" from code, spec and evidence, not version numbers.</li>
<li><strong>Keep handoffs as pointers</strong>: a document path and item numbers, not pasted content.</li>
<li><strong>Tests need a control case</strong>, or an empty result proves nothing.</li>
<li><strong>Keep the human gate</strong> for device tests, accounts and release.</li>
</ol>
<p>Claude Code versus Codex is the wrong comparison. The useful question is which one writes and which one is allowed to say no.</p>
<hr />
<p><em>Originally published on my site:</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-claude-code-writes-codex-reviews.html"><em>https://mm7382.github.io/pec-ai-agent-training/journal-claude-code-writes-codex-reviews.html</em></a><em>.</em> Related: <a href="https://mm7382.github.io/pec-ai-agent-training/journal-where-the-tokens-go.html">Where the tokens actually go: measuring a Claude Code session</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Where the Tokens Actually Go: Measuring a Claude Code Session]]></title><description><![CDATA[One question in Claude Code was eating about 4% of my context window. I was sure the cause was the pile of MCP servers and connectors I had installed. I…]]></description><link>https://michaelagentlab.hashnode.dev/where-the-tokens-actually-go-measuring-a-claude-code-session</link><guid isPermaLink="true">https://michaelagentlab.hashnode.dev/where-the-tokens-actually-go-measuring-a-claude-code-session</guid><category><![CDATA[claude-code]]></category><category><![CDATA[AI]]></category><category><![CDATA[llm]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Michael Chuang]]></dc:creator><pubDate>Thu, 03 Dec 2026 03:04:04 GMT</pubDate><content:encoded><![CDATA[<p>One question in Claude Code was eating about 4% of my context window. I was sure the cause was the pile of MCP servers and connectors I had installed. I was wrong. Here is what measuring showed, and the one rule that now decides what I optimise.</p>
<h2>The suspect everyone blames</h2>
<p>My setup is crowded. Claude Code writes code, Codex reviews it, and both share one knowledge base through an MCP server. On top of that the desktop app has connectors for design tools, mail, a browser extension and computer control. When a single question started costing a visible slice of the context window, the obvious move was to disconnect things.</p>
<p>Before deleting anything, I measured one real working session instead.</p>
<h2>What one 82k-token session was made of</h2>
<ul>
<li><strong>Messages: about 60k tokens (73%).</strong> The back-and-forth itself — my questions, the agent's answers and every tool result that landed in the conversation.</li>
<li><strong>Fixed overhead: about 22k tokens in total.</strong> MCP tool definitions about 7.7k, skills about 6k, memory files about 4.2k, system prompt about 2.5k.</li>
<li><strong>Deferred connectors: zero.</strong> The design, mail, browser and computer-control connectors were listed by name only. Their full definitions — about 165k tokens' worth — were never loaded, because the agent fetches a tool's schema only when it is about to use it.</li>
</ul>
<p>So the thing I was about to rip out cost nothing, and the expensive part was something I had not even looked at.</p>
<h2>The rule: paid every turn vs. paid once</h2>
<p>The fixed overhead is paid at the start of a session and then served from the prompt cache. Messages are different: everything that enters the conversation is re-read on every later turn. A 5,000-token tool result on turn 3 of a 40-turn session is not a 5,000-token cost. It rides along for the other 37 turns.</p>
<p>That gives one question to ask about any token cost: <strong>is this paid once, or paid every turn?</strong> Optimise the second kind first. Almost every useful fix I found came from this split.</p>
<h2>Fix 1: the search reply that was nine times too big</h2>
<p>The biggest per-turn item was my own knowledge-base search. Each call returned eight results, and each result carried its full metadata: score breakdowns, excerpts, related links, privacy flags, timestamps and supersession chains. One search reply was over 9,000 bytes. The agent only needed a title and a one-line summary to decide what to open next.</p>
<p>The fix was small:</p>
<ul>
<li>A slim result shape for search only: ID, title, path, kind, status, date, a 160-character summary and the score.</li>
<li>Default results cut from 8 to 4.</li>
<li>The tool description now says: read the summaries first, then fetch one full note on purpose.</li>
</ul>
<p>The same query went from 9,000+ bytes to about 1,560 — roughly 83% smaller. Full notes are still one call away, so nothing was lost. Because Claude Code and Codex share the same search function, both agents got the saving at once.</p>
<h2>Fix 2: my own formatting rules were inflating the context</h2>
<p>The second surprise was embarrassing. I had asked my agents to present every decision as five options, each assessed on effect, risk, cost, maintenance and fit. That made every option a small essay. Those essays were messages, so they were re-read for the rest of the session.</p>
<p>I kept the five options and cut each one to a single line: one benefit, one cost, one recommendation. The decision quality did not drop. If I need more detail I ask, and only then is it paid for.</p>
<p>The lesson generalises: <strong>output-format rules are a recurring cost.</strong> Every instruction that makes answers longer is multiplied by the number of turns that follow.</p>
<h2>Fix 3: keep long digging out of the main conversation</h2>
<p>Some work is long to do and short to report. Searching many files, running a test suite or reading a long log produces large intermediate output for a conclusion of a few lines. If that output lands in the main conversation, it is paid for on every later turn.</p>
<p>Now that kind of work goes to a sub-agent with an explicit instruction: return the conclusion only, not the raw content. The main thread receives a few hundred tokens instead of tens of thousands. The sub-agent still spends tokens, but once, not on every later turn of a long session.</p>
<h2>The most expensive token is the one spent on rework</h2>
<p>Context size was not the biggest cost I found. I pulled the logs for a single feature ticket in one of my iOS projects:</p>
<ul>
<li>First attempt: about 99k output tokens and 21.5 million cached input tokens.</li>
<li>Second attempt, to fix it: about 47k output and 11.2 million cached.</li>
<li>Third attempt: about 61k output and 19.5 million cached.</li>
<li>Total: about 207k output tokens and 52 million cached tokens over roughly two hours.</li>
</ul>
<p>The same ticket was built three times. The two rework runs used about 60% of the total. The root cause was not the model: the project's tests could not run locally, so the agent could not check its own work before handing it over. Each broken handoff meant another full run with a long context.</p>
<p>Making the tests runnable and trimming their output was worth more than any prompt trick. <strong>A run that cannot verify itself will eventually be paid for twice.</strong></p>
<h2>One more trap: what you store is not what you pay for</h2>
<p>A related problem showed up on disk, not in the bill. A computer-control plugin in another agent saved every screenshot inline, as base64 text inside its session log. One log file reached 1.6 GB with only about 45,000 lines, roughly 37 KB per line, while normal conversation lines are a few hundred bytes. Monthly log growth went from 52 MB to 2.2 GB in four months. Turning off that plugin when I was not using it stopped the growth.</p>
<p>It is not a token cost, but the habit that finds it is the same: measure the artefact, and do not trust the label.</p>
<h2>A checklist you can run on your own setup</h2>
<ol>
<li><strong>Measure one real session before changing anything.</strong> Split it into messages, fixed overhead and deferred tools. Your guess about which is biggest is probably wrong; mine was.</li>
<li><strong>Classify every cost as per-turn or once.</strong> Ignore the once-per-session items until the per-turn ones are fixed.</li>
<li><strong>Put your own tools on a diet.</strong> Return summaries and let the agent fetch full content deliberately. Default result counts are usually too high.</li>
<li><strong>Audit your formatting rules.</strong> Anything that makes every answer longer is multiplied by the session length.</li>
<li><strong>Move long digging into sub-agents</strong> that report conclusions, not raw output.</li>
<li><strong>Make the agent able to test its own work.</strong> Rework is the most expensive line on the bill and the one no prompt setting can fix.</li>
<li><strong>Keep a baseline.</strong> Write down the numbers before a change, or you will never know whether it helped.</li>
</ol>
<p>None of this needed a new tool. It needed one habit: separate what you pay once from what you pay on every turn, and measure before you cut.</p>
<hr />
<p><em>Originally published on</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-where-the-tokens-go.html"><em>my site</em></a><em>. I also wrote about</em> <a href="https://mm7382.github.io/pec-ai-agent-training/journal-claude-code-writes-codex-reviews.html"><em>a two-agent workflow where Claude Code writes and Codex reviews</em></a><em>.</em></p>
]]></content:encoded></item></channel></rss>