opc-architecture

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OPC 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:
  1. Main Claude Code instance (your terminal) runs hook on Task tool
  2. Hook calls
    subprocess.Popen(["claude", "-p", "prompt"])
  3. A NEW Claude Code instance spawns as child process
  4. Child runs independently, reads/writes to coordination DB
  5. 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时:
  1. 主Claude Code实例(即你的终端)在Task工具上运行钩子
  2. 钩子调用
    subprocess.Popen(["claude", "-p", "prompt"])
  3. 新的Claude Code实例作为子进程生成
  4. 子进程独立运行,可对协调数据库进行读写操作
  5. 父进程通过数据库中的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 3

What 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 schema

Coordination Flow

协调流程

  1. User runs
    claude
    in terminal
  2. Claude Code loads hooks from
    .claude/settings.json
  3. User says "spawn a research agent"
  4. Claude uses Task tool
  5. PreToolUse hook fires, checks resources
  6. Hook spawns
    claude -p "research..."
    as subprocess
  7. Hook stores PID in PostgreSQL
  8. Child agent runs, writes output to
    .claude/cache/agents/<id>/
  9. Child completes, broadcasts "done" to PostgreSQL
  10. Parent checks DB, reads child's output file
  1. 用户在终端中运行
    claude
    命令
  2. Claude Code从
    .claude/settings.json
    加载钩子
  3. 用户输入‘生成一个研究Agent’
  4. Claude调用Task工具
  5. PreToolUse钩子触发,检查资源状态
  6. 钩子生成
    claude -p "research..."
    作为子进程
  7. 钩子将PID存储到PostgreSQL数据库中
  8. 子Agent运行,并将输出写入
    .claude/cache/agents/<id>/
    目录
  9. 子Agent完成任务后,向PostgreSQL发送‘完成’信号
  10. 父进程检查数据库,读取子进程的输出文件

Remember

要点总结

  • Every "agent" is just another
    claude -p
    process
  • 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始终是核心执行引擎