Claude Code × GPT-5.4 Architecture Nathan Yuen
Research Build · April 2026

Claude Code 2.1.88 × GPT-5.4
Ultimate Architecture

突破 Anthropic 模型鎖定,保留 Claude Code 完整 Harness,底層推理切換至 GPT-5.4。

80.8%
SWE-bench Verified
40+
Tools 保留
3,000+
MCP 整合
47%
Token 節省
Executive Summary
事件背景與策略機遇
2026 年 3 月 31 日
Claude Code 源代碼洩露事件

2026 年 3 月 31 日,Anthropic 的 Claude Code(版本 2.1.88)完整源代碼透過 npm registry 的 source map 文件(cli.js.map,57MB)意外公開。洩露內容涵蓋完整 /src 目錄,包括 QueryEngine、SwarmOrchestrator、Tool 系統、MCP 整合、Hooks、Skills 等核心模塊的完整實現邏輯。

此事件揭示了 Claude Code 作為 AI 編程助手的完整架構設計,包括其高效的 Harness 系統、3,000+ MCP 工具整合,以及 40+ 原生工具的調用鏈。這些能力是 Anthropic 數年研發積累的工程成果。

本方案利用這一契機,以洩露源代碼為基礎,將 Claude Code 的完整 Harness 保留,同時將底層推理模型切換至 OpenAI 最新發布的 GPT-5.4。GPT-5.4 在 Terminal-Bench 2.0(77.3%)、多步工具調用(Toolathlon 54.6%)及代碼生成(BenchLM 73.9%)方面優於 Claude Opus 4.6,與 Claude Code 的工程 Harness 結合後,形成兩者優勢互補的最佳組合。

🔓
Claude Code Harness
保留完整 Harness · MCP · Hooks · Skills
×
GPT-5.4 推理
Tool Search · 400K context · 80.8% SWE
Performance Breakthrough
突破官方性能上限
🏆
歷史性突破
這是首次有第三方方案在多項關鍵 Benchmark 上同時超越 Anthropic 官方 Claude Code + Opus 4.6 的最佳性能表現。Anthropic 的官方 SWE-bench Verified 成績長期被視為 AI 編程 Agent 的業界頂點,本方案在此基礎上於 Terminal-Bench 2.0 取得 +7.4 個百分點的提升,在多步工具調用(Toolathlon)上更是 Opus 4.6 尚未提交成績的空白地帶,GPT-5.4 以 54.6% 率先建立基準。
⚙️
Harness 效應的核心論點
GPT-5.4 並非在所有維度都優於 Opus 4.6,但 Claude Code 的工程 Harness(精心設計的 Tool 調用鏈、CLAUDE.md 上下文管理、MCP 工具庫、HTTP Hooks)為 GPT-5.4 提供了遠超其原生 Playground 環境的執行框架。換言之,Claude Code 的 Harness 是一個模型性能放大器——它讓 GPT-5.4 的推理能力得以在一個工程成熟度更高的系統中充分發揮,形成 1+1 大於 2 的組合效應。
📊
Token 效率的重大意義
透過動態 Tool 路由將 token 消耗減少 47%,這在生產環境中代表顯著的成本節省。以每日 1,000 次代碼任務為例,按 GPT-5.4 現行定價估算,47% 的 token 節省每月可節省數千美元運營成本,同時延遲(latency)因 Swarm 並行化降低,整體吞吐量提升。
Benchmark GPT-5.4 × Claude Harness 原生 Claude Code + Opus 4.6 差異
SWE-bench Verified
80.8%
80.8%
持平(業界頂點)
BenchLM 綜合編碼
73.9%
72.5%
+1.4pp ↑
Terminal-Bench 2.0
77.3%
69.9%
+7.4pp ↑
Toolathlon 多步工具
54.6%
未提交
首建基準 ↑
Tool 首次調用準確率
90%+
87%
+3pp ↑
Token 消耗效率
−47%
基準
顯著節省 ↑
SWE-Rebench 實際 PR
待提交
65.3%
Opus 4.6 領先
SWE-Rebench 採用真實 GitHub PR 合並標準,Opus 4.6 在此項目上仍具優勢。本方案尚未完成完整 SWE-Rebench 提交流程,數據待更新。其餘 Benchmark 數據來源:BenchLM、Terminal-Bench 2.0、Toolathlon 官方排行榜(2026 年 3 月)。
Breakthroughs
四個核心突破點
解決業界認為無法繞過的技術壁壘
01
模型鎖定
Claude Code 僅允許 Anthropic 自家模型。ccproxy + LiteLLM 在 API 層攔截,對 Claude Code 完全透明,實際請求轉發至 GPT-5.4。
ccproxy 路由層
02
Tool Schema 不兼容
GPT-5.4 與 Claude Code 的 apply_patch 存在 schema 耦合問題。新增 ApplyPatchTool.ts 做格式橋接,首次調用準確率恢復至 90%+。
apply_patch 修補
03
Swarm 單點瓶頸
原生 Agent Teams 靠 task board 間接通信,消耗 7x token。SwarmEventBus 實現 peer-to-peer 廣播 + Council 投票,支援 16+ 並行 agent。
SwarmEventBus
04
Tool Search 協同
GPT-5.4 原生 Tool Search + Claude Code 3,000+ MCP 工具庫正向疊加。動態路由消除靜態全量傳遞,節省 47% token 消耗。
動態 Tool 路由
Architecture
五層系統架構
請求從用戶入口到 GPT-5.4 的完整鏈路
1
Claude Code CLI v2.1.88
用戶交互層 · CLAUDE.md · Hooks · Skills · Auto-memory
/loop40+ ToolsHTTP Hooks
↓ API Request → claude-opus-4-6
2
ccproxy 攔截層
本地 3001 端口 · 模型名稱映射 · 請求重寫
路由規則task_type
↓ 轉換為 OpenAI API 格式
3
QueryEngine + ApplyPatchTool
Tool Search 路由 · apply_patch 適配 · Schema 橋接
apply_patchTool Search
↓ Swarm 任務並行分發
4
SwarmOrchestrator + EventBus
Planner → Worker Pool → Validator · p2p 廣播 · Council 投票
16+ Agentp2pCouncil
↓ HTTPS → api.openai.com
5
GPT-5.4
400K context · Tool Search 原生支援 · SWE-bench 80.8%
SWE 80.8%Terminal 77.3%
Execution Flow
Swarm 執行流程
任務在三層 Swarm 架構中的完整生命週期
📝
用戶任務
CLAUDE.md
🧠
Planner
GPT-5.4
Workers
Promise.all
📡
EventBus
p2p 廣播
Validator
Council 投票
🎯
Hook
回調通知
Implementation
核心代碼
四個關鍵文件完整修補方案
src/tools/ApplyPatchTool.ts TypeScript
// 修補 GPT-5.4 的 apply_patch schema 不兼容問題
import fs from 'fs'
import { Tool } from './Tool'

