cc-harness-patterns
Harness Engineering 設計模式 — 基於 Claude Code 原始碼逆向分析的 12 條可遷移原則。Use when: 設計 agent 系統架構、實作 tool orchestration、設計 context 管理策略、建構 agent loop。
npx skills add majiayu000/claude-skill-registry --skill cc-harness-patterns --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Harness Engineering 設計模式 `Harness = Tools + Knowledge + Observation + Action Interfaces + Permissions` 基於 Claude Code v2.1.88(92,500 行 TypeScript)逆向分析。 ## 1. Agent Loop:Async Generator 模式 Claude Code 的 agent loop 用 async generator 實作: ```typescript async function* queryModel(...): AsyncGenerator<StreamEvent | AssistantMessage> { // yield 每個 stream event,呼叫端按需消費 } ``` **核心循環**:`queryModel()` → 檢查 `stop_reason` → `tool_use` 時呼叫 `runTools()` → 結果回注 messages → 再次 `queryModel()` **stop_reason 分支**:`end_turn`(結束)、`tool_use`(執行工具)、`max_tokens`(context 滿了,觸發 compaction) ## 2. Tool Orchestration:讀寫分離 ```typescript function isConcurrencySafe(input): boolean { // 工具自己聲明是否可並行 } ``` - `partitionToolCalls()` 把一批工具呼叫分成可並行組和必須串行組 - **讀工具自動合批並行**(FileRead、Grep、Glob) - **寫工具強制串行**(FileEdit、FileWrite、Bash) - 決策權在工具端(Single Responsibility),不在 orchestrator ## 3. 工具執行 7 層管道 ``` Schema Validation → Custom validateInput() → Input Sanitization → PreToolUse Hooks → Permission Resolution → Execution → PostToolUse Hooks ``` 每層只問一個問題:「能否拒絕?」拒絕即停,不往下走。執行邏輯永遠在最後一層。 ## 4. Cache 穩定性模式 **Sticky Latch**:影響 cache key 的欄位一旦啟用就不在 session 內關閉。 ```typescript if (!fastModeHeaderLatched && isFastMode) { fastModeHeaderLat
- 1. Agent Loop:Async Generator 模式
- 2. Tool Orchestration:讀寫分離
- 3. 工具執行 7 層管道
- 4. Cache 穩定性模式
- 5. Context Engineering
- 6. Multi-session Continuity
- 7. Observability
- 參考
What does the cc-harness-patterns skill do?
Harness Engineering 設計模式 — 基於 Claude Code 原始碼逆向分析的 12 條可遷移原則。Use when: 設計 agent 系統架構、實作 tool orchestration、設計 context 管理策略、建構 agent loop。
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill cc-harness-patterns --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
