claude-cli-advanced-starter-pack 1.0.16 → 1.8.0
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.
- package/OVERVIEW.md +5 -1
- package/README.md +241 -132
- package/bin/gtask.js +53 -0
- package/package.json +1 -1
- package/src/cli/menu.js +27 -0
- package/src/commands/explore-mcp/mcp-registry.js +99 -0
- package/src/commands/init.js +309 -80
- package/src/commands/install-panel-hook.js +108 -0
- package/src/commands/install-scripts.js +232 -0
- package/src/commands/install-skill.js +220 -0
- package/src/commands/panel.js +297 -0
- package/src/commands/setup-wizard.js +4 -3
- package/src/commands/test-setup.js +4 -5
- package/src/data/releases.json +209 -0
- package/src/panel/queue.js +188 -0
- package/templates/commands/ask-claude.template.md +118 -0
- package/templates/commands/ccasp-panel.template.md +72 -0
- package/templates/commands/ccasp-setup.template.md +470 -79
- package/templates/commands/create-smoke-test.template.md +186 -0
- package/templates/commands/project-impl.template.md +9 -113
- package/templates/commands/refactor-check.template.md +112 -0
- package/templates/commands/refactor-cleanup.template.md +144 -0
- package/templates/commands/refactor-prep.template.md +192 -0
- package/templates/docs/AI_ARCHITECTURE_CONSTITUTION.template.md +198 -0
- package/templates/docs/DETAILED_GOTCHAS.template.md +347 -0
- package/templates/docs/PHASE-DEV-CHECKLIST.template.md +241 -0
- package/templates/docs/PROGRESS_JSON_TEMPLATE.json +117 -0
- package/templates/docs/background-agent.template.md +264 -0
- package/templates/hooks/autonomous-decision-logger.template.js +207 -0
- package/templates/hooks/branch-merge-checker.template.js +272 -0
- package/templates/hooks/context-injector.template.js +261 -0
- package/templates/hooks/git-commit-tracker.template.js +267 -0
- package/templates/hooks/happy-mode-detector.template.js +214 -0
- package/templates/hooks/happy-title-generator.template.js +260 -0
- package/templates/hooks/issue-completion-detector.template.js +205 -0
- package/templates/hooks/panel-queue-reader.template.js +83 -0
- package/templates/hooks/phase-validation-gates.template.js +307 -0
- package/templates/hooks/session-id-generator.template.js +236 -0
- package/templates/hooks/token-budget-loader.template.js +234 -0
- package/templates/hooks/token-usage-monitor.template.js +193 -0
- package/templates/hooks/tool-output-cacher.template.js +219 -0
- package/templates/patterns/README.md +129 -0
- package/templates/patterns/l1-l2-orchestration.md +189 -0
- package/templates/patterns/multi-phase-orchestration.md +258 -0
- package/templates/patterns/two-tier-query-pipeline.md +192 -0
- package/templates/scripts/README.md +109 -0
- package/templates/scripts/analyze-delegation-log.js +299 -0
- package/templates/scripts/autonomous-decision-logger.js +277 -0
- package/templates/scripts/git-history-analyzer.py +269 -0
- package/templates/scripts/phase-validation-gates.js +307 -0
- package/templates/scripts/poll-deployment-status.js +260 -0
- package/templates/scripts/roadmap-scanner.js +263 -0
- package/templates/scripts/validate-deployment.js +293 -0
- package/templates/skills/agent-creator/skill.json +18 -0
- package/templates/skills/agent-creator/skill.md +335 -0
- package/templates/skills/hook-creator/skill.json +18 -0
- package/templates/skills/hook-creator/skill.md +318 -0
- package/templates/skills/panel/skill.json +18 -0
- package/templates/skills/panel/skill.md +90 -0
- package/templates/skills/rag-agent-creator/skill.json +18 -0
- package/templates/skills/rag-agent-creator/skill.md +307 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agent-creator
|
|
3
|
+
description: Create Claude Code CLI agents (subagents) following best practices - proper Task tool configuration, agent specialization, workflow integration, and RAG-enhanced knowledge bases
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Agent Creator Skill
|
|
7
|
+
|
|
8
|
+
Expert-level Claude Code agent creation following official Anthropic best practices.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
This skill is automatically invoked when:
|
|
13
|
+
|
|
14
|
+
- Creating new specialized agents/subagents
|
|
15
|
+
- Designing agent workflows
|
|
16
|
+
- Configuring agent tool access
|
|
17
|
+
- Setting up multi-agent coordination
|
|
18
|
+
|
|
19
|
+
## Agent Architecture Overview
|
|
20
|
+
|
|
21
|
+
### What are Claude Code Agents?
|
|
22
|
+
|
|
23
|
+
Agents (subagents) are specialized Claude instances launched via the `Task` tool to handle complex, multi-step tasks autonomously. They:
|
|
24
|
+
|
|
25
|
+
- Run in isolated contexts with specific tool access
|
|
26
|
+
- Execute tasks without interrupting main conversation
|
|
27
|
+
- Return results upon completion
|
|
28
|
+
- Can run in parallel for independent tasks
|
|
29
|
+
|
|
30
|
+
### Agent Types
|
|
31
|
+
|
|
32
|
+
| Agent Type | Description | Tools |
|
|
33
|
+
|------------|-------------|-------|
|
|
34
|
+
| `general-purpose` | Research, search, multi-step tasks | All tools |
|
|
35
|
+
| `Explore` | Fast codebase exploration | All except Edit, Write |
|
|
36
|
+
| `Plan` | Planning and discovery | All except Edit, Write |
|
|
37
|
+
| `Bash` | Command execution specialist | Bash only |
|
|
38
|
+
|
|
39
|
+
## Creating Custom Agents
|
|
40
|
+
|
|
41
|
+
### Skill-Based Agents
|
|
42
|
+
|
|
43
|
+
Agents defined as skills live in `.claude/skills/{skill-name}/`:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
.claude/skills/
|
|
47
|
+
my-agent/
|
|
48
|
+
skill.md # Main skill definition (YAML frontmatter)
|
|
49
|
+
context/ # Agent context files
|
|
50
|
+
README.md
|
|
51
|
+
patterns.md
|
|
52
|
+
examples.md
|
|
53
|
+
workflows/ # Sub-workflows
|
|
54
|
+
README.md
|
|
55
|
+
sub-task-1.md
|
|
56
|
+
sub-task-2.md
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### skill.md Format
|
|
60
|
+
|
|
61
|
+
```markdown
|
|
62
|
+
---
|
|
63
|
+
name: my-agent
|
|
64
|
+
description: Brief description shown in skill list
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
# Agent Title
|
|
68
|
+
|
|
69
|
+
Detailed agent instructions, patterns, and capabilities.
|
|
70
|
+
|
|
71
|
+
## When to Use This Agent
|
|
72
|
+
|
|
73
|
+
List specific scenarios when this agent should be invoked.
|
|
74
|
+
|
|
75
|
+
## Capabilities
|
|
76
|
+
|
|
77
|
+
- What this agent can do
|
|
78
|
+
- Tools it has access to
|
|
79
|
+
- Patterns it follows
|
|
80
|
+
|
|
81
|
+
## Workflow
|
|
82
|
+
|
|
83
|
+
Step-by-step process the agent follows.
|
|
84
|
+
|
|
85
|
+
## Output Format
|
|
86
|
+
|
|
87
|
+
What the agent returns upon completion.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Agent Design Patterns
|
|
91
|
+
|
|
92
|
+
### Pattern 1: Discovery Agent
|
|
93
|
+
|
|
94
|
+
Purpose: Research and understand before implementation.
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
---
|
|
98
|
+
name: discovery-agent
|
|
99
|
+
description: Research codebase, find patterns, gather requirements
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
# Discovery Agent
|
|
103
|
+
|
|
104
|
+
## Purpose
|
|
105
|
+
|
|
106
|
+
Explore the codebase to understand:
|
|
107
|
+
- Existing patterns and conventions
|
|
108
|
+
- File organization and structure
|
|
109
|
+
- Dependencies and relationships
|
|
110
|
+
- Potential impact areas
|
|
111
|
+
|
|
112
|
+
## Workflow
|
|
113
|
+
|
|
114
|
+
1. **Initial Search** - Use Glob/Grep to find relevant files
|
|
115
|
+
2. **Deep Read** - Read key files to understand patterns
|
|
116
|
+
3. **Map Dependencies** - Trace imports and relationships
|
|
117
|
+
4. **Document Findings** - Summarize discoveries
|
|
118
|
+
|
|
119
|
+
## Output
|
|
120
|
+
|
|
121
|
+
Return a structured report:
|
|
122
|
+
- Files discovered
|
|
123
|
+
- Patterns identified
|
|
124
|
+
- Key dependencies
|
|
125
|
+
- Recommendations
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Pattern 2: Implementation Agent
|
|
129
|
+
|
|
130
|
+
Purpose: Execute code changes with proper patterns.
|
|
131
|
+
|
|
132
|
+
```markdown
|
|
133
|
+
---
|
|
134
|
+
name: implementation-agent
|
|
135
|
+
description: Write code following project patterns and conventions
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
# Implementation Agent
|
|
139
|
+
|
|
140
|
+
## Purpose
|
|
141
|
+
|
|
142
|
+
Implement features following project standards:
|
|
143
|
+
- Use established patterns
|
|
144
|
+
- Maintain consistency
|
|
145
|
+
- Add appropriate tests
|
|
146
|
+
- Update documentation
|
|
147
|
+
|
|
148
|
+
## Prerequisites
|
|
149
|
+
|
|
150
|
+
- Discovery complete
|
|
151
|
+
- Plan approved
|
|
152
|
+
- Target files identified
|
|
153
|
+
|
|
154
|
+
## Workflow
|
|
155
|
+
|
|
156
|
+
1. **Read Target Files** - Understand current state
|
|
157
|
+
2. **Apply Patterns** - Use project conventions
|
|
158
|
+
3. **Implement Changes** - Write clean code
|
|
159
|
+
4. **Add Tests** - Cover new functionality
|
|
160
|
+
5. **Validate** - Ensure no regressions
|
|
161
|
+
|
|
162
|
+
## Output
|
|
163
|
+
|
|
164
|
+
Return implementation summary:
|
|
165
|
+
- Files modified
|
|
166
|
+
- Tests added
|
|
167
|
+
- Breaking changes (if any)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Pattern 3: QA Agent
|
|
171
|
+
|
|
172
|
+
Purpose: Validate changes and ensure quality.
|
|
173
|
+
|
|
174
|
+
```markdown
|
|
175
|
+
---
|
|
176
|
+
name: qa-agent
|
|
177
|
+
description: Validate changes, run tests, verify patterns
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
# QA Agent
|
|
181
|
+
|
|
182
|
+
## Purpose
|
|
183
|
+
|
|
184
|
+
Ensure quality through:
|
|
185
|
+
- Pattern compliance
|
|
186
|
+
- Test coverage
|
|
187
|
+
- Error handling
|
|
188
|
+
- Performance impact
|
|
189
|
+
|
|
190
|
+
## Workflow
|
|
191
|
+
|
|
192
|
+
1. **Review Changes** - Examine modified files
|
|
193
|
+
2. **Run Tests** - Execute relevant test suites
|
|
194
|
+
3. **Check Patterns** - Verify convention compliance
|
|
195
|
+
4. **Report Issues** - Document findings
|
|
196
|
+
|
|
197
|
+
## Output
|
|
198
|
+
|
|
199
|
+
Return QA report:
|
|
200
|
+
- Tests passed/failed
|
|
201
|
+
- Pattern violations
|
|
202
|
+
- Recommendations
|
|
203
|
+
- Sign-off status
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Pattern 4: Orchestrator Agent
|
|
207
|
+
|
|
208
|
+
Purpose: Coordinate multiple agents for complex tasks.
|
|
209
|
+
|
|
210
|
+
```markdown
|
|
211
|
+
---
|
|
212
|
+
name: orchestrator-agent
|
|
213
|
+
description: Coordinate multi-agent workflows for complex tasks
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
# Orchestrator Agent
|
|
217
|
+
|
|
218
|
+
## Purpose
|
|
219
|
+
|
|
220
|
+
Coordinate complex workflows:
|
|
221
|
+
- Decompose tasks
|
|
222
|
+
- Assign to specialized agents
|
|
223
|
+
- Aggregate results
|
|
224
|
+
- Handle dependencies
|
|
225
|
+
|
|
226
|
+
## Workflow
|
|
227
|
+
|
|
228
|
+
1. **Analyze Task** - Understand scope
|
|
229
|
+
2. **Create Plan** - Break into subtasks
|
|
230
|
+
3. **Dispatch Agents** - Launch specialized agents
|
|
231
|
+
4. **Monitor Progress** - Track completion
|
|
232
|
+
5. **Aggregate Results** - Combine outputs
|
|
233
|
+
|
|
234
|
+
## Agent Dispatch
|
|
235
|
+
|
|
236
|
+
Launch agents in parallel when independent:
|
|
237
|
+
- Discovery can run with initial planning
|
|
238
|
+
- Implementation waits for planning
|
|
239
|
+
- QA waits for implementation
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Task Tool Configuration
|
|
243
|
+
|
|
244
|
+
### Basic Agent Launch
|
|
245
|
+
|
|
246
|
+
To launch an agent, invoke the Task tool with these parameters:
|
|
247
|
+
|
|
248
|
+
```json
|
|
249
|
+
{
|
|
250
|
+
"description": "Research authentication patterns",
|
|
251
|
+
"prompt": "Search the codebase for authentication implementations...",
|
|
252
|
+
"subagent_type": "Explore"
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Agent Parameters
|
|
257
|
+
|
|
258
|
+
| Parameter | Required | Description |
|
|
259
|
+
|-----------|----------|-------------|
|
|
260
|
+
| `description` | Yes | Short (3-5 word) task description |
|
|
261
|
+
| `prompt` | Yes | Detailed task instructions |
|
|
262
|
+
| `subagent_type` | Yes | Agent type to use |
|
|
263
|
+
| `model` | No | Override model (sonnet, opus, haiku) |
|
|
264
|
+
| `resume` | No | Agent ID to resume from |
|
|
265
|
+
|
|
266
|
+
### Model Selection
|
|
267
|
+
|
|
268
|
+
| Model | Best For | Cost |
|
|
269
|
+
|-------|----------|------|
|
|
270
|
+
| `haiku` | Quick, straightforward tasks | Lowest |
|
|
271
|
+
| `sonnet` | Default, balanced | Medium |
|
|
272
|
+
| `opus` | Complex reasoning | Highest |
|
|
273
|
+
|
|
274
|
+
## Best Practices
|
|
275
|
+
|
|
276
|
+
### Agent Design
|
|
277
|
+
|
|
278
|
+
1. **Single Responsibility** - Each agent does one thing well
|
|
279
|
+
2. **Clear Boundaries** - Define what agent can/cannot do
|
|
280
|
+
3. **Explicit Output** - Specify return format
|
|
281
|
+
4. **Error Handling** - Define failure behavior
|
|
282
|
+
|
|
283
|
+
### Task Prompts
|
|
284
|
+
|
|
285
|
+
1. **Be Specific** - Include all necessary context
|
|
286
|
+
2. **Define Success** - What does "done" look like?
|
|
287
|
+
3. **Scope Limits** - What should agent NOT do?
|
|
288
|
+
4. **Output Format** - How to structure results?
|
|
289
|
+
|
|
290
|
+
### Parallel Execution
|
|
291
|
+
|
|
292
|
+
1. **Independence** - Only parallelize independent tasks
|
|
293
|
+
2. **Single Message** - Multiple Task calls in one message
|
|
294
|
+
3. **Dependencies** - Sequential tasks must wait
|
|
295
|
+
|
|
296
|
+
**Parallel Execution**: In a single message, invoke the Task tool multiple times.
|
|
297
|
+
|
|
298
|
+
**Sequential Execution**: For dependent tasks, wait for first agent to complete before invoking the next Task tool.
|
|
299
|
+
|
|
300
|
+
### Context Management
|
|
301
|
+
|
|
302
|
+
1. **Stateless** - Each agent invocation is fresh
|
|
303
|
+
2. **Self-Contained** - Include all needed context in prompt
|
|
304
|
+
3. **Explicit Return** - Specify what to report back
|
|
305
|
+
4. **No Follow-up** - Cannot send additional messages
|
|
306
|
+
|
|
307
|
+
## Creating a New Agent
|
|
308
|
+
|
|
309
|
+
### Step-by-Step Process
|
|
310
|
+
|
|
311
|
+
1. **Define Purpose** - What problem does this agent solve?
|
|
312
|
+
2. **Identify Tools** - What tools does it need?
|
|
313
|
+
3. **Design Workflow** - What steps does it follow?
|
|
314
|
+
4. **Specify Output** - What does it return?
|
|
315
|
+
5. **Create Skill** - Write skill.md with context
|
|
316
|
+
6. **Add RAG if Needed** - Include knowledge base for domain expertise
|
|
317
|
+
7. **Add to README** - Document in skills README
|
|
318
|
+
8. **Test Thoroughly** - Verify in real scenarios
|
|
319
|
+
|
|
320
|
+
### Checklist
|
|
321
|
+
|
|
322
|
+
- [ ] skill.md with YAML frontmatter
|
|
323
|
+
- [ ] Clear "When to Use" section
|
|
324
|
+
- [ ] Defined workflow steps
|
|
325
|
+
- [ ] Explicit output format
|
|
326
|
+
- [ ] Context files if needed
|
|
327
|
+
- [ ] Added to skills README
|
|
328
|
+
- [ ] Tested with sample tasks
|
|
329
|
+
|
|
330
|
+
## References
|
|
331
|
+
|
|
332
|
+
- Task Tool: System prompt documentation
|
|
333
|
+
- Skills: `.claude/skills/README.md`
|
|
334
|
+
- Agents: `.claude/agents/`
|
|
335
|
+
- Official Docs: https://docs.anthropic.com/en/docs/claude-code
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hook-creator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Create Claude Code CLI hooks following best practices",
|
|
5
|
+
"category": "development",
|
|
6
|
+
"portability": 100,
|
|
7
|
+
"features": [
|
|
8
|
+
"JSON schema configuration",
|
|
9
|
+
"Event type handling",
|
|
10
|
+
"Matcher patterns",
|
|
11
|
+
"Error handling templates"
|
|
12
|
+
],
|
|
13
|
+
"entryPoint": "skill.md",
|
|
14
|
+
"context": [],
|
|
15
|
+
"workflows": [],
|
|
16
|
+
"requiredTools": ["Read", "Write", "Edit"],
|
|
17
|
+
"suggestedModel": "sonnet"
|
|
18
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hook-creator
|
|
3
|
+
description: Create Claude Code CLI hooks following best practices - proper JSON schema, event types, matchers, error handling, and file organization
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Hook Creator Skill
|
|
7
|
+
|
|
8
|
+
Expert-level Claude Code hook creation following official Anthropic best practices.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
This skill is automatically invoked when:
|
|
13
|
+
|
|
14
|
+
- Creating new hooks for Claude Code CLI
|
|
15
|
+
- Modifying existing hook configurations
|
|
16
|
+
- Writing hook scripts (JS, Python, PowerShell)
|
|
17
|
+
- Configuring hook matchers and event types
|
|
18
|
+
|
|
19
|
+
## Hook Architecture Overview
|
|
20
|
+
|
|
21
|
+
### Configuration Files (Priority Order)
|
|
22
|
+
|
|
23
|
+
1. `~/.claude/settings.json` - Global user settings (all projects)
|
|
24
|
+
2. `.claude/settings.json` - Project settings (checked into git)
|
|
25
|
+
3. `.claude/settings.local.json` - Local overrides (gitignored)
|
|
26
|
+
|
|
27
|
+
### Hook Directory Structure
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
.claude/
|
|
31
|
+
settings.local.json # Hook configurations (JSON)
|
|
32
|
+
hooks/
|
|
33
|
+
README.md # Hook system documentation
|
|
34
|
+
lifecycle/ # SessionStart, SessionEnd, Stop hooks
|
|
35
|
+
README.md
|
|
36
|
+
session-start.js
|
|
37
|
+
tools/ # PreToolUse, PostToolUse hooks
|
|
38
|
+
README.md
|
|
39
|
+
validate-files.js
|
|
40
|
+
notifications/ # Notification hooks
|
|
41
|
+
README.md
|
|
42
|
+
alert-handler.js
|
|
43
|
+
security/ # Security-focused hooks
|
|
44
|
+
README.md
|
|
45
|
+
block-dangerous-ops.js
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Supported Hook Events
|
|
49
|
+
|
|
50
|
+
| Event | Trigger | Can Block | Primary Use Cases |
|
|
51
|
+
|-------|---------|-----------|-------------------|
|
|
52
|
+
| `SessionStart` | Session begins | No | Setup, notifications, load context |
|
|
53
|
+
| `SessionEnd` | Session ends | No | Cleanup, save state |
|
|
54
|
+
| `Stop` | Claude stops responding | No | Notifications, state saving |
|
|
55
|
+
| `PreToolUse` | Before tool executes | **Yes** | Security gates, input validation |
|
|
56
|
+
| `PostToolUse` | After tool completes | No | Logging, validation, sync |
|
|
57
|
+
| `Notification` | Attention needed | No | Custom alerts, sounds |
|
|
58
|
+
| `UserPromptSubmit` | Before prompt processes | **Yes** | Input validation |
|
|
59
|
+
| `SubagentStop` | Subagent completes | No | Aggregate results |
|
|
60
|
+
| `PreCompact` | Before transcript compaction | No | Archive, cleanup |
|
|
61
|
+
| `PermissionRequest` | Permission dialog shown | No | Custom handling |
|
|
62
|
+
|
|
63
|
+
## JSON Configuration Schema
|
|
64
|
+
|
|
65
|
+
### Basic Hook Configuration
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"hooks": {
|
|
70
|
+
"EventType": [
|
|
71
|
+
{
|
|
72
|
+
"matcher": "pattern",
|
|
73
|
+
"hooks": [
|
|
74
|
+
{
|
|
75
|
+
"type": "command",
|
|
76
|
+
"command": "your-command-here",
|
|
77
|
+
"timeout": 60
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Configuration Fields
|
|
87
|
+
|
|
88
|
+
| Field | Required | Type | Description |
|
|
89
|
+
|-------|----------|------|-------------|
|
|
90
|
+
| `matcher` | No | string (regex) | Filter which tools/events trigger hook |
|
|
91
|
+
| `hooks` | Yes | array | List of hook commands to execute |
|
|
92
|
+
| `type` | Yes | `"command"` or `"prompt"` | Hook execution type |
|
|
93
|
+
| `command` | For type:command | string | Shell command to execute |
|
|
94
|
+
| `timeout` | No | number | Seconds before timeout (default: 60) |
|
|
95
|
+
|
|
96
|
+
### Matcher Patterns
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
// Single tool
|
|
100
|
+
"matcher": "Write"
|
|
101
|
+
|
|
102
|
+
// Multiple tools (regex OR)
|
|
103
|
+
"matcher": "Write|Edit|MultiEdit"
|
|
104
|
+
|
|
105
|
+
// MCP namespace
|
|
106
|
+
"matcher": "mcp__browserbase__.*"
|
|
107
|
+
|
|
108
|
+
// Specific MCP tool
|
|
109
|
+
"matcher": "mcp__browserbase__browserbase_stagehand_act"
|
|
110
|
+
|
|
111
|
+
// No matcher = all tools
|
|
112
|
+
// Just omit the matcher field
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Hook Input/Output
|
|
116
|
+
|
|
117
|
+
### Environment Variables (Available to Hooks)
|
|
118
|
+
|
|
119
|
+
| Variable | Description |
|
|
120
|
+
|----------|-------------|
|
|
121
|
+
| `CLAUDE_HOOK_INPUT` | JSON string of tool input |
|
|
122
|
+
| `CLAUDE_TOOL_NAME` | Name of tool being called |
|
|
123
|
+
| `CLAUDE_SESSION_ID` | Unique session identifier |
|
|
124
|
+
| `CLAUDE_PROJECT_PATH` | Path to project root |
|
|
125
|
+
| `CLAUDE_PERMISSION_MODE` | Current permission mode |
|
|
126
|
+
|
|
127
|
+
### Hook Output Format
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"decision": "approve", // "approve", "block", or "ask"
|
|
132
|
+
"reason": "Optional explanation",
|
|
133
|
+
"systemMessage": "Warning to show user",
|
|
134
|
+
"updatedInput": {} // Modified tool input
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Exit Codes
|
|
139
|
+
|
|
140
|
+
| Code | Meaning | Behavior |
|
|
141
|
+
|------|---------|----------|
|
|
142
|
+
| 0 | Success | Allow action to proceed |
|
|
143
|
+
| 2 | Blocking error | Block action, show stderr to Claude |
|
|
144
|
+
| Other | Non-blocking error | Show stderr to user, allow action |
|
|
145
|
+
| Timeout | >60s (default) | Kill process, use default behavior |
|
|
146
|
+
|
|
147
|
+
## Hook Templates
|
|
148
|
+
|
|
149
|
+
### Template: JavaScript Tool Hook
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
#!/usr/bin/env node
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Hook Name: [Description]
|
|
156
|
+
* Event: PreToolUse | PostToolUse
|
|
157
|
+
* Trigger: When [condition]
|
|
158
|
+
* Purpose: [What this hook accomplishes]
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
const fs = require('fs');
|
|
162
|
+
const path = require('path');
|
|
163
|
+
|
|
164
|
+
// Parse hook input from environment
|
|
165
|
+
const hookInput = JSON.parse(process.env.CLAUDE_HOOK_INPUT || '{}');
|
|
166
|
+
const toolName = process.env.CLAUDE_TOOL_NAME || '';
|
|
167
|
+
const projectPath = process.env.CLAUDE_PROJECT_PATH || process.cwd();
|
|
168
|
+
|
|
169
|
+
async function main() {
|
|
170
|
+
try {
|
|
171
|
+
// Your validation/processing logic here
|
|
172
|
+
const shouldBlock = false; // Set based on your logic
|
|
173
|
+
|
|
174
|
+
if (shouldBlock) {
|
|
175
|
+
console.error('Blocked: [reason]');
|
|
176
|
+
process.exit(2); // Exit code 2 = blocking error
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Success - allow action
|
|
180
|
+
console.log(JSON.stringify({
|
|
181
|
+
decision: 'approve',
|
|
182
|
+
reason: 'Validation passed'
|
|
183
|
+
}));
|
|
184
|
+
process.exit(0);
|
|
185
|
+
|
|
186
|
+
} catch (error) {
|
|
187
|
+
// CRITICAL: Always default to allowing on error
|
|
188
|
+
console.error('Hook error:', error.message);
|
|
189
|
+
console.log(JSON.stringify({
|
|
190
|
+
decision: 'approve',
|
|
191
|
+
reason: `Error in hook: ${error.message}`
|
|
192
|
+
}));
|
|
193
|
+
process.exit(0);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
main();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Template: Python Security Hook
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
#!/usr/bin/env python3
|
|
204
|
+
"""
|
|
205
|
+
Hook Name: [Description]
|
|
206
|
+
Event: PreToolUse
|
|
207
|
+
Trigger: Write|Edit|Bash
|
|
208
|
+
Purpose: Block dangerous operations
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
import json
|
|
212
|
+
import os
|
|
213
|
+
import sys
|
|
214
|
+
|
|
215
|
+
# Parse hook input
|
|
216
|
+
try:
|
|
217
|
+
hook_input = json.loads(os.environ.get('CLAUDE_HOOK_INPUT', '{}'))
|
|
218
|
+
tool_name = os.environ.get('CLAUDE_TOOL_NAME', '')
|
|
219
|
+
project_path = os.environ.get('CLAUDE_PROJECT_PATH', os.getcwd())
|
|
220
|
+
except json.JSONDecodeError:
|
|
221
|
+
hook_input = {}
|
|
222
|
+
tool_name = ''
|
|
223
|
+
project_path = os.getcwd()
|
|
224
|
+
|
|
225
|
+
# Dangerous patterns to block
|
|
226
|
+
DANGEROUS_PATTERNS = [
|
|
227
|
+
'.env',
|
|
228
|
+
'secrets/',
|
|
229
|
+
'credentials',
|
|
230
|
+
'private_key',
|
|
231
|
+
]
|
|
232
|
+
|
|
233
|
+
def is_dangerous(file_path: str) -> bool:
|
|
234
|
+
"""Check if file path matches dangerous patterns."""
|
|
235
|
+
return any(pattern in file_path.lower() for pattern in DANGEROUS_PATTERNS)
|
|
236
|
+
|
|
237
|
+
def main():
|
|
238
|
+
try:
|
|
239
|
+
file_path = hook_input.get('file_path', '')
|
|
240
|
+
|
|
241
|
+
if is_dangerous(file_path):
|
|
242
|
+
sys.stderr.write(f"Blocked: Dangerous file pattern detected: {file_path}\n")
|
|
243
|
+
sys.exit(2) # Exit 2 = blocking error
|
|
244
|
+
|
|
245
|
+
print(json.dumps({
|
|
246
|
+
'decision': 'approve',
|
|
247
|
+
'reason': 'File path validated'
|
|
248
|
+
}))
|
|
249
|
+
sys.exit(0)
|
|
250
|
+
|
|
251
|
+
except Exception as e:
|
|
252
|
+
# CRITICAL: Default to allowing on error
|
|
253
|
+
sys.stderr.write(f"Hook error: {str(e)}\n")
|
|
254
|
+
print(json.dumps({
|
|
255
|
+
'decision': 'approve',
|
|
256
|
+
'reason': f'Error in hook: {str(e)}'
|
|
257
|
+
}))
|
|
258
|
+
sys.exit(0)
|
|
259
|
+
|
|
260
|
+
if __name__ == '__main__':
|
|
261
|
+
main()
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Best Practices
|
|
265
|
+
|
|
266
|
+
### Performance
|
|
267
|
+
|
|
268
|
+
1. **Keep hooks fast** - Target <5 seconds execution
|
|
269
|
+
2. **Use timeouts** - Set appropriate timeouts for longer operations
|
|
270
|
+
3. **Async when possible** - Background non-critical work
|
|
271
|
+
4. **Minimize I/O** - Cache frequently accessed data
|
|
272
|
+
|
|
273
|
+
### Security
|
|
274
|
+
|
|
275
|
+
1. **Quote variables** - Prevent command injection
|
|
276
|
+
2. **Validate inputs** - Never trust hook input blindly
|
|
277
|
+
3. **Scope credentials** - Hooks run with your full environment
|
|
278
|
+
4. **Block sensitive files** - Use PreToolUse to protect secrets
|
|
279
|
+
|
|
280
|
+
### Error Handling
|
|
281
|
+
|
|
282
|
+
1. **Always default to `approve`** - Don't block on hook errors
|
|
283
|
+
2. **Log errors** - Write to stderr for debugging
|
|
284
|
+
3. **Graceful degradation** - Hooks should fail safely
|
|
285
|
+
4. **Test locally** - Verify hooks before deploying
|
|
286
|
+
|
|
287
|
+
### Organization
|
|
288
|
+
|
|
289
|
+
1. **Use subdirectories** - Group hooks by purpose
|
|
290
|
+
2. **Document everything** - README.md in each directory
|
|
291
|
+
3. **Consistent naming** - `{purpose}-{action}-hook.{ext}`
|
|
292
|
+
4. **Version control** - Track hook changes in git
|
|
293
|
+
|
|
294
|
+
## Workflows
|
|
295
|
+
|
|
296
|
+
### Creating a New Hook
|
|
297
|
+
|
|
298
|
+
1. **Determine event type** - Which lifecycle event triggers your hook?
|
|
299
|
+
2. **Design matcher** - What tools/actions should trigger it?
|
|
300
|
+
3. **Choose language** - JS for complex logic, Python for security
|
|
301
|
+
4. **Write hook script** - Use templates above
|
|
302
|
+
5. **Configure in settings** - Add to `.claude/settings.local.json`
|
|
303
|
+
6. **Document** - Update README.md in appropriate directory
|
|
304
|
+
7. **Test locally** - Run hook manually before enabling
|
|
305
|
+
|
|
306
|
+
### Modifying Existing Hooks
|
|
307
|
+
|
|
308
|
+
1. **Review current config** - Check `.claude/settings.local.json`
|
|
309
|
+
2. **Understand impact** - What tools/events are affected?
|
|
310
|
+
3. **Make changes** - Update configuration or hook script
|
|
311
|
+
4. **Test thoroughly** - Verify both success and error paths
|
|
312
|
+
5. **Update documentation** - Keep README.md current
|
|
313
|
+
|
|
314
|
+
## References
|
|
315
|
+
|
|
316
|
+
- Official Docs: https://docs.anthropic.com/en/docs/claude-code/hooks
|
|
317
|
+
- Project Hooks: `.claude/hooks/README.md`
|
|
318
|
+
- Settings: `.claude/settings.local.json`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "panel",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Launch CCASP Control Panel in a new terminal window",
|
|
5
|
+
"category": "utility",
|
|
6
|
+
"portability": 100,
|
|
7
|
+
"features": [
|
|
8
|
+
"Launch control panel in separate terminal",
|
|
9
|
+
"Cross-platform support (Windows/macOS/Linux)",
|
|
10
|
+
"Queue-based command injection",
|
|
11
|
+
"Single-key command selection"
|
|
12
|
+
],
|
|
13
|
+
"entryPoint": "skill.md",
|
|
14
|
+
"context": [],
|
|
15
|
+
"workflows": [],
|
|
16
|
+
"requiredTools": ["Bash"],
|
|
17
|
+
"suggestedModel": "haiku"
|
|
18
|
+
}
|