Claude Code 500K Lines Code Leak Fully Organized, What's the True Core of the AI Agent?
51.2k lines of code, 1906 files, 59.8 MB source map. In the early hours of March 31, Chaofan Shou from Solayer Labs discovered that Anthropic's flagship product, Claude Code, had exposed the full source code in a public npm repository. Within hours, the code was mirrored on GitHub, with forks surpassing 41k.
This isn't Anthropic's first time making this mistake. When Claude Code was first released in February 2025, a similar source map leak occurred. The version number at that time was v2.1.88, and the leak was due to the same reason: the Bun build tool automatically generated the source map, which was not excluded in the .npmignore file.
Most reports focused on the easter eggs found in the leak, such as a virtual pet system and a "undercover mode" that allowed Claude to anonymously contribute code to open-source projects. But the real question to unpack is why the same Claude model exhibited such different behavior between the web version and Claude Code. What is the 51.2k lines of code really doing?
Model is Just the Tip of the Iceberg
The answer lies in the code structure. According to a GitHub community's reverse analysis of the leaked source code, out of the 51.2k lines of TypeScript, the interface code directly responsible for invoking the AI model accounts for only about 8000 lines, or 1.6% of the total.

What is the remaining 98.4% doing? The two largest modules are the query engine (46k lines) and the tooling system (29k lines). The query engine handles LLM API calls, streaming output, cache orchestration, and multi-turn dialogue management. The tooling system defines around 40 built-in tools and 50 slash commands, forming a plugin-like architecture where each tool has independent permissions control.
Additionally, there are 25k lines of terminal UI rendering code (with a file named print.ts stretching 5594 lines, with a single function spanning 3167 lines), 20k lines of security and permission control (including 23 numbered Bash security checks and 18 Zsh built-in commands that are disabled), and 18k lines of multi-proxy orchestration system.
Machine learning researcher Sebastian Raschka, after analyzing the leaked code, pointed out that the strength of Claude Code compared to the web version of the same model lies not in the model itself but in the software scaffolding built around the model, including repository context loading, dedicated tool dispatch, cache policies, and sub-agent collaboration. He even suggested that if the same engineering architecture were applied to other models like DeepSeek or Kimi, similar programming performance gains could be achieved.
An intuitive comparison can help understand this gap. When you input a question in the ChatGPT or Claude web version, the model processes it and returns an answer, leaving nothing behind at the end of the conversation. However, Claude Code's approach is entirely different. Upon startup, it first reads your project files, understands your codebase structure, remembers preferences like when you last said "do not mock the database in tests," and more. It can directly execute commands in your terminal, edit files, run tests, and when faced with complex tasks, it can break them down into multiple subtasks assigned to different subprocesses for parallel processing. In other words, the web version AI is a question-and-answer window, while Claude Code is a collaborator living on your computer.
Some liken this architecture to an operating system: the 42 built-in tools are akin to system calls, the permission system is similar to user management, the MCP protocol is like device drivers, and the subprocess orchestration is akin to process scheduling. Each tool is initially marked as "unsafe, writable" by default, unless a developer explicitly declares it safe. Tools for editing files will enforce a check to see if you've read the file before allowing modifications. This is not a chatbot with a few add-ons; it's an operating environment with LLM at its core and a complete security mechanism.
This implies one thing: the competitive barrier of AI products may not lie in the model layer but in the engineering layer.
Every Cache Miss Increases Costs Tenfold
Within the leaked code is a file named promptCacheBreakDetection.ts, which tracks 14 potential vectors that could cause a prompt cache invalidation. Why would Anthropic's engineers put in so much effort to prevent cache misses?
A look at Anthropic's official pricing reveals the reason. For example, with Claude Opus 4.6, the standard input price is $5 per million tokens, but if a cache hit occurs, the read price is only $0.5, a 90% discount. In other words, for every cache miss, the inference cost increases tenfold.

This explains the seemingly "overdesigned" architectural decisions in the leaked code. When Claude Code starts, it loads the current git branch, recent commit history, and CLAUDE.md file as context—these static contents are globally cached, with dynamic content separated by boundary markers to ensure conversations do not redundantly process existing contexts. There's also a mechanism called sticky latches in the code to prevent mode switches from disrupting established caches. Subagents are designed to reuse their parent process's cache rather than rebuild their context window.
Here is a detail worth expanding on. Anyone who has used AI programming tools knows that the longer the conversation, the slower the AI's response, because each round of dialogue has to resend the entire history to the model. The common practice is to delete old messages to free up space, but the problem is that deleting any message breaks the continuity of the cache, causing the entire conversation history to be reprocessed, leading to increased latency and cost.
The leaked code contains a mechanism called cache_edits, where instead of actually deleting messages, old messages are marked as "skipped" at the API layer. The model no longer sees these messages, but the cache continuity remains unbroken. This means that in a long conversation lasting hours, after clearing hundreds of old messages, the response speed in the next round is almost as fast as the first round. For the average user, this is the underlying answer to "why Claude Code can support an unlimited long dialogue without slowing down".

According to leaked internal monitoring data (from code comments in autoCompact.ts, dated March 10, 2026), before introducing the automatic compact failure limit, Claude Code wasted about 250,000 API calls per day. There were 1,279 user sessions that experienced 50 or more consecutive compact failures, with the most severe session failing consecutively 3,272 times. The fix was simply adding one line of restriction: MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3.
So, for AI products, model inference cost may not be the most expensive layer; cache management failures are.
44 Switches, Pointing in the Same Direction
The leaked code contains 44 feature flags—precompiled feature switches that have not been publicly released. According to community analysis, these flags are categorized into five groups based on functionality, with the densest being the "Autonomous Agent" class (12 flags), pointing to a system called KAIROS.
KAIROS is referenced in the source code over 150 times; it is a persistent background daemon mode. Claude Code is no longer just a tool that responds when you actively call it but an agent that runs in the background, continuously observing, recording, and proactively acting at the right moment. The condition is not to interrupt the user, and any operation that could block the user for more than 15 seconds will be delayed.

KAIROS also has built-in terminal focus awareness. There is a `terminalFocus` field in the code that detects in real time whether the user is looking at the terminal window. When you switch to the browser or another app, the agent determines that you are "away" and switches to autonomous mode, actively performing tasks, submitting code directly without waiting for your confirmation. When you switch back to the terminal, the agent immediately returns to collaborative mode: first reporting what it has done and then asking for your opinion. The level of autonomy is not fixed but fluctuates in real time with your attention. This solves an embarrassing problem that AI tools have faced for a long time: fully autonomous AI makes people uneasy, while completely passive AI is inefficient. KAIROS's approach is to dynamically adjust the AI's initiative based on the user's attention, behaving obediently when you are focused on it and taking initiative when you are away.
Another subsystem of KAIROS is called autoDream. Every 5 sessions or every 24 hours, the agent initiates a "reflection" process in the background, consisting of four steps. It first scans existing memories to understand what it currently knows. Then it extracts new knowledge from conversation logs. Next, it merges the new and old knowledge, corrects contradictions, and removes duplicates. Finally, it streamlines the index by deleting outdated entries. This design is inspired by the memory consolidation theory in cognitive science. Just as humans organize their memories during sleep, KAIROS organizes project context when the user is away. For ordinary users, this means that the longer you use Claude Code, the more accurately it understands your project, not just "remembering what you said."
The second major category is "Anti-distillation and Security" (8 flags). The most notable among them is the `fake_tools` mechanism. When four conditions are met simultaneously (compile-time flag enabled, CLI entry activated, first-party API used, and GrowthBook remote switch set to true), Claude Code injects fake tool definitions into API requests, aiming to contaminate datasets potentially used in recording API traffic or training competitive models. This represents a new form of defense in the AI arms race. Its goal is not to prevent you from copying but to make you copy incorrect information.
Additionally, the code references the Capybara model alias (divided into standard, fast, and million-context window versions), widely speculated by the community to be the internal alias for the Claude 5 series.
Easter Egg: Within 512,000 lines of code lies an electronic pet
Among all the serious engineering architecture and security mechanisms, Anthropic's engineers have also quietly built a complete virtual pet system, internally codenamed BUDDY.
According to leaked code and community analysis, BUDDY is a gamified terminal pet that will appear as an ASCII art bubble next to the user's input box. It features 18 species (including Otter, Salamander, Mushroom, Ghost, Dragon, and a range of original creatures like Pebblecrab, Dustbunny, Mossfrog), divided into five rarity levels: Common (60%), Rare (25%), Epic (10%), Legendary (4%), and Mythic (1%). Each species also has a "Shiny variant," with the rarest being the Shiny Legendary Nebulynx with a one in ten thousand chance of appearing.
Each BUDDY has five attributes: DEBUGGING, PATIENCE, CHAOS, WISDOM, and SNARK. They can also wear hats, including a Crown, Top Hat, Propeller Cap, Halo, Wizard Hat, and even a Mini Duck. The pet you hatch is determined by the hash of your user ID, and Claude will generate its name and personality.
As per the leaked launch schedule, BUDDY was originally set to start closed beta from April 1st to 7th, with a full launch in May, starting with Anthropic's internal employees.
With 512,000 lines of code, 98.4% hardcore engineering, but someone took the time in the end to create an electronic salamander that wears a propeller cap. Perhaps, this is the most human touch in the leaked code.
You may also like

a16z: 5 Ways Blockchain Helps AI Agent Infrastructure

Morning News | The Hong Kong Securities and Futures Commission announced the regulatory framework for secondary market trading of tokenized investment products; Strategy increased its holdings by 34,164 bitcoins last week; KAIO completed a strategic fi...

What Is an XRP Wallet? The Best Wallets to Store XRP (2026 Updated)
An XRP wallet lets you safely store, send, and receive XRP on the XRP Ledger. Learn what wallets support XRP and discover the best XRP wallets for beginners and long-term holders in 2026.

What are the Top AI Crypto Coins? Render vs. Akash: 5 Gems Solving the 2026 GPU Crisis
What are the best AI crypto coins for the 2026 cycle? Beyond the hype, we analyze top tokens like RNDR, AKT, and FET that provide real-world solutions to the global GPU shortage and the rise of autonomous agents.

What Is a Token in AI? What Is an AI Token + 3 Gems You Can't Miss in 2026
The era of AI hype has transitioned into an era of utility. As we move through Q2 2026, the market is no longer rewarding "narrative-only" projects. At WEEX Research, we are seeing a massive capital rotation into Decentralized Compute (DePIN) and Autonomous Agent coordination layers. This guide analyzes which AI tokens are capturing institutional liquidity and how to spot high-conviction setups in a maturing market.

Consumer-grade Crypto Global Survey: Users, Revenue, and Track Distribution

Prediction Markets Under Bias

Stolen: $290 million, Three Parties Refusing to Acknowledge, Who Should Foot the Bill for the KelpDAO Incident Resolution?

ASTEROID Pumped 10,000x in Three Days, Is Meme Season Back on Ethereum?

ChainCatcher Hong Kong Themed Forum Highlights: Decoding the Growth Engine Under the Integration of Crypto Assets and Smart Economy

Why can this institution still grow by 150% when the scale of leading crypto VCs has shrunk significantly?

Anthropic's $1 trillion, compared to DeepSeek's $100 billion

Geopolitical Risk Persists, Is Bitcoin Becoming a Key Barometer?

Annualized 11.5%, Wall Street Buzzing: Is MicroStrategy's STRC Bitcoin's Savior or Destroyer?

An Obscure Open Source AI Tool Alerted on Kelp DAO's $292 million Bug 12 Days Ago

