Skip to main content
Claude Code

GitHub Launches Payshak/claude-hook-kit, a TypeScript SDK for building Claude Code hooks

Published by
SectorHQ Editorial
GitHub Launches Payshak/claude-hook-kit, a TypeScript SDK for building Claude Code hooks

Photo by Alexey Demidov (unsplash.com/@alexeydemidov) on Unsplash

According to a recent report, GitHub has unveiled the Payshak/claude-hook-kit — a TypeScript SDK that adds type safety, testing utilities, and composable patterns to Claude Code’s raw JSON hook system.

Key Facts

  • Key company: Claude Code

GitHub’s new Payshak/claude‑hook‑kit is more than a convenience wrapper—it’s a full‑blown developer experience upgrade for Claude Code’s otherwise brittle hook system, according to the package’s own documentation. By swapping raw shell scripts that read and write JSON for a typed TypeScript SDK, developers now get compile‑time safety, built‑in testing helpers, and a set of composable primitives that turn ad‑hoc “hook‑as‑a‑script” into a maintainable codebase. The kit ships with a single entry point, `defineHook`, which automatically parses stdin, serializes stdout, and catches errors, letting you focus on the logic that matters: deciding whether to allow, block, or augment a tool call.

The SDK’s API is deliberately minimal yet expressive. A hook is defined by passing an async handler to `defineHook`; the handler receives a strongly‑typed `event` object that mirrors Claude Code’s JSON payload. From there you can call `allow()` to let the operation proceed, `block(reason?)` to abort it with a custom error message, or `inject(context)` to prepend a string to Claude’s context window. The documentation even shows a concrete example that blocks any Bash command containing `rm -rf /`, illustrating how a single line of TypeScript can replace a fragile Bash script that would otherwise have to manually parse JSON and manage exit codes.

Testing, which was previously a nightmare because hooks interacted only via stdin/stdout, is now a first‑class feature. The kit exposes a `.handle()` method that lets you invoke the handler directly with a mock event object, bypassing the need for a live Claude Code process. In the repo’s README, a unit test demonstrates this pattern: a hook that blocks sudo commands is fed a synthetic event, and the test asserts that the response matches `{ decision: 'block', reason: 'No sudo' }`. This approach brings the same confidence developers expect from modern JavaScript testing frameworks to the world of AI‑driven tool orchestration.

Beyond the core decision helpers, claude‑hook‑kit bundles a handful of utility functions that make common pattern matching painless. `matchesGlob(path, pattern)` supports standard glob syntax (including ``, `*`, `?`, and brace expansion) for file‑path checks, while `matchesRegex(text, pattern)` accepts either a RegExp object or a string pattern. These helpers let you write declarative guards—such as refusing to run commands on files that match a “read‑only” glob—without pulling in heavyweight libraries. The SDK also includes `matchesAnyGlob` and `matchesAnyRegex` for batch evaluations, reinforcing the composable ethos that GitHub promotes throughout the package.

Installation is straightforward: a single `npm install claude-hook-kit` command, with a Node ≥ 18 requirement. Once installed, hooks are registered in `~/.claude/settings.json` under the `hooks` section, mapping lifecycle events (e.g., `PreToolUse`, `PostToolUse`, `SessionStart`) to the command that runs the compiled TypeScript file. The documentation clarifies which events can block or inject context—PreToolUse can do both, PostToolUse can only inject, and SessionStart can only block—giving developers a clear mental model of where to place their logic.

In practice, the kit promises to turn Claude Code from a “cool demo” into a production‑ready tool for enterprises that need fine‑grained control over AI‑generated actions. By providing type safety, testability, and reusable patterns out of the box, GitHub is addressing the biggest pain point developers have expressed about Claude’s hook system: its reliance on raw JSON shells. As the repository’s README notes, the SDK “fixes” this gap, and early adopters can now write hooks that are as robust as any other part of their codebase—no more fragile one‑liners, just clean, composable TypeScript.

Sources

Primary source

Reporting based on verified sources and public filings. Sector HQ editorial standards require multi-source attribution.

More from SectorHQ:📊Intelligence📝Blog

🏢Companies in This Story

Related Stories