@localtech/claude-code-toolkit 1.0.2 → 1.0.4

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.
@@ -0,0 +1,72 @@
1
+ # Common Patterns and Solutions
2
+
3
+ ## Error Handling Pattern
4
+ ```
5
+ try {
6
+ // Operation that might fail
7
+ const result = await riskyOperation();
8
+ return result;
9
+ } catch (error) {
10
+ // Log error with context
11
+ console.error(`Operation failed: ${error.message}`, { context: additionalData });
12
+ // Return safe default or re-throw
13
+ throw new Error(`Operation failed: ${error.message}`);
14
+ }
15
+ ```
16
+
17
+ ## API Response Pattern
18
+ ```
19
+ interface ApiResponse<T> {
20
+ success: boolean;
21
+ data?: T;
22
+ error?: string;
23
+ timestamp: string;
24
+ }
25
+
26
+ function createResponse<T>(data: T): ApiResponse<T> {
27
+ return {
28
+ success: true,
29
+ data,
30
+ timestamp: new Date().toISOString()
31
+ };
32
+ }
33
+ ```
34
+
35
+ ## Component Structure Pattern
36
+ ```
37
+ interface ComponentProps {
38
+ // Define props interface
39
+ }
40
+
41
+ export function ComponentName({ prop1, prop2 }: ComponentProps) {
42
+ // Early returns for edge cases
43
+ if (!prop1) return null;
44
+
45
+ // Main component logic
46
+ return (
47
+ <div>
48
+ {/* Component JSX */}
49
+ </div>
50
+ );
51
+ }
52
+ ```
53
+
54
+ ## Testing Pattern
55
+ ```
56
+ describe('ComponentName', () => {
57
+ it('should render correctly with valid props', () => {
58
+ // Arrange
59
+ const props = { /* test props */ };
60
+
61
+ // Act
62
+ render(<ComponentName {...props} />);
63
+
64
+ // Assert
65
+ expect(screen.getByText('expected text')).toBeInTheDocument();
66
+ });
67
+
68
+ it('should handle error states gracefully', () => {
69
+ // Test error scenarios
70
+ });
71
+ });
72
+ ```
@@ -0,0 +1,23 @@
1
+ # User Preferences and Working Styles
2
+
3
+ ## Development Environment
4
+ **IDE**: Cursor IDE with Claude Code extension
5
+ **Theme**: Dark mode preferred
6
+ **Font**: Monospace, 14pt for code readability
7
+
8
+ ## Code Style Preferences
9
+ **Language**: TypeScript preferred over JavaScript for new projects
10
+ **Architecture**: Functional programming principles where appropriate
11
+ **Naming**: camelCase for variables/functions, PascalCase for classes/types
12
+ **Documentation**: JSDoc/TSDoc for public APIs, inline comments for complex logic
13
+
14
+ ## Communication Style
15
+ **Feedback**: Prefer specific, actionable feedback with examples
16
+ **Documentation**: Professional yet approachable tone
17
+ **Decision Making**: Prefer data-driven decisions with clear rationale
18
+
19
+ ## Tool Preferences
20
+ **Version Control**: Git with conventional commits
21
+ **Testing**: Jest/Vitest with >80% coverage target
22
+ **Linting**: ESLint with TypeScript rules
23
+ **Package Management**: Prefer npm for stability, yarn/pnpm for performance
@@ -0,0 +1,358 @@
1
+ # Claude Code Skill: Claude Code Hooks Master
2
+
3
+ ## Metadata
4
+ name: claude-code-hooks-master
5
+ description: Master the power of Claude Code hooks for automated development workflows, continuous integration, and seamless productivity enhancement
6
+ author: Carlos Fadhel
7
+ version: 1.0.0
8
+ tags: automation, hooks, workflow, efficiency, ci, productivity, integration
9
+
10
+ ## When to Use This Skill
11
+ Use this skill when you need to:
12
+ - Automate repetitive development tasks
13
+ - Implement continuous integration workflows
14
+ - Enhance development efficiency with smart automation
15
+ - Integrate Claude Code with external tools and services
16
+ - Create custom development workflows
17
+ - Ensure code quality through automated checks
18
+
19
+ ## Core Concepts: Hooks Architecture
20
+
21
+ ### What Are Claude Code Hooks?
22
+ Hooks are automated scripts that trigger at specific points in your development workflow:
23
+ - **Pre-commit**: Run before code is committed (linting, testing, formatting)
24
+ - **Post-commit**: Run after commits (documentation, notifications, deployment prep)
25
+ - **Pre-push**: Run before pushing to remote (integration tests, security checks)
26
+ - **Post-merge**: Run after merging branches (cleanup, notifications, deployments)
27
+ - **File-change**: Trigger on specific file modifications
28
+ - **Custom events**: User-defined triggers for specific workflows
29
+
30
+ ### Hook Directory Structure
31
+ ```
32
+ .claude/hooks/
33
+ ├── pre-commit/
34
+ │ ├── lint-and-format.sh
35
+ │ ├── run-tests.sh
36
+ │ └── security-check.py
37
+ ├── post-commit/
38
+ │ ├── update-docs.sh
39
+ │ ├── notify-team.py
40
+ │ └── backup-code.sh
41
+ ├── pre-push/
42
+ │ ├── integration-tests.sh
43
+ │ ├── performance-check.py
44
+ │ └── deployment-prep.sh
45
+ └── custom/
46
+ ├── on-api-change/
47
+ │ └── regenerate-clients.sh
48
+ ├── on-db-migration/
49
+ │ └── run-migrations.sh
50
+ └── on-release/
51
+ └── publish-package.sh
52
+ ```
53
+
54
+ ## Hook Implementation Best Practices
55
+
56
+ ### 1. Hook Script Standards
57
+ ```bash
58
+ #!/bin/bash
59
+ # HOOK: pre-commit-lint-format
60
+ # DESCRIPTION: Lint and format code before commits
61
+ # AUTHOR: Claude Code Hooks Master
62
+ # VERSION: 1.0.0
63
+
64
+ set -e # Exit on any error
65
+
66
+ # Colors for output
67
+ RED='\033[0;31m'
68
+ GREEN='\033[0;32m'
69
+ YELLOW='\033[1;33m'
70
+ NC='\033[0m' # No Color
71
+
72
+ log_info() {
73
+ echo -e "${GREEN}[INFO]${NC} $1"
74
+ }
75
+
76
+ log_warn() {
77
+ echo -e "${YELLOW}[WARN]${NC} $1"
78
+ }
79
+
80
+ log_error() {
81
+ echo -e "${RED}[ERROR]${NC} $1"
82
+ }
83
+
84
+ # Main execution
85
+ main() {
86
+ log_info "Running pre-commit lint and format checks..."
87
+
88
+ # Your automation logic here
89
+ if ! run_linter; then
90
+ log_error "Linting failed. Please fix issues before committing."
91
+ exit 1
92
+ fi
93
+
94
+ if ! run_formatter; then
95
+ log_error "Formatting failed."
96
+ exit 1
97
+ fi
98
+
99
+ log_info "All pre-commit checks passed!"
100
+ }
101
+
102
+ # Helper functions
103
+ run_linter() {
104
+ # Implement your linting logic
105
+ echo "Running linter..."
106
+ # Return 0 for success, 1 for failure
107
+ }
108
+
109
+ run_formatter() {
110
+ # Implement your formatting logic
111
+ echo "Running formatter..."
112
+ # Return 0 for success, 1 for failure
113
+ }
114
+
115
+ # Run main function
116
+ main "$@"
117
+ ```
118
+
119
+ ### 2. Error Handling & Logging
120
+ - Always use `set -e` to fail fast on errors
121
+ - Provide clear, actionable error messages
122
+ - Log both successes and failures
123
+ - Use exit codes appropriately (0 = success, 1 = failure)
124
+
125
+ ### 3. Performance Considerations
126
+ - Keep hooks fast (< 30 seconds for pre-commit)
127
+ - Cache results when possible
128
+ - Run expensive operations in background for post-commit hooks
129
+ - Use parallel execution for independent checks
130
+
131
+ ### 4. Integration with Claude Code Skills
132
+ Hooks can trigger Claude Code skills automatically:
133
+ ```bash
134
+ # In a post-commit hook
135
+ claude_code_run_skill "professional-documentation-writer" "update-api-docs"
136
+ claude_code_run_skill "test-generator" "run-regression-tests"
137
+ ```
138
+
139
+ ## Essential Hook Categories
140
+
141
+ ### 🔍 **Quality Assurance Hooks**
142
+ - **Pre-commit**: Linting, formatting, type checking
143
+ - **Pre-push**: Full test suite, integration tests
144
+ - **Post-merge**: Cross-browser testing, accessibility audits
145
+
146
+ ### 🚀 **Deployment Hooks**
147
+ - **Pre-push**: Build verification, environment checks
148
+ - **Post-commit**: Automatic staging deployments
149
+ - **Post-merge**: Production deployments (with approval gates)
150
+
151
+ ### 📚 **Documentation Hooks**
152
+ - **Post-commit**: Auto-generate API docs, update README
153
+ - **On-api-change**: Regenerate client SDKs
154
+ - **Pre-release**: Generate changelog, update version numbers
155
+
156
+ ### 🔒 **Security Hooks**
157
+ - **Pre-commit**: Secret scanning, dependency vulnerability checks
158
+ - **Pre-push**: Security testing, penetration testing triggers
159
+ - **Post-merge**: Security audit notifications
160
+
161
+ ### 🤝 **Collaboration Hooks**
162
+ - **Post-commit**: Team notifications, Slack updates
163
+ - **Post-merge**: Code review assignments, QA notifications
164
+ - **On-conflict**: Conflict resolution guides, merge conflict notifications
165
+
166
+ ## Advanced Automation Examples
167
+
168
+ ### 1. Smart Commit Messages
169
+ ```bash
170
+ # pre-commit-smart-commit.sh
171
+ # Analyzes changes and suggests commit message format
172
+
173
+ CHANGED_FILES=$(git diff --cached --name-only)
174
+ if echo "$CHANGED_FILES" | grep -q "test"; then
175
+ SUGGEST_TYPE="test"
176
+ elif echo "$CHANGED_FILES" | grep -q "docs"; then
177
+ SUGGEST_TYPE="docs"
178
+ elif echo "$CHANGED_FILES" | grep -q "\.md$"; then
179
+ SUGGEST_TYPE="docs"
180
+ else
181
+ SUGGEST_TYPE="feat"
182
+ fi
183
+
184
+ echo "Suggested commit type: $SUGGEST_TYPE"
185
+ echo "Example: $SUGGEST_TYPE: add user authentication"
186
+ ```
187
+
188
+ ### 2. Intelligent Testing
189
+ ```bash
190
+ # pre-push-smart-testing.sh
191
+ # Runs only relevant tests based on changed files
192
+
193
+ CHANGED_FILES=$(git diff --name-only HEAD~1)
194
+ TEST_COMMAND="npm test"
195
+
196
+ # Run full suite for core changes
197
+ if echo "$CHANGED_FILES" | grep -E "(core|config|package\.json)"; then
198
+ echo "Core changes detected - running full test suite"
199
+ TEST_COMMAND="$TEST_COMMAND -- --coverage"
200
+ # Run specific tests for feature changes
201
+ elif echo "$CHANGED_FILES" | grep -E "src/components"; then
202
+ echo "Component changes detected - running component tests"
203
+ TEST_COMMAND="$TEST_COMMAND -- --testPathPattern=components"
204
+ fi
205
+
206
+ eval $TEST_COMMAND
207
+ ```
208
+
209
+ ### 3. Automated Documentation
210
+ ```bash
211
+ # post-commit-docs-update.sh
212
+ # Auto-updates documentation based on code changes
213
+
214
+ if git diff --name-only HEAD~1 | grep -E "\.(js|ts|py)$"; then
215
+ echo "Code changes detected - updating documentation"
216
+
217
+ # Use Claude Code skills for documentation
218
+ claude_code_run_skill "professional-documentation-writer" "update-api-docs"
219
+
220
+ # Update README if necessary
221
+ if git diff --name-only HEAD~1 | grep -E "(README|readme)"; then
222
+ claude_code_run_skill "professional-documentation-writer" "update-readme"
223
+ fi
224
+ fi
225
+ ```
226
+
227
+ ### 4. Deployment Automation
228
+ ```bash
229
+ # post-merge-deployment.sh
230
+ # Automates deployment after successful merges
231
+
232
+ BRANCH=$(git rev-parse --abbrev-ref HEAD)
233
+ if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
234
+ echo "Merge to main branch detected - starting deployment"
235
+
236
+ # Run final checks
237
+ npm run test:ci
238
+ npm run build
239
+
240
+ # Deploy to staging
241
+ deploy_to_staging
242
+
243
+ # Notify team
244
+ notify_deployment "staging"
245
+
246
+ # Optional: auto-deploy to production after manual approval
247
+ if [ "$AUTO_DEPLOY_PROD" = "true" ]; then
248
+ deploy_to_production
249
+ notify_deployment "production"
250
+ fi
251
+ fi
252
+ ```
253
+
254
+ ## Integration with Claude Code Agents
255
+
256
+ ### Memory System Integration
257
+ ```bash
258
+ # post-commit-memory-update.sh
259
+ # Updates the persistent memory system with project changes
260
+
261
+ COMMIT_MSG=$(git log -1 --pretty=%B)
262
+ CHANGED_FILES=$(git diff --name-only HEAD~1)
263
+
264
+ # Add to decisions memory
265
+ if echo "$COMMIT_MSG" | grep -i "decision\|choice\|architect"; then
266
+ echo "## $(date) - Architecture Decision" >> .claude/memory/decisions.md
267
+ echo "**Decision**: $COMMIT_MSG" >> .claude/memory/decisions.md
268
+ fi
269
+
270
+ # Add to learnings memory
271
+ if echo "$COMMIT_MSG" | grep -i "learn\|discover\|find"; then
272
+ echo "## $(date) - Development Learning" >> .claude/memory/learnings.md
273
+ echo "**Insight**: $COMMIT_MSG" >> .claude/memory/learnings.md
274
+ fi
275
+ ```
276
+
277
+ ### Agent Triggering
278
+ ```bash
279
+ # on-file-change-trigger-agents.sh
280
+ # Triggers specific agents based on file changes
281
+
282
+ CHANGED_FILES=$(git diff --name-only)
283
+
284
+ # Trigger mobile UI specialist for UI changes
285
+ if echo "$CHANGED_FILES" | grep -E "mobile|ui|component"; then
286
+ claude_code_run_agent "mobile-ui-specialist" "review-ui-changes"
287
+ fi
288
+
289
+ # Trigger code reviewer for critical files
290
+ if echo "$CHANGED_FILES" | grep -E "(security|auth|payment)"; then
291
+ claude_code_run_agent "code-reviewer" "security-review"
292
+ fi
293
+ ```
294
+
295
+ ## Performance & Reliability
296
+
297
+ ### Hook Performance Guidelines
298
+ - **Pre-commit**: < 10 seconds (blocking operations)
299
+ - **Pre-push**: < 30 seconds (can be interrupted)
300
+ - **Post-commit**: < 60 seconds (background operations)
301
+ - **Post-merge**: < 5 minutes (deployment operations)
302
+
303
+ ### Reliability Features
304
+ - **Timeout handling**: Prevent hanging hooks
305
+ - **Retry logic**: For network-dependent operations
306
+ - **Fallback behavior**: Graceful degradation on failures
307
+ - **Logging**: Comprehensive logging for debugging
308
+
309
+ ### Monitoring & Maintenance
310
+ ```bash
311
+ # hook-monitor.sh
312
+ # Monitors hook performance and health
313
+
314
+ HOOK_LOGS_DIR=".claude/hooks/logs"
315
+ mkdir -p "$HOOK_LOGS_DIR"
316
+
317
+ # Log hook execution time
318
+ start_time=$(date +%s)
319
+ # ... hook logic ...
320
+ end_time=$(date +%s)
321
+ duration=$((end_time - start_time))
322
+
323
+ echo "$(date): $HOOK_NAME took ${duration}s" >> "$HOOK_LOGS_DIR/performance.log"
324
+
325
+ # Alert on slow hooks
326
+ if [ $duration -gt 30 ]; then
327
+ notify_team "Slow hook detected: $HOOK_NAME (${duration}s)"
328
+ fi
329
+ ```
330
+
331
+ ## Security Considerations
332
+
333
+ ### Safe Hook Practices
334
+ - **Validate inputs**: Never trust user-provided data
335
+ - **Limit permissions**: Run hooks with minimal required permissions
336
+ - **Audit logging**: Log all hook executions for security review
337
+ - **Secret management**: Use secure credential storage (not plain text)
338
+
339
+ ### Network Security
340
+ - **HTTPS only**: All external API calls must use HTTPS
341
+ - **Certificate validation**: Verify SSL certificates
342
+ - **API authentication**: Use proper authentication tokens
343
+ - **Rate limiting**: Respect API rate limits to avoid blocks
344
+
345
+ ## Input Requirements
346
+ - Project type (web app, mobile app, API, library)
347
+ - Development workflow preferences (Git flow, trunk-based, etc.)
348
+ - External integrations needed (CI/CD, monitoring, notifications)
349
+ - Performance requirements and constraints
350
+
351
+ ## Output Format
352
+ Return production-ready hook implementations with:
353
+ - Proper error handling and logging
354
+ - Performance optimizations
355
+ - Security best practices
356
+ - Integration with existing Claude Code skills
357
+ - Documentation and maintenance guides
358
+ - Monitoring and alerting capabilities