Mixin has launched USTD-margined perpetual contracts, bringing derivative trading into the chat scene.
The privacy-focused crypto wallet Mixin announced today the launch of its U-based perpetual contract (a derivative priced in USDT). Unlike traditional exchanges, Mixin has taken a new approach by "liberating" derivative trading from isolated matching engines and embedding it into the instant messaging environment.
Users can directly open positions within the app with leverage of up to 200x, while sharing positions, discussing strategies, and copy trading within private communities. Trading, social interaction, and asset management are integrated into the same interface.
Based on its non-custodial architecture, Mixin has eliminated friction from the traditional onboarding process, allowing users to participate in perpetual contract trading without identity verification.
The trading process has been streamlined into five steps:
· Choose the trading asset
· Select long or short
· Input position size and leverage
· Confirm order details
· Confirm and open the position
The interface provides real-time visualization of price, position, and profit and loss (PnL), allowing users to complete trades without switching between multiple modules.
Mixin has directly integrated social features into the derivative trading environment. Users can create private trading communities and interact around real-time positions:
· End-to-end encrypted private groups supporting up to 1024 members
· End-to-end encrypted voice communication
· One-click position sharing
· One-click trade copying
On the execution side, Mixin aggregates liquidity from multiple sources and accesses decentralized protocol and external market liquidity through a unified trading interface.
By combining social interaction with trade execution, Mixin enables users to collaborate, share, and execute trading strategies instantly within the same environment.
Mixin has also introduced a referral incentive system based on trading behavior:
· Users can join with an invite code
· Up to 60% of trading fees as referral rewards
· Incentive mechanism designed for long-term, sustainable earnings
This model aims to drive user-driven network expansion and organic growth.
Mixin's derivative transactions are built on top of its existing self-custody wallet infrastructure, with core features including:
· Separation of transaction account and asset storage
· User full control over assets
· Platform does not custody user funds
· Built-in privacy mechanisms to reduce data exposure
The system aims to strike a balance between transaction efficiency, asset security, and privacy protection.
Against the background of perpetual contracts becoming a mainstream trading tool, Mixin is exploring a different development direction by lowering barriers, enhancing social and privacy attributes.
The platform does not only view transactions as execution actions but positions them as a networked activity: transactions have social attributes, strategies can be shared, and relationships between individuals also become part of the financial system.
Mixin's design is based on a user-initiated, user-controlled model. The platform neither custodies assets nor executes transactions on behalf of users.
This model aligns with a statement issued by the U.S. Securities and Exchange Commission (SEC) on April 13, 2026, titled "Staff Statement on Whether Partial User Interface Used in Preparing Cryptocurrency Securities Transactions May Require Broker-Dealer Registration."
The statement indicates that, under the premise where transactions are entirely initiated and controlled by users, non-custodial service providers that offer neutral interfaces may not need to register as broker-dealers or exchanges.
Mixin is a decentralized, self-custodial privacy wallet designed to provide secure and efficient digital asset management services.
Its core capabilities include:
· Aggregation: integrating multi-chain assets and routing between different transaction paths to simplify user operations
· High liquidity access: connecting to various liquidity sources, including decentralized protocols and external markets
· Decentralization: achieving full user control over assets without relying on custodial intermediaries
· Privacy protection: safeguarding assets and data through MPC, CryptoNote, and end-to-end encrypted communication
Mixin has been in operation for over 8 years, supporting over 40 blockchains and more than 10,000 assets, with a global user base exceeding 10 million and an on-chain self-custodied asset scale of over $1 billion.

$600 million stolen in 20 days, ushering in the era of AI hackers in the crypto world

Vitalik's 2026 Hong Kong Web3 Summit Speech: Ethereum's Ultimate Vision as the "World Computer" and Future Roadmap
a16z: 5 Ways Blockchain Helps AI Agent Infrastructure
Morning News | The Hong Kong Securities and Futures Commission announced the regulatory framework for secondary market trading of tokenized investment products; Strategy increased its holdings by 34,164 bitcoins last week; KAIO completed a strategic fi...
What Is an XRP Wallet? The Best Wallets to Store XRP (2026 Updated)
An XRP wallet lets you safely store, send, and receive XRP on the XRP Ledger. Learn what wallets support XRP and discover the best XRP wallets for beginners and long-term holders in 2026.
What are the Top AI Crypto Coins? Render vs. Akash: 5 Gems Solving the 2026 GPU Crisis
What are the best AI crypto coins for the 2026 cycle? Beyond the hype, we analyze top tokens like RNDR, AKT, and FET that provide real-world solutions to the global GPU shortage and the rise of autonomous agents.
What Is a Token in AI? What Is an AI Token + 3 Gems You Can't Miss in 2026
The era of AI hype has transitioned into an era of utility. As we move through Q2 2026, the market is no longer rewarding "narrative-only" projects. At WEEX Research, we are seeing a massive capital rotation into Decentralized Compute (DePIN) and Autonomous Agent coordination layers. This guide analyzes which AI tokens are capturing institutional liquidity and how to spot high-conviction setups in a maturing market.




