Define Claude Code hooks with full type safety using TypeScript. Enables operations teams to automate workflows with type-safe hooks. Integrates with Claude agents for reliable automation.
git clone https://github.com/sushichan044/cc-hooks-ts.gitcc-hooks-ts is a TypeScript library that lets you define type-safe hooks for Claude Code, triggering custom automation logic on events like SessionStart, PreToolUse, PostToolUse, and PermissionRequest. It provides full type safety for tool inputs and supports tool-specific hooks, conditional execution, and advanced JSON output including experimental async operations. Operations teams use it to enforce security policies, block dangerous commands, customize session behavior, and integrate MCP-defined tools with type checking. The library handles hook configuration through Claude Code settings and supports multiple JavaScript runtimes including Node.js, Bun, and Deno.
[{"step":"Define your input/output interfaces in a new TypeScript file (e.g., `automation-hooks.ts`). Use descriptive names and include all required fields. Validate with your IDE's TypeScript support.","tip":"Use `Deno` for hook development as it provides built-in TypeScript support and secure permissions for file operations."},{"step":"Implement the hook logic using the interfaces. Include error handling for common failure cases (file not found, invalid format, etc.).","tip":"Log intermediate steps to `Deno.stderr` for debugging during development: `console.error('Processing:', input.filePath)`."},{"step":"Test the hook locally with sample data. Create a test script that calls the hook with valid/invalid inputs and verifies the outputs.","tip":"Use `Deno test` for unit testing. Example: `Deno.test('validateDataFile', () => { ... });`."},{"step":"Integrate the hook with your Claude agent. Import the hook in your agent's workflow file and call it with the required inputs.","tip":"Use `await` for async operations in hooks. Example: `const output = await validateDataFile(input);`"},{"step":"Deploy the hook to your automation environment. Ensure the execution context has permissions to access required resources (files, APIs, etc.).","tip":"Use `deno compile` to create a standalone binary for deployment: `deno compile --allow-read --allow-net automation-hooks.ts`."}]
Block dangerous bash commands or file access before tool execution
Enforce security policies on tool usage with type-safe validation
Customize session startup with welcome messages and initialization logic
Add type-safe hooks for custom MCP tools and external integrations
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/sushichan044/cc-hooks-tsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Create a type-safe Claude Code hook in TypeScript for [AUTOMATION_TASK] that integrates with [CLAUDE_AGENT_NAME]. The hook should handle [INPUT_TYPE] and return [OUTPUT_TYPE]. Include error handling for [POTENTIAL_ERRORS]. Use the following structure: ```typescript
// [HOOK_NAME].ts
export interface [INPUT_INTERFACE] { ... }
export interface [OUTPUT_INTERFACE] { ... }
export const [HOOK_NAME] = (input: [INPUT_INTERFACE]): [OUTPUT_INTERFACE] => { ... };
``````typescript
// data-validation-hook.ts
export interface DataValidationInput {
filePath: string;
expectedColumns: string[];
delimiter?: string;
}
export interface DataValidationOutput {
isValid: boolean;
errors: string[];
rowCount: number;
}
export const validateDataFile = (input: DataValidationInput): DataValidationOutput => {
const errors: string[] = [];
let rowCount = 0;
try {
const fileContent = Deno.readTextFileSync(input.filePath);
const lines = fileContent.split('\n').filter(line => line.trim() !== '');
rowCount = lines.length;
if (rowCount === 0) {
errors.push('File is empty');
return { isValid: false, errors, rowCount };
}
const header = lines[0].split(input.delimiter || ',');
const missingColumns = input.expectedColumns.filter(col => !header.includes(col));
if (missingColumns.length > 0) {
errors.push(`Missing columns: ${missingColumns.join(', ')}`);
}
if (errors.length === 0) {
return { isValid: true, errors: [], rowCount };
}
return { isValid: false, errors, rowCount };
} catch (error) {
errors.push(`Failed to read file: ${error.message}`);
return { isValid: false, errors, rowCount: 0 };
}
};
```
This hook validates CSV/TSV files against expected columns and returns structured validation results. It handles file reading errors, empty files, and missing columns with clear error messages. The type-safe interfaces ensure compile-time checks for input/output compatibility with Claude agents.Agents that listen, think and act for you.
AI assistant built for thoughtful, nuanced conversation
Real-time collaborative writing platform
IronCalc is a spreadsheet engine and ecosystem
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan