typescript-hook-writer
БесплатноБез исполняемых скриптовНе проверенExpert guidance for developing Claude Code hooks in TypeScript with shared utilities, esbuild compilation, and Vitest testing - distributes compiled JS while…
от pr-pm★ 125 звёзд на GitHubОб этом скилле
TypeScript Hook Writer
Use this skill when developing Claude Code hooks in TypeScript. This skill ensures you maintain type safety, shared utilities, proper build pipeline, and comprehensive testing while distributing single-file JavaScript bundles to users.
When to Use This Skill
- Creating new TypeScript hooks for Claude Code
- Setting up the hooks development environment
- Adding shared utilities for hooks
- Writing tests for hooks with Vitest
- Building hooks for distribution
- Publishing TypeScript-based hooks as PRPM packages
Why TypeScript for Hooks?
Advantages over bash:
- Type safety catches errors at compile time
- Shared utility functions reduce code duplication
- Better IDE support with autocomplete and refactoring
- Easier to test with Vitest
- More readable for complex logic
- Strong validation with TypeScript interfaces
Trade-offs:
- Requires build step (esbuild)
- Slightly larger bundle size (~2-3KB vs bash)
- Users still just need Node.js (no TypeScript dependency)
When to use TypeScript hooks:
- Complex input validation or pattern matching
- Hooks that share common logic
- Hooks requiring automated testing
- Teams familiar with TypeScript
When to stick with bash:
- Simple one-off hooks (< 20 lines)
- Hooks that just call other CLI tools
- Extreme performance requirements (though difference is negligible)
Project Structure
packages/hooks/
├── package.json # Build tooling (esbuild, tsx, vitest)
├── tsconfig.json # TypeScript configuration
├── vitest.config.ts # Test configuration
├── scripts/
│ └── build-all-hooks.ts # Build script (compiles all hooks)
├── shared/
│ ├── types.ts # Shared TypeScript interfaces
│ ├── hook-utils.ts # Shared utility functions
│ └── hook-utils.test.ts # Tests for shared utilities
# Each hook lives in .claude/hooks/
.claude/hooks/
├── my-hook/
│ ├── hook.json # Hook configuration
│ ├── README.md # Documentation
│ ├── src/
│ │ ├── hook.ts # TypeScript source (development)
│ │ ├── hook.test.ts # Vitest tests
│ │ ├── hook-utils.ts # Copied shared utilities
│ │ └── types.ts # Copied shared types
│ └── dist/
│ └── hook.js # Compiled bundle (distributed)
Setup: packages/hooks Infrastructure
1. package.json
{
"name": "@prpm/hooks",
"version": "1.0.0",
"description": "Build system and shared utilities for PRPM Claude Code hooks",
"private": true,
"type": "module",
"scripts": {
"build": "tsx scripts/build-all-hooks.ts",
"build:watch": "tsx scripts/build-all-hooks.ts --watch",
"test": "vitest",
"test:watch": "vitest --watch",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"@types/node": "^20.10.0",
"esbuild": "^0.19.8",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"vitest": "^1.0.4"
}
}
2. tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022"],
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
3. vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['**/*.test.ts'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'dist/',
'**/*.test.ts',
'**/scripts/**',
],
},
},
});
4. Build Script: scripts/build-all-hooks.ts
#!/usr/bin/env tsx
/**
* Build script for compiling all Claude Code hooks to standalone JavaScript bundles
*/
import { build, BuildOptions } from 'esbuild';
import { readdirSync, statSync, existsSync, mkdirSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Root directory is app/ which is 3 levels up from packages/hooks/scripts/
const ROOT_DIR = join(__dirname, '../../..');
const HOOKS_DIR = join(ROOT_DIR, '.claude/hooks');
interface HookInfo {
name: string;
srcPath: string;
distPath: string;
}
/**
* Find all hooks with TypeScript source files
*/
function findHooks(): HookInfo[] {
const hooks: HookInfo[] = [];
if (!existsSync(HOOKS_DIR)) {
console.error(`Hooks directory not found: ${HOOKS_DIR}`);
return hooks;
}
const entries = readdirSync(HOOKS_DIR);
for (const entry of entries) {
const hookPath = join(HOOKS_DIR, entry);
// Skip non-directories and special directories
if (!statSync(hookPath).isDirectory() || entry === 'shared') {
continue;
}
c
Установить typescript-hook-writer в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл typescript-hook-writer?
Expert guidance for developing Claude Code hooks in TypeScript with shared utilities, esbuild compilation, and Vitest testing - distributes compiled JS while maintaining TypeScript development experience
Как установить скилл typescript-hook-writer?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл typescript-hook-writer запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic