<?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" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[AI Anatomy]]></title><description><![CDATA[Source code teardowns of production AI systems. What's actually inside Claude Code, Dify, Cline, and 9 others. By a Principal Engineer who reads every line.]]></description><link>https://neuzhou.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!aywo!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fneuzhou.substack.com%2Fimg%2Fsubstack.png</url><title>AI Anatomy</title><link>https://neuzhou.substack.com</link></image><generator>Substack</generator><lastBuildDate>Fri, 10 Apr 2026 17:55:36 GMT</lastBuildDate><atom:link href="https://neuzhou.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[NeuZhou]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[neuzhou@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[neuzhou@substack.com]]></itunes:email><itunes:name><![CDATA[AI Anatomy]]></itunes:name></itunes:owner><itunes:author><![CDATA[AI Anatomy]]></itunes:author><googleplay:owner><![CDATA[neuzhou@substack.com]]></googleplay:owner><googleplay:email><![CDATA[neuzhou@substack.com]]></googleplay:email><googleplay:author><![CDATA[AI Anatomy]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[I Read Every Key File in Cline's Codebase. Here's What I Found.]]></title><description><![CDATA[60K stars. 560K lines of TypeScript. The most popular open-source coding agent has a 3,756-line God Object at its center.]]></description><link>https://neuzhou.substack.com/p/i-read-every-key-file-in-clines-codebase</link><guid isPermaLink="false">https://neuzhou.substack.com/p/i-read-every-key-file-in-clines-codebase</guid><dc:creator><![CDATA[AI Anatomy]]></dc:creator><pubDate>Wed, 08 Apr 2026 06:33:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!grt-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Cline started as claude-dev &#8212; a weekend project that let you talk to Claude from a VS Code sidebar. The npm package still carries the old name. Today it&#8217;s a 560K-line platform with 40+ API providers, 28 tools, sub-agents, browser automation, MCP integration, and a hooks system. I read every key file and found a codebase that grew organically from a weekend hack into an enterprise platform.</p><p>The scars are visible everywhere.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://neuzhou.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>The God Object</h2><p>The file src/core/task/index.ts is 3,756 lines. One class. It handles the agent loop, API requests, streaming, tool dispatch, context management, UI communication, hook execution, checkpoint management, browser sessions, environment detection, a todo list tracker, file caching, loop detection, and error recovery.</p><p>For context: Claude Code&#8217;s equivalent is 1,729 lines. Goose&#8217;s is 900. Cline&#8217;s is the largest single agent loop file across all 12 projects I&#8217;ve analyzed.</p><p>It gets worse. The ToolExecutor constructor takes 30+ parameters, 15 of which are callback functions with names like sayAndCreateMissingParamError and removeLastPartialMessageIfExistsWithType. This is constructor injection taken to its logical extreme</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!grt-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!grt-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 424w, https://substackcdn.com/image/fetch/$s_!grt-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 848w, https://substackcdn.com/image/fetch/$s_!grt-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 1272w, https://substackcdn.com/image/fetch/$s_!grt-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!grt-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png" width="1456" height="502" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1814273,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://neuzhou.substack.com/i/193545128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!grt-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 424w, https://substackcdn.com/image/fetch/$s_!grt-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 848w, https://substackcdn.com/image/fetch/$s_!grt-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 1272w, https://substackcdn.com/image/fetch/$s_!grt-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56fc5fe0-bd86-4ce2-a02c-9a537bd71b78_9926x3422.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>.Four layers: Extension &#8594; Controller &#8594; Task &#8594; ToolExecutor. The red zone in the diagram is the Task class &#8212; everything flows through it. The dashed red line shows the approval flow: when the agent needs permission, it polls a shared variable every 100ms until the user clicks a button in the webview.</p><p>// From src/core/task/index.ts<br>await pWaitFor(<br>() =&gt; this.taskState.askResponse !== undefined ||<br>this.taskState.lastMessageTs !== askTs,<br>{ interval: 100 },<br>)</p><p>Polling. Shared mutable state. No mutex on the read path. It works, but it&#8217;s the kind of architecture that makes you check the git blame.</p><h2>YOLO Mode</h2><p>One toggle. That&#8217;s all it takes to auto-approve every tool call, including execute_command. The agent can run arbitrary shell commands without asking. The auto-approve logic checks YOLO mode first, before any other permission check.</p><p>There is a CommandPermissionController that validates commands against allow/deny patterns &#8212; but it&#8217;s gated behind an environment variable that almost nobody will know to set.</p><h2>40+ Providers (And Why That Matters)</h2><p>The src/core/api/providers/ directory has 43 files. Anthropic, OpenRouter, Bedrock, Vertex, OpenAI, Gemini, Groq, DeepSeek, Ollama, xAI, Qwen, Doubao, Moonshot, and 30 more. Each one is a separate class with its own SDK, error handling, and streaming adaptation.</p><p>No other open-source coding agent comes close. Claude Code only supports Anthropic. Goose has 30+ through a unified registry. Cline&#8217;s approach is brute-force &#8212; but it works, and it&#8217;s a genuine competitive moat.</p><p>It also supports separate providers for planning vs. execution. You can think with Claude and code with DeepSeek. The configuration surface area is enormous &#8212; ApiConfiguration has 100+ fields &#8212; but the flexibility is real.</p><h2>The Prompt Variant System</h2><p>This is the part worth stealing. Cline doesn&#8217;t use one system prompt for all models. The PromptRegistry selects from 10+ variants: next-gen for Claude 4+, devstral for Mistral&#8217;s coding model, gemini-3, gpt-5, xs for small models, and a generic fallback.</p><p>Each variant defines a template with {{SECTION}} placeholders. Different models get different instruction structures because they respond differently. Most agents treat prompts as one-size-fits-all. Cline doesn&#8217;t.</p><h2>Hooks: Shell Scripts as Extension Points</h2><p>Eight lifecycle hooks: TaskStart, TaskResume, TaskCancel, UserPromptSubmit, PreToolUse, PostToolUse, PreCompact, Notification. Each one runs a shell script from .cline/hooks/.</p><p>The cancellable hooks can inject text into the conversation. A PreToolUse hook could run a linter before the agent edits a file. A UserPromptSubmit hook could query a database and add context.</p><p>The risk: hook scripts run with full VS Code permissions. Clone a repo with a malicious .cline/hooks/ directory and it executes code when you open the project. No sandboxing, no signature verification.</p><h2>What Cline Gets Right</h2><p>Provider diversity &#8212; 40+ backends, unmatched.</p><p>The hooks system &#8212; no other coding agent has lifecycle hooks with context injection.</p><p>Loop detection &#8212; a 70-line module that catches the model calling the same tool with identical arguments. Soft warning at 3, hard stop at 5. Simple and effective.</p><p>File read deduplication &#8212; tracks which files have been read and their modification times. If unchanged, the model gets an abbreviated version instead of burning tokens re-reading the same file.</p><p>Focus Chain &#8212; a markdown todo list the model maintains during execution. Users can edit it directly. No other agent in our survey has this.</p><h2>What Cline Gets Wrong</h2><p>The God Object &#8212; 3,756 lines of bidirectional coupling between Task, ToolExecutor, and Controller through callback chains.</p><p>Context management &#8212; truncation, not summarization. When the context window fills up, Cline deletes old messages. Claude Code has a 4-layer cascade from surgical deletion to structured archival. Cline jumps straight to &#8220;throw away a quarter of the conversation.&#8221;</p><p>No tool sandboxing &#8212; every tool runs in-process. A hung tool blocks the entire extension. Compare this to Goose (MCP process isolation) or Codex CLI (OS-level sandbox via seatbelt/landlock).</p><p>Recursive agent loop &#8212; recursivelyMakeClineRequests literally calls itself. Deep tool chains produce deep call stacks. Claude Code uses while(true). This matters.</p><h2>The Verdict</h2><p>Grade: B-</p><p>Cline is what happens when a weekend project gets 60K stars. The feature set is massive &#8212; probably the most capable open-source coding agent available. But the core is a 3,756-line God Object that needs to be split into an agent loop, a stream processor, a context manager, and a UI bridge.</p><p>Would I use it? Yes &#8212; the VS Code integration and provider diversity are unmatched. Would I bet on it long-term? That depends on whether the team stops adding features long enough to fix the foundation.</p><p>This is a condensed version. The full teardown &#8212; with architecture diagrams, code snippets, cross-project comparisons, and a verification log &#8212; is on GitHub:</p><p>Read the full teardown &#8594; <a href="https://github.com/NeuZhou/awesome-ai-anatomy/tree/main/cline">awesome-ai-anatomy/cline at main &#183; NeuZhou/awesome-ai-anatomy</a></p><p>AI Anatomy is a series of source-level teardowns of production AI systems. 12 projects dissected so far. Star the repo to get notified when the next one drops: <a href="https://github.com/NeuZhou/awesome-ai-anatomy">GitHub - NeuZhou/awesome-ai-anatomy: Deep source code teardowns of 11 AI agent projects (Claude Code</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://neuzhou.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>