คู่มือ Subsystems
เอกสารละเอียดของ subsystems หลักใน Claude Code
สารบัญ
- Bridge (IDE Integration)
- MCP (Model Context Protocol)
- Permission System
- Plugin System
- Skill System
- Task System
- Memory System
- Coordinator (Multi-Agent)
- Voice System
- Service Layer
Bridge (IDE Integration)
Location: src/bridge/
Bridge คือ bidirectional communication layer ที่เชื่อมต่อ Claude Code CLI กับ IDE extensions (VS Code, JetBrains) โดยให้ CLI ทำงานเป็น backend สำหรับ IDE-based interfaces
สถาปัตยกรรม
┌──────────────────┐ ┌──────────────────────┐
│ IDE Extension │◄───────►│ Bridge Layer │
│ (VS Code, JB) │ JWT │ (src/bridge/) │
│ │ Auth │ │
│ - UI rendering │ │ - Session mgmt │
│ - File watching │ │ - Message routing │
│ - Diff display │ │ - Permission proxy │
└──────────────────┘ └──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Claude Code Core │
│ (QueryEngine, Tools) │
└──────────────────────┘
Key Files
| ไฟล์ | วัตถุประสงค์ |
|---|---|
bridgeMain.ts | Bridge loop หลัก — เริ่ม bidirectional channel |
bridgeMessaging.ts | Message protocol (serialize/deserialize) |
bridgePermissionCallbacks.ts | Route permission prompts ไปยัง IDE |
bridgeApi.ts | API surface ที่เปิดเผยต่อ IDE |
bridgeConfig.ts | Bridge configuration |
replBridge.ts | เชื่อมต่อ REPL session กับ bridge |
jwtUtils.ts | JWT-based authentication ระหว่าง CLI และ IDE |
sessionRunner.ts | จัดการ bridge session execution |
createSession.ts | สร้าง bridge sessions ใหม่ |
trustedDevice.ts | Device trust verification |
workSecret.ts | Workspace-scoped secrets |
inboundMessages.ts | จัดการ messages จาก IDE |
inboundAttachments.ts | จัดการ file attachments จาก IDE |
types.ts | TypeScript types สำหรับ bridge protocol |
Feature Flag
Bridge ถูก gate ไว้หลัง feature flag BRIDGE_MODE และถูกตัดออกจาก non-IDE builds
MCP (Model Context Protocol)
Location: src/services/mcp/
Claude Code ทำงานทั้งในฐานะ MCP client (ใช้งาน tools/resources จาก MCP servers) และสามารถทำงานเป็น MCP server (เปิดเผย tools ของตัวเองผ่าน src/entrypoints/mcp.ts)
Client Features
- Tool discovery — ระบุ tools จาก MCP servers ที่เชื่อมต่อ
- Resource browsing — แสดงและอ่าน MCP-exposed resources
- Dynamic tool loading —
ToolSearchToolค้นพบ tools ขณะ runtime - Authentication —
McpAuthToolจัดการ MCP server auth flows - Connectivity monitoring — hook
useMcpConnectivityStatusติดตาม connection health
Server Mode
เมื่อเปิดผ่าน src/entrypoints/mcp.ts Claude Code เปิดเผย tools และ resources ของตัวเองผ่าน MCP protocol ให้ AI agents อื่นใช้ Claude Code เป็น tool server
Related Tools
| Tool | วัตถุประสงค์ |
|---|---|
MCPTool | เรียกใช้ tools บน MCP servers ที่เชื่อมต่อ |
ListMcpResourcesTool | แสดง MCP resources ที่มี |
ReadMcpResourceTool | อ่าน MCP resource เฉพาะ |
McpAuthTool | ยืนยันตัวตนกับ MCP server |
ToolSearchTool | ค้นพบ deferred tools จาก MCP servers |
Configuration
MCP servers ตั้งค่าผ่าน /mcp command หรือไฟล์ settings approval flow อยู่ใน src/services/mcpServerApproval.tsx
Permission System
Location: src/hooks/toolPermission/
ทุก tool invocation ผ่าน centralized permission check ก่อน execute
Permission Modes
| โหมด | พฤติกรรม |
|---|---|
default | แจ้งให้ user อนุมัติสำหรับแต่ละ operation ที่อาจทำลายข้อมูล |
plan | แสดง execution plan ทั้งหมด ขออนุมัติ batch ครั้งเดียว |
bypassPermissions | อนุมัติ operations ทั้งหมดอัตโนมัติ (อันตราย — สำหรับ trusted environments) |
auto | ML-based classifier ตัดสินใจอัตโนมัติ (experimental) |
วิธีการทำงาน
- Tool ถูกเรียกโดย Query Engine
checkPermissions(input, context)ถูกเรียกบน tool- Permission handler ตรวจสอบกับ rules ที่ตั้งค่าไว้
- หากไม่ได้ auto-approved user จะได้รับการแจ้งผ่าน terminal หรือ IDE
Permission Rules
Rules ใช้ wildcard patterns เพื่อ match tool invocations:
Bash(git *) # อนุญาต git commands ทั้งหมดโดยไม่ต้องถาม
Bash(npm test) # อนุญาต 'npm test' โดยเฉพาะ
FileEdit(/src/*) # อนุญาตแก้ไขทุกอย่างใต้ src/
FileRead(*) # อนุญาตอ่านทุกไฟล์
Key Files
| ไฟล์ | Path |
|---|---|
| Permission context | src/hooks/toolPermission/PermissionContext.ts |
| Permission handlers | src/hooks/toolPermission/handlers/ |
| Permission logging | src/hooks/toolPermission/permissionLogging.ts |
| Permission types | src/types/permissions.ts |
Plugin System
Location: src/plugins/, src/services/plugins/
Claude Code รองรับ installable plugins ที่สามารถขยาย capabilities ได้
โครงสร้าง
| Component | Location | วัตถุประสงค์ |
|---|---|---|
| Plugin loader | src/services/plugins/ | ค้นพบและโหลด plugins |
| Built-in plugins | src/plugins/builtinPlugins.ts | Plugins ที่มาพร้อมกับ Claude Code |
| Bundled plugins | src/plugins/bundled/ | Plugin code ที่ bundle ในตัว binary |
| Plugin types | src/types/plugin.ts | TypeScript types สำหรับ plugin API |
Plugin Lifecycle
- Discovery — สแกน plugin directories และ marketplace
- Installation — ดาวน์โหลดและลงทะเบียน (ผ่าน
/plugincommand) - Loading — เริ่มต้นเมื่อ startup หรือ on-demand
- Execution — Plugins สามารถ contribute tools, commands และ prompts
- Auto-update —
usePluginAutoupdateNotificationจัดการการอัปเดต
Related Commands
| Command | วัตถุประสงค์ |
|---|---|
/plugin | ติดตั้ง ลบ หรือจัดการ plugins |
/reload-plugins | โหลด plugins ที่ติดตั้งทั้งหมดใหม่ |
Skill System
Location: src/skills/
Skills คือ workflows ที่นำกลับมาใช้ใหม่ได้และมีชื่อ ที่รวม prompts และ tool configurations สำหรับงานเฉพาะ
โครงสร้าง
| Component | Location | วัตถุประสงค์ |
|---|---|---|
| Bundled skills | src/skills/bundled/ | Skills ที่มาพร้อมกับ Claude Code |
| Skill loader | src/skills/loadSkillsDir.ts | โหลด skills จาก disk |
| MCP skill builders | src/skills/mcpSkillBuilders.ts | สร้าง skills จาก MCP resources |
| Skill registry | src/skills/bundledSkills.ts | การลงทะเบียน bundled skills ทั้งหมด |
Bundled Skills (16 รายการ)
| Skill | วัตถุประสงค์ |
|---|---|
batch | Batch operations ข้ามหลายไฟล์ |
claudeApi | การโต้ตอบ Anthropic API โดยตรง |
claudeInChrome | Chrome extension integration |
debug | Debugging workflows |
keybindings | การตั้งค่า keybinding |
loop | Iterative refinement loops |
loremIpsum | สร้าง placeholder text |
remember | บันทึกข้อมูลไว้ใน memory |
scheduleRemoteAgents | กำหนดเวลา agents สำหรับ remote execution |
simplify | ลดความซับซ้อนของโค้ด |
skillify | สร้าง skills ใหม่จาก workflows |
stuck | ได้รับความช่วยเหลือเมื่อติดขัด |
updateConfig | แก้ไข configuration แบบ programmatic |
verify / verifyContent | ตรวจสอบความถูกต้องของโค้ด |
Execution
Skills ถูกเรียกผ่าน SkillTool หรือ /skills command ผู้ใช้ยังสามารถสร้าง custom skills ได้
Task System
Location: src/tasks/
จัดการ background และ parallel work items — shell tasks, agent tasks และ teammate agents
Task Types
| ประเภท | Location | วัตถุประสงค์ |
|---|---|---|
LocalShellTask | LocalShellTask/ | Background shell command execution |
LocalAgentTask | LocalAgentTask/ | Sub-agent ที่ทำงานใน local |
RemoteAgentTask | RemoteAgentTask/ | Agent ที่ทำงานบน remote machine |
InProcessTeammateTask | InProcessTeammateTask/ | Parallel teammate agent |
DreamTask | DreamTask/ | Background “dreaming” process |
LocalMainSessionTask | LocalMainSessionTask.ts | Main session ในฐานะ task |
Task Tools
| Tool | วัตถุประสงค์ |
|---|---|
TaskCreateTool | สร้าง background task ใหม่ |
TaskUpdateTool | อัปเดตสถานะ task |
TaskGetTool | ดึงรายละเอียด task |
TaskListTool | แสดงรายการ tasks ทั้งหมด |
TaskOutputTool | ดู task output |
TaskStopTool | หยุด task ที่กำลังทำงาน |
Memory System
Location: src/memdir/
ระบบ persistent memory ของ Claude Code อิงตาม CLAUDE.md files
Memory Hierarchy
| Scope | Location | วัตถุประสงค์ |
|---|---|---|
| Project memory | CLAUDE.md ใน project root | ข้อเท็จจริง conventions เฉพาะ project |
| User memory | ~/.claude/CLAUDE.md | User preferences ข้าม project |
| Extracted memories | src/services/extractMemories/ | Auto-extracted จาก conversations |
| Team memory sync | src/services/teamMemorySync/ | ความรู้ที่แชร์ในทีม |
Related
/memorycommand สำหรับจัดการ memoriesrememberskill สำหรับบันทึกข้อมูลuseMemoryUsagehook สำหรับติดตามขนาด memory
Coordinator (Multi-Agent)
Location: src/coordinator/
Orchestrate agents หลายตัวที่ทำงานพร้อมกันบนแง่มุมต่างๆ ของงาน
วิธีการทำงาน
coordinatorMode.tsจัดการ coordinator lifecycleTeamCreateToolและTeamDeleteToolจัดการทีม agentsSendMessageToolช่วยให้ agents สื่อสารกันได้AgentToolspawn sub-agents
Gate ไว้หลัง feature flag COORDINATOR_MODE
Voice System
Location: src/voice/
รองรับ voice input/output สำหรับ hands-free interaction
Components
| ไฟล์ | Location | วัตถุประสงค์ |
|---|---|---|
| Voice service | src/services/voice.ts | Core voice processing |
| STT streaming | src/services/voiceStreamSTT.ts | Speech-to-text streaming |
| Key terms | src/services/voiceKeyterms.ts | Domain-specific vocabulary |
| Voice hooks | src/hooks/useVoice.ts, useVoiceEnabled.ts, useVoiceIntegration.tsx | React hooks |
| Voice command | src/commands/voice/ | /voice slash command |
Gate ไว้หลัง feature flag VOICE_MODE
Service Layer
Location: src/services/
External integrations และ shared services
| Service | Path | วัตถุประสงค์ |
|---|---|---|
| API | api/ | Anthropic SDK client, file uploads, bootstrap |
| MCP | mcp/ | MCP client connections และ tool discovery |
| OAuth | oauth/ | OAuth 2.0 authentication flow |
| LSP | lsp/ | Language Server Protocol manager |
| Analytics | analytics/ | GrowthBook feature flags, telemetry |
| Plugins | plugins/ | Plugin loader และ marketplace |
| Compact | compact/ | Conversation context compression |
| Policy Limits | policyLimits/ | Organization rate limits/quota |
| Remote Settings | remoteManagedSettings/ | Enterprise managed settings sync |
| Token Estimation | tokenEstimation.ts | Token count estimation |
| Team Memory | teamMemorySync/ | Team knowledge synchronization |
| Tips | tips/ | Contextual usage tips |
| Agent Summary | AgentSummary/ | Agent work summaries |
| Prompt Suggestion | PromptSuggestion/ | Suggested follow-up prompts |
| Session Memory | SessionMemory/ | Session-level memory |
| Magic Docs | MagicDocs/ | Documentation generation |
| Auto Dream | autoDream/ | Background ideation |
| x402 | x402/ | x402 payment protocol |
ดูเพิ่มเติม
- Architecture — วิธีที่ subsystems เชื่อมต่อใน core pipeline
- Tools Reference — Tools ที่เกี่ยวข้องกับแต่ละ subsystem
- Commands Reference — Commands สำหรับจัดการ subsystems
- Exploration Guide — การค้นหา source code ของ subsystem