npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@genzai/claude

v0.3.1

Published

Claude Code integration for Genzai - hooks for protecting generated files with slot-based editing

Readme

@genzai/claude

Claude Code integration for Genzai - protects generated files with slot-based editing.

Overview

This package provides a generator that creates Claude Code integration files:

  1. Hook - Protects files with @regenerationStrategy overwrite, allowing edits only within slot boundaries
  2. Configuration - Sets up .claude/settings.json and custom instructions

Installation

npm install @genzai/claude
# or
pnpm add @genzai/claude

Usage

Use the claudeIntegration generator in your code generation:

import { generate, file, folder, defaultMiddleware } from "@genzai/core";
import { slot, slotMiddleware } from "@genzai/slots";
import { claudeIntegration } from "@genzai/claude";

const appGenerator = () => [
  folder("src", [
    file("config.ts", () => `
export const config = {
  ${slot.begin("custom-config")}
  // Add your custom configuration here
  ${slot.end}
};
`),
  ]),
];

// Compose with Claude Code integration
const generator = () => [
  ...appGenerator(),
  ...claudeIntegration({
    instructions: "Generated files are in src/. Run `npm run generate` to regenerate.",
  }),
];

await generate(generator, "./output", {}, {
  middlewares: [...defaultMiddleware, slotMiddleware],
});

This generates:

output/
  src/
    config.ts           # Your generated file with slots
  .claude/
    hooks/
      genzai-hook.ts    # Pre-tool hook script
    settings.json       # Claude Code configuration
    genzai.json         # Custom instructions (if provided)

How It Works

File Protection

Files generated by Genzai (with defaultMiddleware) include metadata markers:

/**
 * @generated genzai
 * @regenerationStrategy overwrite
 * @slots custom-config
 */

When Claude Code tries to edit a file:

  • preserve-edits: Edit allowed normally
  • overwrite:
    • Edit allowed if within slot content (between @slot and @end-slot markers)
    • Edit blocked if outside slot boundaries or touching markers
  • No marker: Edit allowed (not a generated file)

Slot Editing

Claude can directly edit content within slots using the standard Edit tool:

// This file has @regenerationStrategy overwrite
export const config = {
  /** @slot custom-config */
  timeout: 5000,        // <-- Claude can edit this line
  retryCount: 3,        // <-- Claude can edit this line
  /** @end-slot */

  generatedField: true, // <-- Claude CANNOT edit this line
};

API

claudeIntegration(options?)

Returns a generator that creates the Claude Code integration files.

Options:

  • instructions (string, optional): Custom instructions shown when edits are blocked

Returns: Node[] - Array of nodes to be composed with other generators

Generated Files

.claude/settings.json

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npx tsx .claude/hooks/genzai-hook.ts"
          }
        ]
      }
    ]
  }
}

.claude/genzai.json (if instructions provided)

{
  "instructions": "Generated files are in src/. Run `npm run generate` to regenerate."
}

Testing

After generating, test the integration:

  1. Open Claude Code in the generated project
  2. Try to edit content within a slot - should work
  3. Try to edit generated code outside a slot - should be blocked
  4. Try to edit the slot markers themselves - should be blocked

Related Packages

  • @genzai/core - Core framework with regeneration strategy support
  • @genzai/slots - Slot-based content preservation
  • @genzai/templates - Template-based generation

License

MIT