start-vibing 3.0.7 → 3.0.9
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/README.md +64 -51
- package/package.json +1 -1
- package/template/.claude/CLAUDE.md +717 -229
- package/template/.claude/agents/claude-md-compactor.md +2 -14
- package/template/.claude/agents/documenter.md +0 -7
- package/template/.claude/agents/domain-updater.md +2 -7
- package/template/.claude/config/README.md +10 -8
- package/template/.claude/config/domain-mapping.json +1 -1
- package/template/.claude/settings.json +0 -129
- package/template/.claude/skills/api-docs/SKILL.md +206 -0
- package/template/.claude/skills/claude-seo/SKILL.md +84 -0
- package/template/.claude/skills/codebase-knowledge/domains/claude-system.md +51 -416
- package/template/.claude/skills/codebase-knowledge/domains/mcp-integration.md +37 -204
- package/template/.claude/skills/mongoose-patterns/SKILL.md +141 -452
- package/template/.claude/skills/playwright-testing/SKILL.md +251 -0
- package/template/.claude/skills/skill-creator/SKILL.md +106 -0
- package/template/.claude/skills/test-infrastructure/SKILL.md +242 -0
- package/template/CLAUDE.md +65 -701
- package/template/.claude/agents/_archive/01-orchestration/agent-selector.md +0 -130
- package/template/.claude/agents/_archive/01-orchestration/checkpoint-manager.md +0 -142
- package/template/.claude/agents/_archive/01-orchestration/context-manager.md +0 -138
- package/template/.claude/agents/_archive/01-orchestration/error-recovery.md +0 -182
- package/template/.claude/agents/_archive/01-orchestration/orchestrator.md +0 -114
- package/template/.claude/agents/_archive/01-orchestration/parallel-coordinator.md +0 -141
- package/template/.claude/agents/_archive/01-orchestration/task-decomposer.md +0 -121
- package/template/.claude/agents/_archive/01-orchestration/workflow-router.md +0 -119
- package/template/.claude/agents/_archive/02-typescript/bun-runtime-expert.md +0 -197
- package/template/.claude/agents/_archive/02-typescript/esm-resolver.md +0 -193
- package/template/.claude/agents/_archive/02-typescript/import-alias-enforcer.md +0 -158
- package/template/.claude/agents/_archive/02-typescript/ts-generics-helper.md +0 -183
- package/template/.claude/agents/_archive/02-typescript/ts-migration-helper.md +0 -238
- package/template/.claude/agents/_archive/02-typescript/ts-strict-checker.md +0 -180
- package/template/.claude/agents/_archive/02-typescript/ts-types-analyzer.md +0 -199
- package/template/.claude/agents/_archive/02-typescript/type-definition-writer.md +0 -187
- package/template/.claude/agents/_archive/02-typescript/zod-schema-designer.md +0 -212
- package/template/.claude/agents/_archive/02-typescript/zod-validator.md +0 -158
- package/template/.claude/agents/_archive/03-testing/playwright-assertions.md +0 -265
- package/template/.claude/agents/_archive/03-testing/playwright-e2e.md +0 -247
- package/template/.claude/agents/_archive/03-testing/playwright-fixtures.md +0 -234
- package/template/.claude/agents/_archive/03-testing/playwright-multi-viewport.md +0 -256
- package/template/.claude/agents/_archive/03-testing/playwright-page-objects.md +0 -247
- package/template/.claude/agents/_archive/03-testing/test-cleanup-manager.md +0 -248
- package/template/.claude/agents/_archive/03-testing/test-data-generator.md +0 -254
- package/template/.claude/agents/_archive/03-testing/tester-integration.md +0 -278
- package/template/.claude/agents/_archive/03-testing/tester-unit.md +0 -207
- package/template/.claude/agents/_archive/03-testing/vitest-config.md +0 -287
- package/template/.claude/agents/_archive/04-docker/container-health.md +0 -255
- package/template/.claude/agents/_archive/04-docker/deployment-validator.md +0 -225
- package/template/.claude/agents/_archive/04-docker/docker-compose-designer.md +0 -281
- package/template/.claude/agents/_archive/04-docker/docker-env-manager.md +0 -235
- package/template/.claude/agents/_archive/04-docker/docker-multi-stage.md +0 -241
- package/template/.claude/agents/_archive/04-docker/dockerfile-optimizer.md +0 -208
- package/template/.claude/agents/_archive/05-database/database-seeder.md +0 -273
- package/template/.claude/agents/_archive/05-database/mongodb-query-optimizer.md +0 -230
- package/template/.claude/agents/_archive/05-database/mongoose-aggregation.md +0 -306
- package/template/.claude/agents/_archive/05-database/mongoose-index-optimizer.md +0 -182
- package/template/.claude/agents/_archive/05-database/mongoose-schema-designer.md +0 -267
- package/template/.claude/agents/_archive/06-security/auth-session-validator.md +0 -68
- package/template/.claude/agents/_archive/06-security/input-sanitizer.md +0 -80
- package/template/.claude/agents/_archive/06-security/owasp-checker.md +0 -97
- package/template/.claude/agents/_archive/06-security/permission-auditor.md +0 -100
- package/template/.claude/agents/_archive/06-security/security-auditor.md +0 -84
- package/template/.claude/agents/_archive/06-security/sensitive-data-scanner.md +0 -83
- package/template/.claude/agents/_archive/07-documentation/api-documenter.md +0 -136
- package/template/.claude/agents/_archive/07-documentation/changelog-manager.md +0 -105
- package/template/.claude/agents/_archive/07-documentation/claude-md-compactor.md +0 -214
- package/template/.claude/agents/_archive/07-documentation/documenter.md +0 -184
- package/template/.claude/agents/_archive/07-documentation/domain-updater.md +0 -138
- package/template/.claude/agents/_archive/07-documentation/jsdoc-generator.md +0 -114
- package/template/.claude/agents/_archive/07-documentation/readme-generator.md +0 -135
- package/template/.claude/agents/_archive/08-git/branch-manager.md +0 -58
- package/template/.claude/agents/_archive/08-git/commit-manager.md +0 -78
- package/template/.claude/agents/_archive/09-quality/code-reviewer.md +0 -71
- package/template/.claude/agents/_archive/09-quality/quality-checker.md +0 -67
- package/template/.claude/agents/_archive/10-research/best-practices-finder.md +0 -89
- package/template/.claude/agents/_archive/10-research/competitor-analyzer.md +0 -106
- package/template/.claude/agents/_archive/10-research/pattern-researcher.md +0 -93
- package/template/.claude/agents/_archive/10-research/research-cache-manager.md +0 -76
- package/template/.claude/agents/_archive/10-research/research-web.md +0 -98
- package/template/.claude/agents/_archive/10-research/tech-evaluator.md +0 -101
- package/template/.claude/agents/_archive/11-ui-ux/accessibility-auditor.md +0 -136
- package/template/.claude/agents/_archive/11-ui-ux/design-system-enforcer.md +0 -125
- package/template/.claude/agents/_archive/11-ui-ux/skeleton-generator.md +0 -118
- package/template/.claude/agents/_archive/11-ui-ux/ui-desktop.md +0 -132
- package/template/.claude/agents/_archive/11-ui-ux/ui-mobile.md +0 -125
- package/template/.claude/agents/_archive/11-ui-ux/ui-tablet.md +0 -110
- package/template/.claude/agents/_archive/12-performance/api-latency-analyzer.md +0 -156
- package/template/.claude/agents/_archive/12-performance/bundle-analyzer.md +0 -113
- package/template/.claude/agents/_archive/12-performance/memory-leak-detector.md +0 -137
- package/template/.claude/agents/_archive/12-performance/performance-profiler.md +0 -115
- package/template/.claude/agents/_archive/12-performance/query-optimizer.md +0 -124
- package/template/.claude/agents/_archive/12-performance/render-optimizer.md +0 -154
- package/template/.claude/agents/_archive/13-debugging/build-error-fixer.md +0 -207
- package/template/.claude/agents/_archive/13-debugging/debugger.md +0 -149
- package/template/.claude/agents/_archive/13-debugging/error-stack-analyzer.md +0 -141
- package/template/.claude/agents/_archive/13-debugging/network-debugger.md +0 -208
- package/template/.claude/agents/_archive/13-debugging/runtime-error-fixer.md +0 -181
- package/template/.claude/agents/_archive/13-debugging/type-error-resolver.md +0 -185
- package/template/.claude/agents/_archive/14-validation/final-validator.md +0 -93
- package/template/.claude/agents/_archive/_backup/analyzer.md +0 -134
- package/template/.claude/agents/_archive/_backup/code-reviewer.md +0 -279
- package/template/.claude/agents/_archive/_backup/commit-manager.md +0 -219
- package/template/.claude/agents/_archive/_backup/debugger.md +0 -280
- package/template/.claude/agents/_archive/_backup/documenter.md +0 -237
- package/template/.claude/agents/_archive/_backup/domain-updater.md +0 -197
- package/template/.claude/agents/_archive/_backup/final-validator.md +0 -169
- package/template/.claude/agents/_archive/_backup/orchestrator.md +0 -149
- package/template/.claude/agents/_archive/_backup/performance.md +0 -232
- package/template/.claude/agents/_archive/_backup/quality-checker.md +0 -240
- package/template/.claude/agents/_archive/_backup/research.md +0 -315
- package/template/.claude/agents/_archive/_backup/security-auditor.md +0 -192
- package/template/.claude/agents/_archive/_backup/tester.md +0 -566
- package/template/.claude/agents/_archive/_backup/ui-ux-reviewer.md +0 -247
- package/template/.claude/commands/feature.md +0 -48
- package/template/.claude/commands/fix.md +0 -80
- package/template/.claude/commands/research.md +0 -107
- package/template/.claude/commands/validate.md +0 -72
- package/template/.claude/config/mcp-config.json +0 -344
- package/template/.claude/hooks/SETUP.md +0 -126
- package/template/.claude/hooks/run-hook.cmd +0 -46
- package/template/.claude/hooks/run-hook.sh +0 -43
- package/template/.claude/hooks/run-hook.ts +0 -230
- package/template/.claude/hooks/security-check.js +0 -202
- package/template/.claude/hooks/stop-validator.ts +0 -1667
- package/template/.claude/hooks/user-prompt-submit.ts +0 -104
- package/template/.claude/scripts/mcp-quick-install.ts +0 -151
- package/template/.claude/scripts/setup-mcps.ts +0 -651
- package/template/.claude/skills/hook-development/SKILL.md +0 -343
- package/template/.claude/skills/playwright-automation/SKILL.md +0 -438
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: hook-development
|
|
3
|
-
description: "ALWAYS invoke when creating or modifying Claude Code hooks — stop, prompt-submit, pre-tool-use events. Do NOT write hooks without checking patterns and event types first."
|
|
4
|
-
allowed-tools: Read, Write, Edit, Bash, Grep, Glob
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Hook Development for Claude Code
|
|
8
|
-
|
|
9
|
-
> Event-driven automation scripts for Claude Code. Hooks execute in response to system events, enabling validation, policy enforcement, context loading, and workflow integration.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Hook Types
|
|
14
|
-
|
|
15
|
-
### Prompt-Based Hooks (Recommended)
|
|
16
|
-
|
|
17
|
-
Use LLM-driven decision making for context-aware validation. Natural language reasoning for complex decisions.
|
|
18
|
-
|
|
19
|
-
**Supported Events:** Stop, SubagentStop, UserPromptSubmit, PreToolUse
|
|
20
|
-
|
|
21
|
-
### Command Hooks
|
|
22
|
-
|
|
23
|
-
Execute bash/shell scripts for deterministic operations. Fast, predictable, no LLM calls.
|
|
24
|
-
|
|
25
|
-
**Best For:** File system operations, external tool integration, quick validations
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Hook Events
|
|
30
|
-
|
|
31
|
-
| Event | Purpose | Use Case |
|
|
32
|
-
|-------|---------|----------|
|
|
33
|
-
| **PreToolUse** | Validate/modify tool calls before execution | Block dangerous operations, inject context |
|
|
34
|
-
| **PostToolUse** | React to tool completion | Log results, trigger follow-up actions |
|
|
35
|
-
| **Stop** | Validate task completeness before agent halts | Enforce branch rules, documentation checks |
|
|
36
|
-
| **SubagentStop** | Validate subagent completion | Quality gates for agent outputs |
|
|
37
|
-
| **UserPromptSubmit** | Process incoming prompts | Add context, block invalid requests |
|
|
38
|
-
| **SessionStart** | Initialize session | Load project context, set environment |
|
|
39
|
-
| **SessionEnd** | Cleanup on session close | Save state, cleanup temp files |
|
|
40
|
-
| **PreCompact** | Before context compaction | Preserve critical information |
|
|
41
|
-
| **Notification** | React to Claude notifications | Custom notification handling |
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Configuration
|
|
46
|
-
|
|
47
|
-
### Plugin Format (hooks/hooks.json)
|
|
48
|
-
|
|
49
|
-
```json
|
|
50
|
-
{
|
|
51
|
-
"description": "Optional explanation",
|
|
52
|
-
"hooks": {
|
|
53
|
-
"PreToolUse": [...],
|
|
54
|
-
"Stop": [...]
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Settings Format (.claude/settings.json)
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"hooks": {
|
|
64
|
-
"Stop": [
|
|
65
|
-
{
|
|
66
|
-
"hooks": [
|
|
67
|
-
{
|
|
68
|
-
"type": "command",
|
|
69
|
-
"command": "npx tsx .claude/hooks/stop-validator.ts",
|
|
70
|
-
"timeout": 30
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Input/Output
|
|
82
|
-
|
|
83
|
-
### Standard Input (JSON via stdin)
|
|
84
|
-
|
|
85
|
-
All hooks receive:
|
|
86
|
-
|
|
87
|
-
```json
|
|
88
|
-
{
|
|
89
|
-
"session_id": "string",
|
|
90
|
-
"transcript_path": "string",
|
|
91
|
-
"cwd": "string",
|
|
92
|
-
"permission_mode": "string",
|
|
93
|
-
"hook_event_name": "string"
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Event-specific fields:
|
|
98
|
-
- **PreToolUse/PostToolUse**: `tool_name`, `tool_input`
|
|
99
|
-
- **UserPromptSubmit**: `user_prompt`
|
|
100
|
-
- **Stop**: Current state info
|
|
101
|
-
|
|
102
|
-
### Standard Output
|
|
103
|
-
|
|
104
|
-
```json
|
|
105
|
-
{
|
|
106
|
-
"continue": true,
|
|
107
|
-
"suppressOutput": false,
|
|
108
|
-
"systemMessage": "Optional context for Claude"
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Exit Codes
|
|
113
|
-
|
|
114
|
-
| Code | Meaning | Behavior |
|
|
115
|
-
|------|---------|----------|
|
|
116
|
-
| 0 | Success | JSON stdout is processed (decision, reason, continue fields) |
|
|
117
|
-
| 2 | Blocking error | JSON stdout is IGNORED, only stderr shown to Claude |
|
|
118
|
-
| Other | Non-blocking error | Hook failed, but doesn't block |
|
|
119
|
-
|
|
120
|
-
**IMPORTANT for Stop Hooks:** To make Claude CONTINUE working after a block, use exit(0) with `decision: "block"` in JSON. Exit code 2 ignores JSON, so Claude just stops instead of fixing issues.
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Environment Variables
|
|
125
|
-
|
|
126
|
-
Available in all command hooks:
|
|
127
|
-
|
|
128
|
-
| Variable | Description |
|
|
129
|
-
|----------|-------------|
|
|
130
|
-
| `$CLAUDE_PROJECT_DIR` | Project root directory |
|
|
131
|
-
| `$CLAUDE_PLUGIN_ROOT` | Plugin directory (for portability) |
|
|
132
|
-
| `$CLAUDE_ENV_FILE` | SessionStart persistence file |
|
|
133
|
-
| `$CLAUDE_CODE_REMOTE` | Remote execution flag |
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## Matcher Patterns
|
|
138
|
-
|
|
139
|
-
Matchers determine which tools trigger hooks:
|
|
140
|
-
|
|
141
|
-
| Pattern | Example | Matches |
|
|
142
|
-
|---------|---------|---------|
|
|
143
|
-
| Exact | `"Write"` | Only Write tool |
|
|
144
|
-
| Multiple | `"Read\|Write\|Edit"` | Any of these tools |
|
|
145
|
-
| Wildcard | `"*"` | All tools |
|
|
146
|
-
| Regex | `"mcp__.*__delete.*"` | MCP delete operations |
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
## Best Practices
|
|
151
|
-
|
|
152
|
-
### Security
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
// Always validate paths
|
|
156
|
-
if (filePath.includes('..') || filePath.startsWith('/etc')) {
|
|
157
|
-
throw new Error('Path traversal blocked');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Always quote variables in bash
|
|
161
|
-
const cmd = `cat "${filePath}"`; // Correct
|
|
162
|
-
const cmd = `cat ${filePath}`; // WRONG - injection risk
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Performance
|
|
166
|
-
|
|
167
|
-
- All matching hooks execute **in parallel**
|
|
168
|
-
- Use command hooks for quick, deterministic checks
|
|
169
|
-
- Use prompt hooks for complex reasoning
|
|
170
|
-
- Default timeout: 60s (command), 30s (prompt)
|
|
171
|
-
|
|
172
|
-
### Error Handling
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
// For Stop hooks - use JSON with decision: "block" + exit(0)
|
|
176
|
-
// This makes Claude CONTINUE working to fix the issues
|
|
177
|
-
if (validationFailed) {
|
|
178
|
-
console.log(JSON.stringify({ decision: 'block', reason: errorMessage }));
|
|
179
|
-
process.exit(0); // Must be 0 for JSON to be processed!
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// For PreToolUse hooks - exit(2) blocks the specific tool operation
|
|
183
|
-
if (dangerousOperation) {
|
|
184
|
-
process.stderr.write('BLOCKED: Dangerous operation');
|
|
185
|
-
process.exit(2); // Blocks this tool call only
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// For non-blocking warnings
|
|
189
|
-
if (warningCondition) {
|
|
190
|
-
console.error('Warning:', message);
|
|
191
|
-
process.exit(1); // Logs but doesn't block
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
## Stop Hook Template
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
#!/usr/bin/env node
|
|
201
|
-
import { execSync } from 'child_process';
|
|
202
|
-
|
|
203
|
-
interface HookResult {
|
|
204
|
-
decision: 'approve' | 'block';
|
|
205
|
-
reason: string;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async function main(): Promise<void> {
|
|
209
|
-
// Read stdin
|
|
210
|
-
const stdin = await readStdin();
|
|
211
|
-
const input = JSON.parse(stdin);
|
|
212
|
-
|
|
213
|
-
// Validation logic
|
|
214
|
-
const error = validateSomething();
|
|
215
|
-
|
|
216
|
-
if (error) {
|
|
217
|
-
// Block and make Claude CONTINUE working to fix the issue
|
|
218
|
-
// IMPORTANT: Use exit(0) so JSON is processed. exit(2) ignores JSON!
|
|
219
|
-
const result: HookResult = {
|
|
220
|
-
decision: 'block',
|
|
221
|
-
reason: `
|
|
222
|
-
ERROR: ${error.type}
|
|
223
|
-
|
|
224
|
-
${error.message}
|
|
225
|
-
|
|
226
|
-
REQUIRED ACTION:
|
|
227
|
-
Task(subagent_type="${error.agent}", prompt="${error.prompt}")
|
|
228
|
-
`
|
|
229
|
-
};
|
|
230
|
-
console.log(JSON.stringify(result));
|
|
231
|
-
process.exit(0); // Must be 0 for JSON to be processed!
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Success - allow task completion
|
|
235
|
-
const result: HookResult = { decision: 'approve', reason: 'All checks passed' };
|
|
236
|
-
console.log(JSON.stringify(result));
|
|
237
|
-
process.exit(0);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
main();
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
---
|
|
244
|
-
|
|
245
|
-
## PreToolUse Hook Template
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
#!/usr/bin/env node
|
|
249
|
-
interface PreToolUseInput {
|
|
250
|
-
tool_name: string;
|
|
251
|
-
tool_input: Record<string, unknown>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
async function main(): Promise<void> {
|
|
255
|
-
const input: PreToolUseInput = JSON.parse(await readStdin());
|
|
256
|
-
|
|
257
|
-
// Check if this is a dangerous operation
|
|
258
|
-
if (input.tool_name === 'Write' && input.tool_input.file_path?.includes('.env')) {
|
|
259
|
-
process.stderr.write('BLOCKED: Cannot write to .env files');
|
|
260
|
-
process.exit(2);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Allow operation
|
|
264
|
-
console.log(JSON.stringify({ continue: true }));
|
|
265
|
-
process.exit(0);
|
|
266
|
-
}
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
## Debugging
|
|
272
|
-
|
|
273
|
-
**Important:** Hooks load at session startup. Config changes require restarting Claude Code.
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
# Debug hook execution
|
|
277
|
-
claude --debug
|
|
278
|
-
|
|
279
|
-
# View hook registration
|
|
280
|
-
claude --debug 2>&1 | grep -i hook
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## Implementation Checklist
|
|
286
|
-
|
|
287
|
-
1. [ ] Identify target events (Stop, PreToolUse, etc.)
|
|
288
|
-
2. [ ] Choose hook type (prompt-based vs command)
|
|
289
|
-
3. [ ] Write configuration in settings.json
|
|
290
|
-
4. [ ] Create hook script with proper exit codes
|
|
291
|
-
5. [ ] Test with `claude --debug`
|
|
292
|
-
6. [ ] Document in project README
|
|
293
|
-
|
|
294
|
-
---
|
|
295
|
-
|
|
296
|
-
## Common Patterns
|
|
297
|
-
|
|
298
|
-
### Validation Gate (Stop Hook)
|
|
299
|
-
|
|
300
|
-
Check conditions before task completion:
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
const validations = [
|
|
304
|
-
checkBranch(), // Must be on main
|
|
305
|
-
checkGitClean(), // No uncommitted changes
|
|
306
|
-
checkDocumentation() // All files documented
|
|
307
|
-
];
|
|
308
|
-
|
|
309
|
-
const firstError = validations.find(v => v !== null);
|
|
310
|
-
if (firstError) {
|
|
311
|
-
// Use JSON with decision: "block" + exit(0) so Claude CONTINUES fixing
|
|
312
|
-
console.log(JSON.stringify({
|
|
313
|
-
decision: 'block',
|
|
314
|
-
reason: formatError(firstError)
|
|
315
|
-
}));
|
|
316
|
-
process.exit(0); // NOT exit(2) - that ignores JSON!
|
|
317
|
-
}
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
### Context Injection (UserPromptSubmit)
|
|
321
|
-
|
|
322
|
-
Add context to user prompts:
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
const context = loadProjectContext();
|
|
326
|
-
const result = {
|
|
327
|
-
continue: true,
|
|
328
|
-
systemMessage: `Project context: ${context}`
|
|
329
|
-
};
|
|
330
|
-
console.log(JSON.stringify(result));
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Tool Blocking (PreToolUse)
|
|
334
|
-
|
|
335
|
-
Block dangerous operations:
|
|
336
|
-
|
|
337
|
-
```typescript
|
|
338
|
-
const BLOCKED_PATHS = ['.env', 'credentials', 'secrets'];
|
|
339
|
-
if (BLOCKED_PATHS.some(p => input.tool_input.path?.includes(p))) {
|
|
340
|
-
process.stderr.write('Blocked: Cannot access sensitive files');
|
|
341
|
-
process.exit(2);
|
|
342
|
-
}
|
|
343
|
-
```
|