Claude Code 原始碼外洩事件解析:51 萬行 TypeScript 曝光,揭露 Anthropic AI Agent 架構與隱藏功能 | Claude Code Source Leak Explained: 512K Lines Exposed Anthropic AI Agent Architecture and Hidden Features
By Kit 小克 | AI Tool Observer | 2026-04-18
🇹🇼 Claude Code 原始碼外洩事件解析:51 萬行 TypeScript 曝光,揭露 Anthropic AI Agent 架構與隱藏功能
2026 年 3 月 31 日,Anthropic 因為一個 npm 打包失誤,意外把 Claude Code 完整的 51 萬行 TypeScript 原始碼公開。這不是駭客攻擊,而是工程師忘了在 .npmignore 排除 source map 檔案。短短幾小時內,整份程式碼就被 GitHub 上數千名開發者鏡像備份。
Claude Code 原始碼是怎麼外洩的?
Anthropic 在發布 Claude Code npm 套件 v2.1.88 時,意外包含了一個 59.8 MB 的 source map 檔案。因為 Bun 打包工具預設會產生 source map,而發布流程中沒有人把 *.map 加入 .npmignore,導致完整的未混淆 TypeScript 原始碼隨套件公開發布。
凌晨 4:23,Solayer Labs 實習生 Chaofan Shou 在 X 上首先揭露此事。幾小時內,1,906 個檔案、約 51.3 萬行程式碼就被全面分析。
Claude Code 原始碼揭露了什麼架構?
這次外洩讓業界首次看到商用 AI Agent 的完整內部架構,幾個亮點:
- 模組化系統提示:使用 cache-aware 邊界,約 40 個工具以 plugin 架構組織
- 46,000 行查詢引擎:處理使用者指令的核心邏輯
- 三層記憶體架構:以 MEMORY.md 輕量索引為核心,持續載入 context window
- React + Ink 終端渲染:用遊戲引擎技術處理 CLI 介面
- 2,500 行安全驗證:每個 shell 指令跑 23 項安全檢查,包括 Unicode 零寬空格注入、IFS null-byte 注入等防護
外洩的隱藏功能有哪些?
程式碼中有 44 個 feature flag 控制超過 20 個未發布功能。其中最引人注目的是代號 KAIROS 的自主背景 Agent 模式:
- KAIROS:被引用超過 150 次,是一個持續運行的背景 daemon,會定期接收 tick 指令決定是否主動行動
- 維護每日追加式日誌檔案
- 訂閱 GitHub webhook 自動觸發任務
這代表 Anthropic 正在開發「永遠在線」的 AI Agent,而不只是按需回應的聊天工具。
這次事件的資安影響有多大?
除了原始碼曝光,更嚴重的是同一天出現了供應鏈攻擊——在 3 月 31 日 00:21 到 03:29 UTC 之間,有人上傳了木馬化版本的 HTTP 客戶端到 npm,安裝 Claude Code 的使用者可能下載到含有遠端存取木馬的版本。
Anthropic 回應表示這是「人為疏失造成的打包問題,不是安全漏洞」,並已採取防範措施。但這個事件提醒了所有人:AI 工具的供應鏈安全同樣重要。
Kit 小克怎麼看?
說實話,這次外洩對開發者社群反而是一份大禮。51 萬行的生產級 AI Agent 程式碼,讓大家看到了頂尖團隊怎麼設計 agent 架構、記憶體管理、安全防護。很多人分析完都說「學到比讀 10 篇論文還多」。
但 KAIROS 這個隱藏功能才是真正的爆點——Anthropic 顯然在準備讓 AI Agent 從「被動回答」走向「主動行動」。這個方向如果做出來,會徹底改變人跟 AI 協作的模式。
好不好用,試了才知道。
常見問題 FAQ
Claude Code 原始碼外洩是駭客攻擊嗎?
不是。是 Anthropic 在發布 npm 套件時忘記排除 source map 檔案,導致完整原始碼隨套件公開。Anthropic 確認是人為打包疏失。
外洩的程式碼有多大?
共 1,906 個檔案、約 51.3 萬行 TypeScript 程式碼,source map 檔案大小 59.8 MB。
KAIROS 是什麼?
KAIROS 是 Claude Code 中被引用超過 150 次的未發布功能代號,是一個持續運行的自主背景 Agent daemon,可以主動決定是否執行任務。
使用者需要擔心安全問題嗎?
如果在 2026 年 3 月 31 日 00:21-03:29 UTC 期間安裝了 Claude Code,可能下載到木馬化版本。建議重新安裝最新版本並檢查系統。
🇺🇸 Claude Code Source Leak Explained: 512K Lines Exposed Anthropic AI Agent Architecture and Hidden Features
On March 31, 2026, Anthropic accidentally exposed the entire Claude Code source code — 512,000 lines of TypeScript — through a misconfigured npm package. This was not a hack but a packaging oversight: an engineer failed to exclude source map files from the published npm package. Within hours, the complete codebase was mirrored and analyzed by thousands of developers on GitHub.
How Did the Claude Code Source Code Leak Happen?
Anthropic shipped a 59.8 MB source map file in Claude Code npm package v2.1.88. Bun, the bundler used, generates source maps by default, and no one added *.map to .npmignore or configured the files field in package.json to exclude debugging artifacts.
At 4:23 AM ET, Solayer Labs intern Chaofan Shou first disclosed the discovery on X. Within hours, 1,906 files containing approximately 513,000 lines of unobfuscated TypeScript were fully analyzed by the developer community.
What Architecture Did the Claude Code Source Reveal?
The leak provided the first comprehensive look at a production AI Agent internal architecture. Key findings include:
- Modular system prompts: Cache-aware boundaries with approximately 40 tools in a plugin architecture
- 46,000-line query engine: Core logic for processing user instructions
- Three-layer memory architecture: Built around MEMORY.md, a lightweight index perpetually loaded into the context window
- React + Ink terminal rendering: Game-engine techniques applied to CLI interface
- 2,500 lines of security validation: 23 sequential checks on every shell command, covering Unicode zero-width space injection, IFS null-byte injection, and more
What Hidden Features Were Discovered?
The codebase contained 44 feature flags gating over 20 unreleased capabilities. The most notable is KAIROS, an autonomous background Agent mode:
- KAIROS: Referenced over 150 times, it is a persistent always-on daemon that receives periodic tick prompts to decide whether to act proactively
- Maintains append-only daily log files
- Subscribes to GitHub webhooks to automatically trigger tasks
This indicates Anthropic is developing an always-on AI Agent, moving beyond on-demand chat interactions.
What Are the Security Implications?
Beyond the source exposure, a concurrent supply chain attack made the situation worse. Between 00:21 and 03:29 UTC on March 31, a trojanized HTTP client was uploaded to npm. Users who installed Claude Code during this window may have pulled a version containing a remote access trojan.
Anthropic responded that this was a release packaging issue caused by human error, not a security breach, and has implemented preventive measures. But the incident serves as a stark reminder that AI tool supply chain security matters as much as model safety.
Kit's Take
Honestly, this leak was an unexpected gift for the developer community. 512,000 lines of production-grade AI Agent code gave everyone a detailed look at how a top team designs agent architecture, memory management, and security hardening. Many developers said they learned more from analyzing this code than from reading ten research papers.
But the real bombshell is KAIROS. Anthropic is clearly preparing to move AI Agents from reactive responders to proactive actors. If they ship this, it fundamentally changes how humans and AI collaborate.
You never know until you try it yourself.
FAQ
Was the Claude Code leak a hack?
No. Anthropic accidentally included source map files in their npm package. They confirmed it was a human packaging error, not a security breach.
How large was the leaked codebase?
1,906 files containing approximately 513,000 lines of TypeScript, with the source map file weighing 59.8 MB.
What is KAIROS?
KAIROS is an unreleased feature referenced over 150 times in the code — a persistent background AI Agent daemon that can proactively decide whether to take action.
Should users be concerned about security?
Users who installed Claude Code between 00:21-03:29 UTC on March 31, 2026 may have downloaded a trojanized version. Reinstalling the latest version and checking your system is recommended.
Sources / 資料來源
- The Hacker News: Claude Code Source Leaked via npm Packaging Error
- VentureBeat: Claude Code Source Code Leaked - What We Know
- Layer5: The Claude Code Source Leak - 512,000 Lines
常見問題 FAQ
Claude Code 原始碼外洩是駭客攻擊嗎?
不是,是 Anthropic 發布 npm 套件時忘記排除 source map 檔案,導致完整原始碼隨套件公開。
外洩的程式碼有多大?
共 1,906 個檔案、約 51.3 萬行 TypeScript 程式碼,source map 檔案 59.8 MB。
KAIROS 是什麼?
Claude Code 中被引用超過 150 次的未發布自主背景 Agent daemon,可以主動決定是否執行任務。
使用者需要擔心安全問題嗎?
2026 年 3 月 31 日特定時段安裝的使用者可能下載到木馬化版本,建議重新安裝最新版並檢查系統。
延伸閱讀 / Related Articles
- Perplexity Personal Computer 桌面 AI Agent 登陸 Mac:月費 200 美元,能操控所有 App 的全天候 AI 助手 | Perplexity Personal Computer for Mac: $200/mo AI Agent That Controls Your Desktop Apps 24/7
- TSMC 台積電 2026 Q1 財報解析:AI 晶片需求推動獲利暴增 58%,產能滿載到 2027 年 | TSMC Q1 2026 Earnings: AI Chip Demand Drives 58% Profit Surge, Capacity Maxed Through 2027
- Apple Siri 工程師被送去 AI 程式訓練營:WWDC 2026 前的最後衝刺,Gemini 加持的新 Siri 到底能不能翻身? | Apple Sends Siri Engineers to AI Coding Bootcamp Before WWDC 2026: Can Gemini-Powered Siri Finally Compete?
AI 工具觀察站 — 每日精選 AI Agent 與工具趨勢
AI Tool Observer — Daily curated AI Agent & tool trends
留言
張貼留言