Claude Skills Guide

Claude Code for Hygen Code Generation Workflow

Code generation is a powerful technique for maintaining consistency across your projects, but manually creating templates and managing generation scripts can become tedious. Combining Claude Code with Hygen—a scalable code generator—creates a powerful workflow that lets you generate boilerplate code through natural language commands. This guide shows you how to integrate these two tools effectively.

What is Hygen?

Hygen is a code generator that lets you create, reuse, and share code templates. Unlike simple scaffolding tools, Hygen supports:

Hygen works by defining templates in a _templates directory and generating code through the hygen CLI. However, crafting these templates and remembering the exact commands can be challenging—exactly where Claude Code shines.

Why Combine Claude Code with Hygen?

Claude Code excels at understanding context, suggesting appropriate templates, and handling the intricacies of template syntax. When you combine these capabilities with Hygen’s generation power, you get:

  1. Natural language interface for code generation
  2. Context-aware template suggestions based on your project structure
  3. Automated template creation without memorizing syntax
  4. Intelligent prompt handling for dynamic generation

Setting Up the Integration

First, ensure both tools are installed in your project:

# Install Hygen globally or locally
npm install -g hygen

# Or add to your project
npm install --save-dev hygen

Create a basic Hygen template structure in your project:

hygen init simple

This creates a _templates directory with a basic example. You can then customize these templates or create new ones for your specific needs.

Practical Examples

Example 1: Generating a React Component

Let’s say you frequently create React components and want to automate this with Hygen. Create a template at _templates/component/new.ejs.t:

---
to: src/components/<%= name %>/index.tsx
---
import React from 'react';
import styles from './<%= name %>.module.css';

interface <%= name %>Props {
  className?: string;
}

export const <%= name %>: React.FC<<%= name %>Props> = ({ className }) => {
  return (
    <div className={className}>
      {/* Component implementation */}
    </div>
  );
};

With Claude Code, you can simply ask: “Create a new React component called Button in src/components” and Claude will run the appropriate Hygen command.

Example 2: Creating API Endpoints

For backend development, generate API endpoints consistently:

---
to: src/routes/<%= name %>.ts
---
import { Router, Request, Response } from 'express';

export const <%= name %>Router = Router();

<%= name %>Router.get('/', async (req: Request, res: Response) => {
  try {
    // TODO: Implement handler
    res.json({ message: '<%= name %> endpoint' });
  } catch (error) {
    res.status(500).json({ error: 'Internal server error' });
  }
});

Example 3: Database Model Generation

Generate consistent database models:

---
to: src/models/<%= name %>.ts
---
import { DataTypes, Model } from 'sequelize';

export class <%= name %> extends Model {
  public id!: number;
  public <%= fields %>!: string;
  public readonly createdAt!: Date;
  public readonly updatedAt!: Date;
}

export function init<%= name %>(sequelize: any) {
  <%= name %>.init({
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    <%= fields %>: {
      type: DataTypes.STRING,
      allowNull: false,
    },
  }, {
    sequelize,
    tableName: '<%= tableName || h.inflection.pluralize(name.toLowerCase()) %>',
  });
}

Creating a Claude Skill for Hygen

To make this workflow seamless, create a Claude skill specifically for Hygen operations. Here’s how to structure it:

---
name: hygen-generator
description: Generate code using Hygen templates
---

You are an expert in Hygen code generation. When asked to generate code:

1. First, check existing templates in the _templates directory
2. If no suitable template exists, offer to create one
3. Run appropriate hygen commands with correct arguments
4. Verify the generated files and report results

Available template types:
- component: React/frontend components
- route: API endpoints
- model: Database models
- service: Business logic services
- util: Utility functions

Best Practices

1. Organize Templates Logically

Structure your _templates directory by feature or domain:

_templates/
├── component/
│   ├── new.ejs.t
│   └── stories.ejs.t
├── route/
│   └── new.ejs.t
├── model/
│   └── new.ejs.t
└── _helpers/
    └── functions.ejs

2. Use Consistent Naming Conventions

Follow predictable naming for templates and generated files. Use Hygen’s built-in inflection helpers:

<%= h.inflection.pluralize(name) %>  # "users"
<%= h.inflection.camelize(name) %>   # "userService"
<%= h.inflection.classify(name) %>   # "UserService"

3. Document Your Templates

Add comments within templates explaining what each section does:

---
to: src/<%= h.inflection.pluralize(name) %>/<%= name %>.ts
---
// Generated by Hygen: {{h}} template
// Purpose: Creates a new <%= name %> entity
// Usage: hygen <%= name %> new --name <%= name %>

4. Test Templates Before Production

Always test templates with dry-run mode:

hygen component new --name Button --dry

This shows what would be generated without creating files.

Automating Template Discovery

Claude Code can help you discover and recommend templates based on context. Add this to your skill:

When scanning for templates:
1. List all .ejs.t files in _templates
2. Read their front matter for descriptions
3. Match user's request to best template
4. Explain what will be generated before running

Conclusion

Combining Claude Code with Hygen creates a powerful code generation workflow that reduces boilerplate while maintaining consistency. Claude handles the natural language interface and template suggestions, while Hygen provides the robust generation engine. Start with a few simple templates, establish conventions, and gradually expand your template library as your project grows.

The key is treating code generation as a collaborative process between you and Claude—describe what you need, let Claude handle the template execution, and focus on the unique business logic that only you can write.

Built by theluckystrike — More at zovo.one