@kood/claude-code 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/index.js +69 -12
  2. package/package.json +2 -1
  3. package/templates/.claude/PARALLEL_AGENTS.md +737 -0
  4. package/templates/.claude/agents/analyst.md +416 -0
  5. package/templates/.claude/agents/architect.md +569 -0
  6. package/templates/.claude/agents/code-reviewer.md +132 -133
  7. package/templates/.claude/agents/dependency-manager.md +93 -94
  8. package/templates/.claude/agents/deployment-validator.md +64 -65
  9. package/templates/.claude/agents/designer.md +655 -0
  10. package/templates/.claude/agents/document-writer.md +500 -0
  11. package/templates/.claude/agents/explore.md +499 -0
  12. package/templates/.claude/agents/git-operator.md +74 -75
  13. package/templates/.claude/agents/implementation-executor.md +138 -109
  14. package/templates/.claude/agents/ko-to-en-translator.md +18 -22
  15. package/templates/.claude/agents/lint-fixer.md +250 -93
  16. package/templates/.claude/agents/planner.md +356 -0
  17. package/templates/.claude/agents/refactor-advisor.md +135 -136
  18. package/templates/.claude/commands/bug-fix.md +296 -207
  19. package/templates/.claude/commands/git-all.md +199 -46
  20. package/templates/.claude/commands/git-session.md +113 -57
  21. package/templates/.claude/commands/lint-fix.md +219 -153
  22. package/templates/.claude/commands/lint-init.md +113 -76
  23. package/templates/.claude/commands/pre-deploy.md +190 -124
  24. package/templates/.claude/commands/refactor.md +407 -162
  25. package/templates/.claude/commands/version-update.md +138 -37
  26. package/templates/.claude/instructions/context-engineering/ANTHROPIC_CONTEXT_ENGINEERING.md +178 -0
  27. package/templates/.claude/instructions/context-engineering/references/claude-4x.md +215 -0
  28. package/templates/.claude/instructions/context-engineering/references/core-principles.md +137 -0
  29. package/templates/.claude/instructions/context-engineering/references/examples.md +351 -0
  30. package/templates/.claude/instructions/context-engineering/references/techniques.md +162 -0
  31. package/templates/.claude/instructions/parallel-agent-execution.md +874 -0
  32. package/templates/.claude/skills/docs-creator/AGENTS.md +238 -0
  33. package/templates/.claude/{commands/docs-creator.md → skills/docs-creator/SKILL.md} +61 -75
  34. package/templates/.claude/skills/docs-refactor/AGENTS.md +270 -0
  35. package/templates/.claude/{commands/docs-refactor.md → skills/docs-refactor/SKILL.md} +30 -44
  36. package/templates/.claude/skills/execute/SKILL.md +451 -0
  37. package/templates/.claude/skills/figma-to-code/AGENTS.md +287 -0
  38. package/templates/.claude/skills/figma-to-code/SKILL.md +225 -225
  39. package/templates/.claude/skills/figma-to-code/references/design-tokens.md +75 -73
  40. package/templates/.claude/skills/figma-to-code/references/figma-mcp-tools.md +73 -73
  41. package/templates/.claude/skills/figma-to-code/references/layout-mapping.md +104 -104
  42. package/templates/.claude/skills/figma-to-code/references/responsive-design.md +99 -99
  43. package/templates/.claude/skills/figma-to-code/references/verification.md +91 -91
  44. package/templates/.claude/skills/global-uiux-design/AGENTS.md +317 -0
  45. package/templates/.claude/skills/global-uiux-design/SKILL.md +738 -0
  46. package/templates/.claude/skills/global-uiux-design/references/accessibility.md +401 -0
  47. package/templates/.claude/skills/global-uiux-design/references/color-system.md +275 -0
  48. package/templates/.claude/skills/global-uiux-design/references/design-philosophy.md +206 -0
  49. package/templates/.claude/skills/global-uiux-design/references/design-systems.md +446 -0
  50. package/templates/.claude/skills/korea-uiux-design/AGENTS.md +307 -0
  51. package/templates/.claude/skills/korea-uiux-design/SKILL.md +170 -0
  52. package/templates/.claude/skills/nextjs-react-best-practices/AGENTS.md +95 -116
  53. package/templates/.claude/skills/nextjs-react-best-practices/SKILL.md +134 -152
  54. package/templates/.claude/skills/nextjs-react-best-practices/rules/advanced-event-handler-refs.md +6 -6
  55. package/templates/.claude/skills/nextjs-react-best-practices/rules/advanced-use-latest.md +5 -5
  56. package/templates/.claude/skills/nextjs-react-best-practices/rules/async-api-routes.md +5 -5
  57. package/templates/.claude/skills/nextjs-react-best-practices/rules/async-defer-await.md +22 -22
  58. package/templates/.claude/skills/nextjs-react-best-practices/rules/async-dependencies.md +5 -5
  59. package/templates/.claude/skills/nextjs-react-best-practices/rules/async-parallel.md +4 -4
  60. package/templates/.claude/skills/nextjs-react-best-practices/rules/async-suspense-boundaries.md +21 -21
  61. package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-barrel-imports.md +18 -18
  62. package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-conditional.md +4 -4
  63. package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-defer-third-party.md +4 -4
  64. package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-dynamic-imports.md +4 -4
  65. package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-preload.md +5 -5
  66. package/templates/.claude/skills/nextjs-react-best-practices/rules/client-event-listeners.md +9 -9
  67. package/templates/.claude/skills/nextjs-react-best-practices/rules/client-swr-dedup.md +7 -7
  68. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-batch-dom-css.md +13 -13
  69. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-function-results.md +14 -14
  70. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-property-access.md +4 -4
  71. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-storage.md +10 -10
  72. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-combine-iterations.md +4 -4
  73. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-early-exit.md +7 -7
  74. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-hoist-regexp.md +6 -6
  75. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-index-maps.md +6 -6
  76. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-length-check-first.md +14 -14
  77. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-min-max-loop.md +16 -16
  78. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-set-map-lookups.md +4 -4
  79. package/templates/.claude/skills/nextjs-react-best-practices/rules/js-tosorted-immutable.md +17 -17
  80. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-activity.md +4 -4
  81. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-animate-svg-wrapper.md +11 -11
  82. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-conditional-render.md +8 -8
  83. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-content-visibility.md +4 -4
  84. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-hoist-jsx.md +6 -6
  85. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-hydration-no-flicker.md +14 -14
  86. package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-svg-precision.md +5 -5
  87. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-defer-reads.md +4 -4
  88. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-dependencies.md +7 -7
  89. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-derived-state.md +5 -5
  90. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-functional-setstate.md +34 -34
  91. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-lazy-state-init.md +15 -15
  92. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-memo.md +5 -5
  93. package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-transitions.md +4 -4
  94. package/templates/.claude/skills/nextjs-react-best-practices/rules/server-after-nonblocking.md +24 -24
  95. package/templates/.claude/skills/nextjs-react-best-practices/rules/server-cache-lru.md +10 -10
  96. package/templates/.claude/skills/nextjs-react-best-practices/rules/server-cache-react.md +4 -4
  97. package/templates/.claude/skills/nextjs-react-best-practices/rules/server-parallel-fetching.md +5 -5
  98. package/templates/.claude/skills/nextjs-react-best-practices/rules/server-serialization.md +6 -6
  99. package/templates/.claude/skills/plan/SKILL.md +594 -0
  100. package/templates/.claude/skills/prd/SKILL.md +496 -0
  101. package/templates/.claude/skills/ralph/AGENTS.md +393 -0
  102. package/templates/.claude/skills/ralph/SKILL.md +1035 -0
  103. package/templates/.claude/skills/tanstack-start-react-best-practices/AGENTS.md +100 -121
  104. package/templates/.claude/skills/tanstack-start-react-best-practices/SKILL.md +139 -157
  105. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-defer-await.md +22 -22
  106. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-dependencies.md +5 -5
  107. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-loader.md +7 -7
  108. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-parallel.md +4 -4
  109. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-barrel-imports.md +18 -18
  110. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-conditional.md +4 -4
  111. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-defer-third-party.md +4 -4
  112. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-lazy-routes.md +12 -12
  113. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-preload.md +5 -5
  114. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-event-listeners.md +9 -9
  115. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-tanstack-query.md +12 -12
  116. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-batch-dom-css.md +13 -13
  117. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-function-results.md +14 -14
  118. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-property-access.md +4 -4
  119. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-storage.md +10 -10
  120. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-combine-iterations.md +4 -4
  121. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-early-exit.md +7 -7
  122. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-hoist-regexp.md +6 -6
  123. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-index-maps.md +6 -6
  124. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-length-check-first.md +14 -14
  125. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-min-max-loop.md +16 -16
  126. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-set-map-lookups.md +4 -4
  127. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-tosorted-immutable.md +17 -17
  128. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-animate-svg-wrapper.md +11 -11
  129. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-conditional-render.md +8 -8
  130. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-content-visibility.md +4 -4
  131. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-hoist-jsx.md +6 -6
  132. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-svg-precision.md +5 -5
  133. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-defer-reads.md +4 -4
  134. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-dependencies.md +7 -7
  135. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-derived-state.md +5 -5
  136. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-functional-setstate.md +34 -34
  137. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-lazy-state-init.md +15 -15
  138. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-memo.md +5 -5
  139. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-transitions.md +4 -4
  140. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-cache-lru.md +12 -12
  141. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-deferred-data.md +14 -14
  142. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-parallel-fetching.md +9 -9
  143. package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-serialization.md +6 -6
  144. package/templates/.claude/commands/agent-creator.md +0 -370
  145. package/templates/.claude/commands/command-creator.md +0 -524
  146. package/templates/.claude/commands/execute.md +0 -469
  147. package/templates/.claude/commands/git.md +0 -98
  148. package/templates/.claude/commands/plan.md +0 -526
  149. package/templates/.claude/commands/prd.md +0 -629
