opc-architecture
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOPC Architecture Understanding
OPC架构解析
OPC (Orchestrated Parallel Claude) extends Claude Code - it does NOT replace it.
OPC(Orchestrated Parallel Claude)是Claude Code的扩展,而非替代方案。
Core Concept
核心概念
Claude Code CLI is the execution engine. OPC adds orchestration via:
- Hooks - Intercept Claude Code events (PreToolUse, PostToolUse, SessionStart, etc.)
- Skills - Load prompts into Claude Code
- Scripts - Called by hooks/skills for coordination
- Database - Store state between Claude Code instances
Claude Code CLI是执行引擎。OPC通过以下方式实现编排功能:
- 钩子(Hooks) - 拦截Claude Code的各类事件(如PreToolUse、PostToolUse、SessionStart等)
- 技能(Skills) - 向Claude Code加载提示词
- 脚本(Scripts) - 由钩子/技能调用,用于协调工作
- 数据库(Database) - 在多个Claude Code实例之间存储状态信息
How Agents Work
Agent的工作机制
When you spawn an agent:
- Main Claude Code instance (your terminal) runs hook on Task tool
- Hook calls
subprocess.Popen(["claude", "-p", "prompt"]) - A NEW Claude Code instance spawns as child process
- Child runs independently, reads/writes to coordination DB
- Parent tracks child via PID in DB
$ claude ← Main Claude Code (your terminal)
↓ Task tool triggers hook
↓ subprocess.Popen(["claude", "-p", "..."])
├── claude -p "research..." ← Child agent 1
├── claude -p "implement..." ← Child agent 2
└── claude -p "test..." ← Child agent 3当你生成一个Agent时:
- 主Claude Code实例(即你的终端)在Task工具上运行钩子
- 钩子调用
subprocess.Popen(["claude", "-p", "prompt"]) - 新的Claude Code实例作为子进程生成
- 子进程独立运行,可对协调数据库进行读写操作
- 父进程通过数据库中的PID跟踪子进程状态
$ claude ← Main Claude Code (your terminal)
↓ Task tool triggers hook
↓ subprocess.Popen(["claude", "-p", "..."])
├── claude -p "research..." ← Child agent 1
├── claude -p "implement..." ← Child agent 2
└── claude -p "test..." ← Child agent 3What OPC Is NOT
OPC并非以下事物
- OPC is NOT a separate application
- OPC does NOT run without Claude Code
- OPC does NOT intercept Claude API calls directly
- OPC does NOT modify Claude Code's internal behavior
- OPC不是独立的应用程序
- 脱离Claude Code,OPC无法运行
- OPC不会直接拦截Claude API调用
- OPC不会修改Claude Code的内部行为
What OPC IS
OPC的本质
- OPC IS hooks that Claude Code loads from
.claude/hooks/ - OPC IS skills that Claude Code loads from
.claude/skills/ - OPC IS scripts that hooks/skills call for coordination
- OPC IS a database backend for state across Claude Code instances
- OPC是Claude Code从目录加载的钩子集合
.claude/hooks/ - OPC是Claude Code从目录加载的技能集合
.claude/skills/ - OPC是由钩子/技能调用的协调脚本
- OPC是用于跨Claude Code实例存储状态的数据库后端
Key Files
核心文件结构
.claude/
├── hooks/ ← TypeScript hooks that Claude Code runs
├── skills/ ← SKILL.md prompts that Claude Code loads
├── settings.json ← Hook registration, Claude Code reads this
└── cache/ ← State files, agent outputs
opc/
├── scripts/ ← Python scripts called by hooks
├── docker-compose.yml ← PostgreSQL, Redis, PgBouncer
└── init-db.sql ← Database schema.claude/
├── hooks/ ← TypeScript hooks that Claude Code runs
├── skills/ ← SKILL.md prompts that Claude Code loads
├── settings.json ← Hook registration, Claude Code reads this
└── cache/ ← State files, agent outputs
opc/
├── scripts/ ← Python scripts called by hooks
├── docker-compose.yml ← PostgreSQL, Redis, PgBouncer
└── init-db.sql ← Database schemaCoordination Flow
协调流程
- User runs in terminal
claude - Claude Code loads hooks from
.claude/settings.json - User says "spawn a research agent"
- Claude uses Task tool
- PreToolUse hook fires, checks resources
- Hook spawns as subprocess
claude -p "research..." - Hook stores PID in PostgreSQL
- Child agent runs, writes output to
.claude/cache/agents/<id>/ - Child completes, broadcasts "done" to PostgreSQL
- Parent checks DB, reads child's output file
- 用户在终端中运行命令
claude - Claude Code从加载钩子
.claude/settings.json - 用户输入‘生成一个研究Agent’
- Claude调用Task工具
- PreToolUse钩子触发,检查资源状态
- 钩子生成作为子进程
claude -p "research..." - 钩子将PID存储到PostgreSQL数据库中
- 子Agent运行,并将输出写入目录
.claude/cache/agents/<id>/ - 子Agent完成任务后,向PostgreSQL发送‘完成’信号
- 父进程检查数据库,读取子进程的输出文件
Remember
要点总结
- Every "agent" is just another process
claude -p - Hooks intercept events, they don't create new functionality
- All coordination happens via files and PostgreSQL
- Claude Code is always the execution engine
- 每个‘Agent’本质上都是另一个进程
claude -p - 钩子仅拦截事件,不创建新功能
- 所有协调工作通过文件和PostgreSQL实现
- Claude Code始终是核心执行引擎