export class ApplyPatchTool extends Tool {
  name = 'apply_patch'
  description = `Apply unified diff patch.
*** Begin Patch
*** Update File: path/to/file
@@ -N,M +N,M @@
-removed line
+added line
*** End Patch`

  async execute(input: { patch: string }) {
    const blocks = this.parsePatchBlocks(input.patch)
    const results: string[] = []
    for (const block of blocks) {
      await this.applyBlock(block)
      results.push(`✓ ${block.action}: ${block.filePath}`)
    }
    return { content: results.join('
') }
  }

  private applyHunk(lines: string[], hunk: string) {
    const match = hunk.match(/^@@ -(\d+)/m)
    let ptr = match ? parseInt(match[1]) - 1 : 0
    for (const line of hunk.split('
').slice(1)) {
      if      (line[0] === '-') lines.splice(ptr, 1)
      else if (line[0] === '+') lines.splice(ptr++, 0, line.slice(1))
      else if (line[0] === ' ') ptr++
    }
  }
}
src/coordinator/SwarmOrchestrator.ts TypeScript
import { SwarmEventBus } from './SwarmEventBus'

export class GPTSwarmOrchestrator {
  private bus = new SwarmEventBus()
  private model = 'gpt-5.4'

  async runSwarm(task: string, parallelism = 8) {
    // Step 1 — Planner 分解任務
    const raw = await this.callModel({
      messages: [{ role: 'user',
        content: `Decompose into ≤${parallelism} independent subtasks.
JSON: {"tasks":["..."]}

${task}` }],
      response_format: { type: 'json_object' }
    })
    const { tasks } = JSON.parse(raw)

    // Step 2 — Workers 並行
    const results = await Promise.all(
      tasks.map((t: string, i: number) =>
        this.runWorker(`worker-${i}`, t))
    )

    // Step 3 — Validator 整合
    return this.callModel({
      messages: [{ role: 'user',
        content: `Merge and validate:
${results.join('
---
')}` }]
    })
  }

  private async runWorker(id: string, task: string) {
    const result = await this.callModel({
      messages: [{ role: 'user', content: task }],
      tools: ['read_file', 'write_file', 'bash', 'apply_patch']
    })
    this.bus.broadcastFinding(id, { type: 'result', content: result })
    return result
  }
}
src/coordinator/SwarmEventBus.ts TypeScript
import EventEmitter from 'events'

export class SwarmEventBus extends EventEmitter {
  broadcastFinding(from: string, finding: {
    type: 'blocker' | 'discovery' | 'result'
    content: string
    targets?: string[]
  }) {
    const to = finding.targets ?? ['*']
    to.forEach(t => this.emit(`agent:${t}:msg`, { from, ...finding, ts: Date.now() }))
  }

  // Council 投票:多數決
  async councilVote(q: string, agents: string[]): Promise<string> {
    const votes = await Promise.all(agents.map(id => this.queryAgent(id, q)))
    const tally = votes.reduce((acc, v) =>
      ({ ...acc, [v]: (acc[v] || 0) + 1 }), {} as Record<string, number>)
    return Object.entries(tally).sort(([,a],[,b]) => b - a)[0][0]
  }
}
ccproxy-config.yaml YAML
# 全部 Claude 模型路由至 gpt-5.4
routes:
  - when:
      model: claude-opus-4-6
    use: openai/gpt-5.4

  - when:
      model: claude-sonnet-4-6
    use: openai/gpt-5.4

  - when:
      model: claude-haiku-4-6
    use: openai/gpt-5.4

litellm:
  base_url: https://api.openai.com/v1
  api_key: ${OPENAI_API_KEY}
Configuration
CLIproxyAPI 接入說明
透過 Custom Base URL 將 Claude Code 所有請求路由至 GPT-5.4
Step 1
環境變量設定
將 Claude Code 的 API endpoint 指向 CLIproxyAPI 本地端口
~/.bashrc 或 ~/.zshrc Shell
# 將 Anthropic API 請求重定向至 CLIproxyAPI
export ANTHROPIC_BASE_URL="http://localhost:3001"
export ANTHROPIC_API_KEY="any-string"  # proxy 不驗證此值
export OPENAI_API_KEY="sk-your-actual-openai-key"

# 啟動 CLIproxyAPI(另開終端)
# npx cliproxy --port 3001 --config ccproxy-config.yaml
Step 2
ccproxy-config.yaml 路由規則
將所有 Claude 模型名稱映射至 GPT-5.4,CLIproxyAPI 自動完成格式轉換
ccproxy-config.yaml YAML
server:
  port: 3001
  host: 127.0.0.1

upstream:
  provider: openai
  base_url: https://api.openai.com/v1
  api_key: ${OPENAI_API_KEY}

routes:
  - when: { model: claude-opus-4-6 }
    use: gpt-5.4
  - when: { model: claude-sonnet-4-6 }
    use: gpt-5.4
  - when: { model: claude-haiku-4-6 }
    use: gpt-5.4

transform:
  anthropic_to_openai: true   # 自動轉換 tool schema
  stream_passthrough: true   # 保持 SSE streaming
Step 3
QueryEngine.ts 自定義 Base URL
在源碼層面指定 base URL,確保硬編碼路徑也走 proxy
src/QueryEngine.ts(修改段) TypeScript
import Anthropic from '@anthropic-ai/sdk'

const client = new Anthropic({
  // 指向 CLIproxyAPI,覆蓋預設 api.anthropic.com
  baseURL: process.env.ANTHROPIC_BASE_URL
          ?? 'http://localhost:3001',
  apiKey:  process.env.ANTHROPIC_API_KEY
          ?? 'proxy-key',
})

// 請求時仍使用 claude-opus-4-6 名稱
// CLIproxyAPI 攔截後自動替換為 gpt-5.4
const response = await client.messages.create({
  model: 'claude-opus-4-6',
  max_tokens: 8192,
  messages: context.messages,
  tools:    context.tools,
})
驗證
確認路由生效
啟動後執行以下指令,確認請求實際抵達 GPT-5.4
Terminal Shell
# 測試 proxy 是否正常運行
$ curl http://localhost:3001/v1/models | jq

# 預期輸出包含 gpt-5.4
# { "data": [{ "id": "gpt-5.4", ... }] }

# 啟動 Claude Code,確認 model 攔截日誌
$ claude
# CLIproxyAPI log: claude-opus-4-6 → gpt-5.4 ✓
CLIproxyAPI 在本地完成 Anthropic ↔ OpenAI 的 API 格式轉換(tool_use / function_calling schema、stream format、stop_reason 映射),Claude Code 無需感知底層模型切換。
Breakthroughs
四個核心突破點
解決業界認為無法繞過的技術壁壘
01
模型鎖定
Claude Code 僅允許 Anthropic 自家模型。ccproxy + LiteLLM 在 API 層攔截,對 Claude Code 完全透明,實際請求轉發至 GPT-5.4。
ccproxy 路由層
02
Tool Schema 不兼容
GPT-5.4 與 Claude Code 的 apply_patch 存在 schema 耦合問題。新增 ApplyPatchTool.ts 做格式橋接,首次調用準確率恢復至 90%+。
apply_patch 修補
03
Swarm 單點瓶頸
原生 Agent Teams 靠 task board 間接通信,消耗 7x token。SwarmEventBus 實現 peer-to-peer 廣播 + Council 投票,支援 16+ 並行 agent。
SwarmEventBus
04
Tool Search 協同
GPT-5.4 原生 Tool Search + Claude Code 3,000+ MCP 工具庫正向疊加。動態路由消除靜態全量傳遞,節省 47% token 消耗。
動態 Tool 路由
Architecture
五層系統架構
請求從用戶入口到 GPT-5.4 的完整鏈路
1
Claude Code CLI v2.1.88
用戶交互層 · CLAUDE.md · Hooks · Skills · Auto-memory
/loop40+ ToolsHTTP Hooks
↓ API Request → claude-opus-4-6
2
ccproxy 攔截層
本地 3001 端口 · 模型名稱映射 · 請求重寫
路由規則task_type
↓ 轉換為 OpenAI API 格式
3
QueryEngine + ApplyPatchTool
Tool Search 路由 · apply_patch 適配 · Schema 橋接
apply_patchTool Search
↓ Swarm 任務並行分發
4
SwarmOrchestrator + EventBus
Planner → Worker Pool → Validator · p2p 廣播 · Council 投票
16+ Agentp2pCouncil
↓ HTTPS → api.openai.com
5
GPT-5.4
400K context · Tool Search 原生支援 · SWE-bench 80.8%
SWE 80.8%Terminal 77.3%
Execution Flow
Swarm 執行流程
任務在三層 Swarm 架構中的完整生命週期
📝
用戶任務
CLAUDE.md
🧠
Planner
GPT-5.4
Workers
Promise.all
📡
EventBus
p2p 廣播
Validator
Council 投票
🎯
Hook
回調通知
Implementation
核心代碼
四個關鍵文件完整修補方案
src/tools/ApplyPatchTool.ts TypeScript
// 修補 GPT-5.4 的 apply_patch schema 不兼容問題
import fs from 'fs'
import { Tool } from './Tool'

export class ApplyPatchTool extends Tool {
  name = 'apply_patch'
  description = `Apply unified diff patch.
*** Begin Patch
*** Update File: path/to/file
@@ -N,M +N,M @@
-removed line
+added line
*** End Patch`

  async execute(input: { patch: string }) {
    const blocks = this.parsePatchBlocks(input.patch)
    const results: string[] = []
    for (const block of blocks) {
      await this.applyBlock(block)
      results.push(`✓ ${block.action}: ${block.filePath}`)
    }
    return { content: results.join('
') }
  }

  private applyHunk(lines: string[], hunk: string) {
    const match = hunk.match(/^@@ -(\d+)/m)
    let ptr = match ? parseInt(match[1]) - 1 : 0
    for (const line of hunk.split('
').slice(1)) {
      if      (line[0] === '-') lines.splice(ptr, 1)
      else if (line[0] === '+') lines.splice(ptr++, 0, line.slice(1))
      else if (line[0] === ' ') ptr++
    }
  }
}
src/coordinator/SwarmOrchestrator.ts TypeScript
import { SwarmEventBus } from './SwarmEventBus'

export class GPTSwarmOrchestrator {
  private bus = new SwarmEventBus()
  private model = 'gpt-5.4'

  async runSwarm(task: string, parallelism = 8) {
    // Step 1 — Planner 分解任務
    const raw = await this.callModel({
      messages: [{ role: 'user',
        content: `Decompose into ≤${parallelism} independent subtasks.
JSON: {"tasks":["..."]}

${task}` }],
      response_format: { type: 'json_object' }
    })
    const { tasks } = JSON.parse(raw)

    // Step 2 — Workers 並行
    const results = await Promise.all(
      tasks.map((t: string, i: number) =>
        this.runWorker(`worker-${i}`, t))
    )

    // Step 3 — Validator 整合
    return this.callModel({
      messages: [{ role: 'user',
        content: `Merge and validate:
${results.join('
---
')}` }]
    })
  }

  private async runWorker(id: string, task: string) {
    const result = await this.callModel({
      messages: [{ role: 'user', content: task }],
      tools: ['read_file', 'write_file', 'bash', 'apply_patch']
    })
    this.bus.broadcastFinding(id, { type: 'result', content: result })
    return result
  }
}
src/coordinator/SwarmEventBus.ts TypeScript
import EventEmitter from 'events'

export class SwarmEventBus extends EventEmitter {
  broadcastFinding(from: string, finding: {
    type: 'blocker' | 'discovery' | 'result'
    content: string
    targets?: string[]
  }) {
    const to = finding.targets ?? ['*']
    to.forEach(t => this.emit(`agent:${t}:msg`, { from, ...finding, ts: Date.now() }))
  }

  // Council 投票:多數決
  async councilVote(q: string, agents: string[]): Promise<string> {
    const votes = await Promise.all(agents.map(id => this.queryAgent(id, q)))
    const tally = votes.reduce((acc, v) =>
      ({ ...acc, [v]: (acc[v] || 0) + 1 }), {} as Record<string, number>)
    return Object.entries(tally).sort(([,a],[,b]) => b - a)[0][0]
  }
}
ccproxy-config.yaml YAML
# 全部 Claude 模型路由至 gpt-5.4
routes:
  - when:
      model: claude-opus-4-6
    use: openai/gpt-5.4

  - when:
      model: claude-sonnet-4-6
    use: openai/gpt-5.4

  - when:
      model: claude-haiku-4-6
    use: openai/gpt-5.4

litellm:
  base_url: https://api.openai.com/v1
  api_key: ${OPENAI_API_KEY}
Configuration
CLIproxyAPI 接入說明
透過 Custom Base URL 將 Claude Code 所有請求路由至 GPT-5.4
Step 1
環境變量設定
將 Claude Code 的 API endpoint 指向 CLIproxyAPI 本地端口
~/.bashrc 或 ~/.zshrc Shell
# 將 Anthropic API 請求重定向至 CLIproxyAPI
export ANTHROPIC_BASE_URL="http://localhost:3001"
export ANTHROPIC_API_KEY="any-string"  # proxy 不驗證此值
export OPENAI_API_KEY="sk-your-actual-openai-key"

# 啟動 CLIproxyAPI(另開終端)
# npx cliproxy --port 3001 --config ccproxy-config.yaml
Step 2
ccproxy-config.yaml 路由規則
將所有 Claude 模型名稱映射至 GPT-5.4,CLIproxyAPI 自動完成格式轉換
ccproxy-config.yaml YAML
server:
  port: 3001
  host: 127.0.0.1

upstream:
  provider: openai
  base_url: https://api.openai.com/v1
  api_key: ${OPENAI_API_KEY}

routes:
  - when: { model: claude-opus-4-6 }
    use: gpt-5.4
  - when: { model: claude-sonnet-4-6 }
    use: gpt-5.4
  - when: { model: claude-haiku-4-6 }
    use: gpt-5.4

transform:
  anthropic_to_openai: true   # 自動轉換 tool schema
  stream_passthrough: true   # 保持 SSE streaming
Step 3
QueryEngine.ts 自定義 Base URL
在源碼層面指定 base URL,確保硬編碼路徑也走 proxy
src/QueryEngine.ts(修改段) TypeScript
import Anthropic from '@anthropic-ai/sdk'

const client = new Anthropic({
  // 指向 CLIproxyAPI,覆蓋預設 api.anthropic.com
  baseURL: process.env.ANTHROPIC_BASE_URL
          ?? 'http://localhost:3001',
  apiKey:  process.env.ANTHROPIC_API_KEY
          ?? 'proxy-key',
})

// 請求時仍使用 claude-opus-4-6 名稱
// CLIproxyAPI 攔截後自動替換為 gpt-5.4
const response = await client.messages.create({
  model: 'claude-opus-4-6',
  max_tokens: 8192,
  messages: context.messages,
  tools:    context.tools,
})
驗證
確認路由生效
啟動後執行以下指令,確認請求實際抵達 GPT-5.4
Terminal Shell
# 測試 proxy 是否正常運行
$ curl http://localhost:3001/v1/models | jq

# 預期輸出包含 gpt-5.4
# { "data": [{ "id": "gpt-5.4", ... }] }

# 啟動 Claude Code,確認 model 攔截日誌
$ claude
# CLIproxyAPI log: claude-opus-4-6 → gpt-5.4 ✓
CLIproxyAPI 在本地完成 Anthropic ↔ OpenAI 的 API 格式轉換(tool_use / function_calling schema、stream format、stop_reason 映射),Claude Code 無需感知底層模型切換。