@@ -0,0 +1,874 @@
1
+ # Parallel Agent Execution
2
+
3
+ 병렬 에이전트 실행을 통한 성능 최적화 및 작업 효율 극대화.
4
+
5
+ ---
6
+
7
+ <purpose>
8
+
9
+ **Goal:** 독립적인 작업을 동시에 처리하여 대기 시간 최소화, 처리량 극대화, 비용 절감.
10
+
11
+ **Core Principle:** 순차 실행 → 병렬 실행으로 5-15배 성능 향상.
12
+
13
+ </purpose>
14
+
15
+ ---
16
+
17
+ <when_to_use>
18
+
19
+ ## 사용 시점
20
+
21
+ | 상황 | 설명 | 예상 효과 |
22
+ |------|------|----------|
23
+ | **독립적인 작업** | 서로 의존하지 않는 여러 작업 | 대기 시간 → 동시 실행 시간 |
24
+ | **여러 파일 수정** | 다른 파일 동시 작업 | 순차 작업 → 병렬 처리 |
25
+ | **탐색 + 구현** | 코드베이스 분석 + 기능 구현 | 별도 컨텍스트 활용 |
26
+ | **다중 도메인** | API + UI + 문서 동시 작업 | 전문 에이전트 활용 |
27
+ | **배치 처리** | 여러 아이템 동일 작업 | 토큰 70-90% 절감 |
28
+
29
+ </when_to_use>
30
+
31
+ ---
32
+
33
+ <core_principles>
34
+
35
+ ## 3대 원칙
36
+
37
+ | 원칙 | 실행 방법 | 기대 효과 |
38
+ |------|----------|----------|
39
+ | **PARALLEL** | 단일 메시지에서 여러 Tool 동시 호출 | 5-15배 속도 향상 |
40
+ | **BACKGROUND** | 10개 이상 작업 시 `run_in_background=true` | 대기 시간 제거 |
41
+ | **DELEGATE** | 전문 에이전트에게 즉시 위임 | 컨텍스트 격리, 품질 향상 |
42
+
43
+ </core_principles>
44
+
45
+ ---
46
+
47
+ <execution_patterns>
48
+
49
+ ## 실행 패턴
50
+
51
+ ### 패턴 1: 단일 메시지 병렬 실행
52
+
53
+ **원칙:** 독립적인 작업은 단일 응답에서 여러 Tool 호출.
54
+
55
+ ```typescript
56
+ // ❌ 순차 실행 (느림)
57
+ Task(subagent_type="implementation-executor", model="sonnet",
58
+ prompt="기능 A 구현")
59
+ // 대기... (60초)
60
+ Task(subagent_type="implementation-executor", model="sonnet",
61
+ prompt="기능 B 구현")
62
+ // 대기... (60초)
63
+ // 총 시간: 120초
64
+
65
+ // ✅ 병렬 실행 (빠름)
66
+ // 단일 메시지에서 두 Task 동시 호출
67
+ Task(subagent_type="implementation-executor", model="sonnet",
68
+ prompt="기능 A 구현")
69
+ Task(subagent_type="implementation-executor", model="sonnet",
70
+ prompt="기능 B 구현")
71
+ // 총 시간: 60초 (가장 긴 작업 기준)
72
+ ```
73
+
74
+ **적용 조건:**
75
+ - 작업 간 의존성 없음
76
+ - 서로 다른 파일/영역
77
+ - 결과가 서로 영향 없음
78
+
79
+ ---
80
+
81
+ ### 패턴 2: Fan-Out Fan-In
82
+
83
+ **정의:** 하나의 작업을 여러 하위 작업으로 분산(Fan-Out) → 결과 수집 및 통합(Fan-In).
84
+
85
+ ```typescript
86
+ // Fan-Out: 여러 컴포넌트 동시 구현
87
+ Task(subagent_type="designer", model="sonnet",
88
+ prompt="Header 컴포넌트 구현")
89
+ Task(subagent_type="designer", model="sonnet",
90
+ prompt="Footer 컴포넌트 구현")
91
+ Task(subagent_type="designer", model="sonnet",
92
+ prompt="Sidebar 컴포넌트 구현")
93
+
94
+ // Fan-In: 결과 수집 후 통합
95
+ Read("components/Header.tsx")
96
+ Read("components/Footer.tsx")
97
+ Read("components/Sidebar.tsx")
98
+ // → Layout.tsx에 통합
99
+ ```
100
+
101
+ **활용 사례:**
102
+ - 여러 API 엔드포인트 동시 호출
103
+ - 다중 컴포넌트 병렬 구현
104
+ - 배치 데이터 처리
105
+
106
+ ---
107
+
108
+ ### 패턴 3: 계층적 위임 (Hierarchical Delegation)
109
+
110
+ **구조:** 메인 에이전트 → 계획 + 조정, 서브 에이전트 → 실행.
111
+
112
+ ```typescript
113
+ // 메인 에이전트: 계획 수립
114
+ Task(subagent_type="planner", model="opus",
115
+ prompt="전체 아키텍처 설계 및 작업 분해")
116
+
117
+ // 서브 에이전트: 병렬 실행
118
+ Task(subagent_type="implementation-executor", model="sonnet",
119
+ prompt="Auth 모듈 구현")
120
+ Task(subagent_type="implementation-executor", model="sonnet",
121
+ prompt="User 모듈 구현")
122
+ Task(subagent_type="implementation-executor", model="sonnet",
123
+ prompt="Post 모듈 구현")
124
+ ```
125
+
126
+ **장점:**
127
+ - 컨텍스트 격리 (각 에이전트 독립 컨텍스트)
128
+ - 전문화 (도메인별 최적화)
129
+ - 재시도 용이 (실패 시 해당 에이전트만 재실행)
130
+
131
+ ---
132
+
133
+ ### 패턴 4: 배치 처리 (Batching)
134
+
135
+ **원리:** 유사 작업을 묶어서 컨텍스트 공유, 토큰 70-90% 절감.
136
+
137
+ ```typescript
138
+ // ❌ 개별 처리 (비효율)
139
+ Edit("file1.ts", ...) // 컨텍스트 전송
140
+ Edit("file2.ts", ...) // 컨텍스트 재전송
141
+ Edit("file3.ts", ...) // 컨텍스트 재전송
142
+
143
+ // ✅ 배치 처리 (효율)
144
+ Task(subagent_type="implementation-executor", model="sonnet",
145
+ prompt=`다음 파일들에 동일한 수정 적용:
146
+ - file1.ts
147
+ - file2.ts
148
+ - file3.ts
149
+
150
+ 수정 내용: [공통 규칙]`)
151
+ ```
152
+
153
+ **적용 기준:**
154
+ - 10개 이상 유사 작업
155
+ - 공통 컨텍스트 공유 가능
156
+ - 순서 무관
157
+
158
+ ---
159
+
160
+ ### 패턴 5: 백그라운드 실행
161
+
162
+ **사용 시점:** 10분 이상 소요 작업, 빌드/테스트.
163
+
164
+ ```typescript
165
+ // ✅ 백그라운드 실행
166
+ Bash("npm install", run_in_background=true)
167
+ Bash("npm run build", run_in_background=true)
168
+ Bash("npm test", run_in_background=true)
169
+
170
+ // 메인 작업 계속 진행
171
+ Task(subagent_type="implementation-executor", ...)
172
+
173
+ // 나중에 결과 확인
174
+ TaskOutput(task_id="...")
175
+ ```
176
+
177
+ **백그라운드 대상:**
178
+ - 패키지 설치 (`npm install`, `pip install`)
179
+ - 빌드 (`npm run build`, `tsc`)
180
+ - 테스트 스위트 (`npm test`, `pytest`)
181
+ - Docker 작업 (`docker build`, `docker pull`)
182
+
183
+ **포그라운드 유지:**
184
+ - 파일 읽기/쓰기 (즉시 결과 필요)
185
+ - 간단한 명령어 (`git status`, `ls`)
186
+ - 에러 즉시 처리 필요한 작업
187
+
188
+ </execution_patterns>
189
+
190
+ ---
191
+
192
+ <model_routing>
193
+
194
+ ## 스마트 모델 라우팅
195
+
196
+ **원칙:** 작업 복잡도에 따라 모델 선택, 비용 최적화.
197
+
198
+ | 복잡도 | 모델 | 작업 예시 | 비용 | 속도 |
199
+ |--------|------|----------|------|------|
200
+ | **LOW** | haiku | 파일 읽기, 정의 조회, 간단한 탐색 | 💰 | ⚡⚡⚡ |
201
+ | **MEDIUM** | sonnet | 기능 구현, 버그 수정, 리팩토링 | 💰💰 | ⚡⚡ |
202
+ | **HIGH** | opus | 아키텍처 설계, 복잡한 디버깅, 보안 | 💰💰💰 | ⚡ |
203
+
204
+ **에이전트별 권장 모델:**
205
+
206
+ | 에이전트 | 권장 모델 | 용도 |
207
+ |---------|----------|------|
208
+ | planner | opus | 아키텍처 설계, 계획 검증 |
209
+ | implementation-executor | sonnet | 일반 구현, 버그 수정 |
210
+ | explore | haiku | 코드베이스 탐색 |
211
+ | designer | sonnet/opus | UI/UX 구현 |
212
+ | document-writer | haiku/sonnet | 문서 작성 |
213
+ | deployment-validator | sonnet | typecheck/lint/build |
214
+ | code-reviewer | opus | 코드 리뷰 |
215
+ | lint-fixer | sonnet | tsc/eslint 수정 |
216
+
217
+ **예시:**
218
+
219
+ ```typescript
220
+ // ✅ 모델 명시
221
+ Task(subagent_type="explore", model="haiku",
222
+ prompt="프로젝트 구조 분석")
223
+ Task(subagent_type="implementation-executor", model="sonnet",
224
+ prompt="API 엔드포인트 구현")
225
+ Task(subagent_type="planner", model="opus",
226
+ prompt="아키텍처 검증")
227
+ ```
228
+
229
+ </model_routing>
230
+
231
+ ---
232
+
233
+ <agent_coordination>
234
+
235
+ ## 에이전트 조정 패턴
236
+
237
+ ### 서브에이전트 패턴 (Subagents Pattern)
238
+
239
+ **특징:** 메인 에이전트가 컨텍스트 유지, 서브에이전트는 stateless.
240
+
241
+ ```typescript
242
+ // 메인 에이전트: 전체 흐름 조정
243
+ // 서브에이전트 1: API 구현
244
+ Task(subagent_type="implementation-executor", model="sonnet",
245
+ prompt="User API 엔드포인트 구현")
246
+
247
+ // 서브에이전트 2: UI 구현
248
+ Task(subagent_type="designer", model="sonnet",
249
+ prompt="User Profile UI 구현")
250
+
251
+ // 서브에이전트 3: 테스트 작성
252
+ Task(subagent_type="implementation-executor", model="sonnet",
253
+ prompt="API 통합 테스트 작성")
254
+ ```
255
+
256
+ **장점:**
257
+ - 컨텍스트 격리 (재귀 위임 방지)
258
+ - 병렬 실행 (독립적인 작업)
259
+ - 재사용 가능 (전문화된 에이전트)
260
+
261
+ ---
262
+
263
+ ### 순차 파이프라인 (Sequential Pipeline)
264
+
265
+ **용도:** 단계별 의존성 있는 작업.
266
+
267
+ ```typescript
268
+ // Step 1: 분석
269
+ Task(subagent_type="explore", model="haiku",
270
+ prompt="기존 인증 로직 분석")
271
+
272
+ // 분석 결과 기반 Step 2: 구현
273
+ Task(subagent_type="implementation-executor", model="sonnet",
274
+ prompt="분석 결과 바탕으로 새 인증 로직 구현")
275
+
276
+ // Step 3: 검증
277
+ Task(subagent_type="deployment-validator", model="sonnet",
278
+ prompt="구현 완료 후 typecheck/lint/build 검증")
279
+ ```
280
+
281
+ **주의:** 순차 실행 시 각 단계는 이전 단계 완료 필수.
282
+
283
+ ---
284
+
285
+ ### 라우터/디스패처 패턴 (Router Pattern)
286
+
287
+ **정의:** 중앙 에이전트가 작업 분석 후 전문 에이전트에게 라우팅.
288
+
289
+ ```typescript
290
+ // 작업 분석
291
+ const taskType = analyzeTask(userRequest)
292
+
293
+ // 조건부 라우팅
294
+ if (taskType === "frontend") {
295
+ Task(subagent_type="designer", model="sonnet", ...)
296
+ } else if (taskType === "backend") {
297
+ Task(subagent_type="implementation-executor", model="sonnet", ...)
298
+ } else if (taskType === "documentation") {
299
+ Task(subagent_type="document-writer", model="haiku", ...)
300
+ }
301
+ ```
302
+
303
+ **활용:** 복잡한 요청을 도메인별로 자동 분배.
304
+
305
+ </agent_coordination>
306
+
307
+ ---
308
+
309
+ <context_preservation>
310
+
311
+ ## 컨텍스트 보존 전략
312
+
313
+ ### 문제: 병렬 실행 시 컨텍스트 손실
314
+
315
+ **원인:**
316
+ - 서브에이전트는 독립 컨텍스트
317
+ - 메인 에이전트 컨텍스트와 분리
318
+ - 결과만 전달됨
319
+
320
+ ### 해결책
321
+
322
+ #### 1. 공유 상태 관리
323
+
324
+ ```typescript
325
+ // ❌ 컨텍스트 손실
326
+ Task(subagent_type="implementation-executor",
327
+ prompt="모듈 A 구현")
328
+ Task(subagent_type="implementation-executor",
329
+ prompt="모듈 B 구현")
330
+ // → 서로 모듈 존재 모름
331
+
332
+ // ✅ 공유 상태 명시
333
+ Task(subagent_type="implementation-executor",
334
+ prompt=`모듈 A 구현
335
+
336
+ 공유 상태:
337
+ - 프로젝트 구조: [설명]
338
+ - 공통 인터페이스: [설명]
339
+ - 의존성: [리스트]`)
340
+
341
+ Task(subagent_type="implementation-executor",
342
+ prompt=`모듈 B 구현 (모듈 A와 통합)
343
+
344
+ 공유 상태:
345
+ - 프로젝트 구조: [설명]
346
+ - 공통 인터페이스: [설명]
347
+ - 모듈 A 위치: [경로]`)
348
+ ```
349
+
350
+ #### 2. 문서 기반 컨텍스트
351
+
352
+ **활용:** 상태 문서 파일로 컨텍스트 공유.
353
+
354
+ ```typescript
355
+ // Step 1: 상태 문서 생성
356
+ Write(".claude/context/project-state.md", `
357
+ # Project State
358
+
359
+ ## Architecture
360
+ - Auth: JWT 기반
361
+ - Database: Prisma + PostgreSQL
362
+ - API: TanStack Start Server Functions
363
+
364
+ ## Modules
365
+ - User: 완료
366
+ - Auth: 진행 중
367
+ - Post: 대기
368
+ `)
369
+
370
+ // Step 2: 병렬 실행 시 문서 참조
371
+ Task(subagent_type="implementation-executor",
372
+ prompt="@.claude/context/project-state.md 참조하여 Post 모듈 구현")
373
+ ```
374
+
375
+ #### 3. 컨텍스트 컴팩션 (Context Compaction)
376
+
377
+ **문제:** 토큰 한계 도달 시 이전 작업 손실.
378
+
379
+ **해결책:**
380
+
381
+ ```typescript
382
+ // 주기적 요약 및 저장
383
+ Task(subagent_type="document-writer", model="haiku",
384
+ prompt=`현재까지 작업 요약하여 .claude/context/summary.md에 저장
385
+
386
+ 포함 내용:
387
+ - 완료된 작업
388
+ - 중요 의사결정
389
+ - 다음 단계`)
390
+ ```
391
+
392
+ **컨텍스트 복구:**
393
+
394
+ ```text
395
+ 1. pwd → 작업 디렉토리 확인
396
+ 2. Read(".claude/context/summary.md") → 진행 상태 파악
397
+ 3. git log --oneline -10 → 최근 작업 확인
398
+ 4. 중단 지점부터 재개
399
+ ```
400
+
401
+ #### 4. 핸드오프 (Handoffs)
402
+
403
+ **정의:** 에이전트 간 명시적 정보 전달.
404
+
405
+ ```typescript
406
+ // Agent A → Agent B 핸드오프
407
+ const resultA = Task(subagent_type="explore", model="haiku",
408
+ prompt="인증 로직 위치 찾기")
409
+
410
+ // 결과 명시적 전달
411
+ Task(subagent_type="implementation-executor", model="sonnet",
412
+ prompt=`인증 로직 수정
413
+
414
+ 이전 에이전트 결과:
415
+ ${resultA}
416
+
417
+ 수정 내용: [...]`)
418
+ ```
419
+
420
+ </context_preservation>
421
+
422
+ ---
423
+
424
+ <error_handling>
425
+
426
+ ## 에러 처리 및 복구
427
+
428
+ ### 원칙
429
+
430
+ | 전략 | 설명 | 구현 |
431
+ |------|------|------|
432
+ | **Failure Isolation** | 실패 도메인 격리 | 에이전트별 독립 실행 |
433
+ | **Redundancy** | 중요 작업 중복 실행 | 동일 작업 여러 에이전트 |
434
+ | **Circuit Breaker** | 반복 실패 시 중단 | 3회 실패 시 에스컬레이션 |
435
+ | **Monitoring** | 상태 추적 | TaskList, 로그 파일 |
436
+ | **Graceful Degradation** | 부분 실패 허용 | 핵심 작업 우선 완료 |
437
+
438
+ ### 패턴 1: 실패 격리
439
+
440
+ ```typescript
441
+ // ✅ 에이전트별 격리
442
+ try {
443
+ Task(subagent_type="implementation-executor",
444
+ prompt="기능 A 구현")
445
+ } catch (error) {
446
+ // 기능 A 실패해도 B는 계속
447
+ }
448
+
449
+ Task(subagent_type="implementation-executor",
450
+ prompt="기능 B 구현")
451
+ ```
452
+
453
+ ### 패턴 2: 재시도 전략
454
+
455
+ ```typescript
456
+ // ❌ 무한 재시도
457
+ while (true) {
458
+ Task(...) // 위험
459
+ }
460
+
461
+ // ✅ 제한적 재시도
462
+ const maxRetries = 3
463
+ let attempt = 0
464
+
465
+ while (attempt < maxRetries) {
466
+ try {
467
+ Task(subagent_type="implementation-executor", ...)
468
+ break // 성공 시 탈출
469
+ } catch (error) {
470
+ attempt++
471
+ if (attempt >= maxRetries) {
472
+ // 에스컬레이션: 더 강력한 모델 사용
473
+ Task(subagent_type="planner", model="opus",
474
+ prompt="문제 분석 및 대안 제시")
475
+ }
476
+ }
477
+ }
478
+ ```
479
+
480
+ ### 패턴 3: 서킷 브레이커
481
+
482
+ ```typescript
483
+ // 에이전트 상태 추적
484
+ const agentFailures = new Map()
485
+
486
+ function executeWithCircuitBreaker(agentType, prompt) {
487
+ const failures = agentFailures.get(agentType) || 0
488
+
489
+ // 3회 이상 실패 시 차단
490
+ if (failures >= 3) {
491
+ console.log(`Circuit breaker: ${agentType} 차단됨`)
492
+ // 대안 에이전트 사용
493
+ return Task(subagent_type="alternative-agent", ...)
494
+ }
495
+
496
+ try {
497
+ const result = Task(subagent_type=agentType, prompt=prompt)
498
+ agentFailures.set(agentType, 0) // 성공 시 리셋
499
+ return result
500
+ } catch (error) {
501
+ agentFailures.set(agentType, failures + 1)
502
+ throw error
503
+ }
504
+ }
505
+ ```
506
+
507
+ ### 패턴 4: 모니터링 및 알림
508
+
509
+ ```typescript
510
+ // 작업 상태 추적
511
+ TaskList() // pending/in_progress 작업 확인
512
+
513
+ // 실패 기록
514
+ Write(".claude/logs/failures.md", `
515
+ ## Failure Log
516
+
517
+ - Time: ${timestamp}
518
+ - Agent: ${agentType}
519
+ - Task: ${taskDescription}
520
+ - Error: ${errorMessage}
521
+ - Retry: ${retryCount}
522
+ `)
523
+ ```
524
+
525
+ ### 패턴 5: 분산 복구
526
+
527
+ ```typescript
528
+ // 여러 에이전트로 중복 실행
529
+ Task(subagent_type="implementation-executor", model="sonnet",
530
+ prompt="인증 로직 구현 (방법 1)")
531
+ Task(subagent_type="implementation-executor", model="sonnet",
532
+ prompt="인증 로직 구현 (방법 2)")
533
+
534
+ // 먼저 완료되거나 더 나은 결과 선택
535
+ ```
536
+
537
+ </error_handling>
538
+
539
+ ---
540
+
541
+ <performance_optimization>
542
+
543
+ ## 성능 최적화
544
+
545
+ ### 최적화 체크리스트
546
+
547
+ - [ ] 독립 작업 → 병렬 실행
548
+ - [ ] 10개 이상 유사 작업 → 배치 처리
549
+ - [ ] 10분 이상 작업 → 백그라운드 실행
550
+ - [ ] 복잡도별 모델 선택 (haiku/sonnet/opus)
551
+ - [ ] 컨텍스트 크기 모니터링 → 컴팩션
552
+ - [ ] 실패 시 재시도 제한 (3회)
553
+ - [ ] 상태 문서화 (컨텍스트 복구)
554
+
555
+ ### 성능 지표
556
+
557
+ | 지표 | 목표 | 측정 방법 |
558
+ |------|------|----------|
559
+ | **대기 시간** | 순차 대비 80% 감소 | 시작~완료 시간 |
560
+ | **토큰 사용** | 70-90% 절감 (배치) | API 로그 |
561
+ | **병렬도** | 3-10개 동시 실행 | 활성 에이전트 수 |
562
+ | **성공률** | 95% 이상 | 완료/시도 비율 |
563
+
564
+ ### 안티패턴
565
+
566
+ | 안티패턴 | 문제 | 올바른 방법 |
567
+ |---------|------|------------|
568
+ | **순차 실행** | 불필요한 대기 | 병렬 실행 |
569
+ | **과도한 병렬** | 컨텍스트 혼란 | 3-10개 제한 |
570
+ | **모델 미스매치** | 비용 낭비 | 복잡도별 선택 |
571
+ | **컨텍스트 미보존** | 작업 손실 | 상태 문서화 |
572
+ | **무한 재시도** | 리소스 낭비 | 3회 제한 |
573
+
574
+ </performance_optimization>
575
+
576
+ ---
577
+
578
+ <best_practices>
579
+
580
+ ## 모범 사례
581
+
582
+ ### 실행 전 체크
583
+
584
+ ```text
585
+ 1. 작업 분석
586
+ - 독립적인가? → 병렬
587
+ - 의존적인가? → 순차
588
+ - 유사한가? → 배치
589
+
590
+ 2. 모델 선택
591
+ - 간단 → haiku
592
+ - 일반 → sonnet
593
+ - 복잡 → opus
594
+
595
+ 3. 컨텍스트 계획
596
+ - 공유 상태 필요? → 문서화
597
+ - 컨텍스트 한계? → 컴팩션
598
+
599
+ 4. 에러 처리
600
+ - 재시도 전략
601
+ - 대안 계획
602
+ - 모니터링
603
+ ```
604
+
605
+ ### 작업 분해 원칙
606
+
607
+ | 원칙 | 설명 | 예시 |
608
+ |------|------|------|
609
+ | **Single Responsibility** | 에이전트당 하나의 책임 | explore, implement, review 분리 |
610
+ | **Loose Coupling** | 에이전트 간 최소 의존성 | 공유 상태만 문서로 전달 |
611
+ | **High Cohesion** | 관련 작업 그룹화 | UI 관련 작업 → designer |
612
+
613
+ ### 효율적인 프롬프트
614
+
615
+ ```typescript
616
+ // ❌ 모호한 지시
617
+ Task(subagent_type="implementation-executor",
618
+ prompt="뭔가 구현해줘")
619
+
620
+ // ✅ 명확한 지시
621
+ Task(subagent_type="implementation-executor", model="sonnet",
622
+ prompt=`User API 엔드포인트 구현
623
+
624
+ 요구사항:
625
+ - GET /users: 사용자 목록
626
+ - POST /users: 사용자 생성
627
+ - 인증: JWT 미들웨어
628
+ - 검증: Zod 스키마
629
+
630
+ 기존 패턴:
631
+ @functions/auth.ts 참조
632
+
633
+ 예상 결과:
634
+ - functions/users.ts
635
+ - 테스트 포함`)
636
+ ```
637
+
638
+ </best_practices>
639
+
640
+ ---
641
+
642
+ <examples>
643
+
644
+ ## 실전 예제
645
+
646
+ ### 예제 1: 풀스택 기능 구현
647
+
648
+ ```typescript
649
+ // 목표: User Profile 기능 구현 (API + UI + 테스트)
650
+
651
+ // ✅ 병렬 실행
652
+ Task(subagent_type="implementation-executor", model="sonnet",
653
+ prompt=`User Profile API 구현
654
+
655
+ - GET /profile: 프로필 조회
656
+ - PUT /profile: 프로필 수정
657
+ - 인증 필수
658
+ - Prisma User 모델 사용`)
659
+
660
+ Task(subagent_type="designer", model="sonnet",
661
+ prompt=`User Profile UI 구현
662
+
663
+ - 프로필 조회 화면
664
+ - 수정 폼
665
+ - TanStack Query 사용
666
+ - Tailwind 스타일`)
667
+
668
+ Task(subagent_type="implementation-executor", model="sonnet",
669
+ prompt=`User Profile 통합 테스트 작성
670
+
671
+ - API 테스트
672
+ - UI 테스트
673
+ - E2E 시나리오`)
674
+ ```
675
+
676
+ **예상 시간:**
677
+ - 순차 실행: 180초 (60 + 60 + 60)
678
+ - 병렬 실행: 60초 (가장 긴 작업)
679
+ - 개선: 3배 향상
680
+
681
+ ---
682
+
683
+ ### 예제 2: 대규모 리팩토링
684
+
685
+ ```typescript
686
+ // 목표: 10개 파일 동일 패턴으로 리팩토링
687
+
688
+ // ❌ 순차 실행 (비효율)
689
+ Edit("file1.ts", ...)
690
+ Edit("file2.ts", ...)
691
+ // ... (10번 반복)
692
+
693
+ // ✅ 배치 처리 (효율)
694
+ Task(subagent_type="implementation-executor", model="sonnet",
695
+ prompt=`다음 파일들 리팩토링:
696
+
697
+ 파일 목록:
698
+ - file1.ts
699
+ - file2.ts
700
+ - file3.ts
701
+ - file4.ts
702
+ - file5.ts
703
+ - file6.ts
704
+ - file7.ts
705
+ - file8.ts
706
+ - file9.ts
707
+ - file10.ts
708
+
709
+ 공통 규칙:
710
+ 1. const 함수 → arrow function
711
+ 2. any → unknown
712
+ 3. 명시적 return type 추가
713
+
714
+ 패턴:
715
+ ❌ function fn() { ... }
716
+ ✅ const fn = (): ReturnType => { ... }`)
717
+ ```
718
+
719
+ **예상 효과:**
720
+ - 토큰 사용: 70-90% 절감
721
+ - 실행 시간: 단축
722
+ - 일관성: 향상
723
+
724
+ ---
725
+
726
+ ### 예제 3: 멀티 스테이지 파이프라인
727
+
728
+ ```typescript
729
+ // Phase 1: 탐색 (병렬)
730
+ Task(subagent_type="explore", model="haiku",
731
+ prompt="프로젝트 구조 분석")
732
+ Task(subagent_type="explore", model="haiku",
733
+ prompt="기존 인증 로직 위치")
734
+ Task(subagent_type="explore", model="haiku",
735
+ prompt="테스트 구조 파악")
736
+
737
+ // Phase 2: 구현 (병렬)
738
+ Task(subagent_type="implementation-executor", model="sonnet",
739
+ prompt="새 인증 로직 구현")
740
+ Task(subagent_type="implementation-executor", model="sonnet",
741
+ prompt="미들웨어 구현")
742
+ Task(subagent_type="implementation-executor", model="sonnet",
743
+ prompt="테스트 작성")
744
+
745
+ // Phase 3: 검증 (순차)
746
+ Task(subagent_type="deployment-validator", model="sonnet",
747
+ prompt="typecheck/lint/build 전체 검증")
748
+
749
+ // Phase 4: 리뷰 (병렬)
750
+ Task(subagent_type="code-reviewer", model="opus",
751
+ prompt="보안 검토")
752
+ Task(subagent_type="code-reviewer", model="opus",
753
+ prompt="성능 검토")
754
+ ```
755
+
756
+ **구조:**
757
+ 1. Phase 1, 2, 4: 병렬 실행 (독립 작업)
758
+ 2. Phase 3: 순차 실행 (의존성)
759
+ 3. 모델 최적화 (haiku → sonnet → opus)
760
+
761
+ ---
762
+
763
+ ### 예제 4: 에러 복구 시나리오
764
+
765
+ ```typescript
766
+ // 목표: 복잡한 기능 구현 (실패 가능성 높음)
767
+
768
+ const maxRetries = 3
769
+ let attempt = 0
770
+
771
+ while (attempt < maxRetries) {
772
+ try {
773
+ // 구현 시도
774
+ Task(subagent_type="implementation-executor", model="sonnet",
775
+ prompt="복잡한 인증 로직 구현")
776
+
777
+ // 검증
778
+ Task(subagent_type="deployment-validator", model="sonnet",
779
+ prompt="typecheck/lint/build 검증")
780
+
781
+ // 성공 시 탈출
782
+ break
783
+
784
+ } catch (error) {
785
+ attempt++
786
+
787
+ // 실패 기록
788
+ Write(".claude/logs/retry.md", `
789
+ ## Retry ${attempt}
790
+ - Error: ${error}
791
+ - Time: ${timestamp}
792
+ `)
793
+
794
+ if (attempt >= maxRetries) {
795
+ // 에스컬레이션: opus 모델 + 전문가
796
+ Task(subagent_type="planner", model="opus",
797
+ prompt=`구현 실패 분석
798
+
799
+ 시도 횟수: ${attempt}
800
+ 에러 로그: @.claude/logs/retry.md
801
+
802
+ 대안 제시:
803
+ 1. 다른 접근 방법
804
+ 2. 단계별 분해
805
+ 3. 예상 블로커`)
806
+ }
807
+ }
808
+ }
809
+ ```
810
+
811
+ </examples>
812
+
813
+ ---
814
+
815
+ <references>
816
+
817
+ ## 참고 자료
818
+
819
+ ### Anthropic
820
+
821
+ 1. [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) - 컨텍스트 엔지니어링 원칙
822
+ 2. [Multi-agent research system](https://www.anthropic.com/engineering/multi-agent-research-system) - 멀티 에이전트 시스템 사례
823
+ 3. [Batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing) - 배치 처리 API
824
+
825
+ ### 아키텍처 패턴
826
+
827
+ 4. [Multi-Agent Design Patterns (Azure)](https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns) - 에이전트 오케스트레이션 패턴
828
+ 5. [Multi-Agent Systems (Google ADK)](https://google.github.io/adk-docs/agents/multi-agents/) - 병렬 에이전트 구현
829
+ 6. [Multi-Agent Patterns (LangChain)](https://docs.langchain.com/oss/python/langchain/multi-agent) - 서브에이전트, 라우터 패턴
830
+ 7. [Agentic AI Patterns (AWS)](https://docs.aws.amazon.com/prescriptive-guidance/latest/agentic-ai-patterns/introduction.html) - 워크플로우 패턴
831
+
832
+ ### 성능 최적화
833
+
834
+ 8. [Batch Query Processing (arXiv)](https://arxiv.org/html/2509.02121v1) - 배치 최적화 연구
835
+ 9. [Parallel Processing with Claude](https://codesignal.com/learn/courses/exploring-workflows-with-claude-in-typescript/lessons/parallel-processing-with-claude) - 병렬 처리 실습
836
+ 10. [AI Agent Performance Optimization](https://www.talktoagent.com/blog/ways-to-optimize-ai-agent-performance) - 9가지 최적화 전략
837
+
838
+ ### 에러 처리
839
+
840
+ 11. [Multi-Agent AI Failure Recovery](https://galileo.ai/blog/multi-agent-ai-system-failure-recovery) - 실패 복구 전략
841
+ 12. [Exception Handling for AI Agents](https://datagrid.com/blog/exception-handling-frameworks-ai-agents) - 예외 처리 프레임워크
842
+ 13. [Multi-Agent Systems Fault Tolerance](https://milvus.io/ai-quick-reference/how-do-multiagent-systems-ensure-fault-tolerance) - 결함 허용
843
+
844
+ ### 고급 패턴
845
+
846
+ 14. [Fan-Out Fan-In Pattern](https://systemdesignschool.io/fundamentals/fan-out-fan-in) - 분산 처리 패턴
847
+ 15. [Context Preservation in Multi-Agent](https://developers.googleblog.com/architecting-efficient-context-aware-multi-agent-framework-for-production/) - 컨텍스트 보존 기법
848
+
849
+ </references>
850
+
851
+ ---
852
+
853
+ <summary>
854
+
855
+ ## 핵심 요약
856
+
857
+ | 개념 | 핵심 포인트 |
858
+ |------|----------|
859
+ | **병렬 실행** | 단일 메시지에서 여러 Tool 호출 → 5-15배 향상 |
860
+ | **배치 처리** | 유사 작업 묶음 → 토큰 70-90% 절감 |
861
+ | **모델 라우팅** | haiku (간단), sonnet (일반), opus (복잡) |
862
+ | **에이전트 위임** | 전문 에이전트 즉시 위임 → 품질 향상 |
863
+ | **컨텍스트 보존** | 상태 문서화 + 핸드오프 |
864
+ | **에러 처리** | 격리 + 재시도 (3회) + 서킷 브레이커 |
865
+ | **성능 목표** | 대기 시간 80% 감소, 병렬도 3-10개 |
866
+
867
+ **시작하기:**
868
+ 1. 작업 분석 → 독립/의존/유사 구분
869
+ 2. 패턴 선택 → 병렬/순차/배치
870
+ 3. 모델 선택 → 복잡도 기반
871
+ 4. 실행 → 단일 메시지 다중 Tool
872
+ 5. 모니터링 → TaskList, 로그
873
+
874
+ </summary>