Getting Started

Learn how to install and set up the Claude Code Validator framework in your project.

Install Package
npm i -D @syncrolabs/claude-code-validator

Set up hooks
.claude/settings.json
 {
   "hooks": {
     "PreToolUse": [
       {
         "matcher": "Edit",
         "hooks": [
           {
             "type": "command",
             "command": "bunx @syncrolabs/claude-code-validator validate",
             "timeout": 10
           }
         ]
       },
       {
         "matcher": "Write",
         "hooks": [
           {
             "type": "command",
             "command": "bunx @syncrolabs/claude-code-validator validate",
             "timeout": 10
           }
         ]
       }
     ]
   }
 }

Create Your First Rule
.claude/rules/my-rule.ts
import { defineCodeRule } from "@syncrolabs/claude-code-validator";

export const myRule = defineCodeRule({
  name: "my-rule",
  description: "Prevents usage of console.log",

  shouldRun: (context) => {
    // Only run on TypeScript and JavaScript files
    return /\.(ts|js)x?$/.test(context.filePath);
  },

  validate(context) {
    const errors: string[] = [];

    if (/console\.log/.test(context.content)) {
      errors.push(
        `❌ console.log detected\n` +
          `   → Use a proper logging library instead\n` +
          `   📄 File: ${context.filePath}`
      );
    }

    return errors;
  },
});

Done ✅

Project Structure

The framework follows this structure:

.claude/
└── rules/                    # Your validation rules (auto-discovered)
    ├── nuxt-ui.ts
    ├── define-model.ts
    └── my-custom-rule.ts

Test Auto-Discovery

Verify your rule is discovered:

bunx @syncrolabs/claude-code-validator list-rules

You should see output like:

📋 Discovered 3 Validation Rules from .claude/rules:

  • my-rule
    Prevents usage of console.log

  • nuxt-ui
    Validate Nuxt UI component usage and patterns

  • define-model
    Enforce use of defineModel() macro instead of modelValue prop + emit pattern

Test the Integration

Try validating manually:

echo '{"tool_name":"Write","tool_input":{"file_path":"test.ts","content":"console.log(\"test\")"}}' | \
  bunx @syncrolabs/claude-code-validator validate

You should see a validation error blocking the operation!

Next Steps