clay [options] [command]
Options:
-V, --version Output the version number
-v, --verbose Enable verbose output
-h, --help Display help information
Initialize a Clay project or generator
clay init [type] [name]
Initialize a project:
clay init
Creates a .clay file in the current directory.
Initialize a generator:
clay init generator my-generator
Creates a new generator in clay/generators/my-generator/
Set up Claude Code hooks to prevent editing Clay-generated files
clay init-claude
Creates .claude/settings.json with a PreToolUse hook
that calls clay check-generated before any Edit/Write
operation. No scripts are generated — Clay handles the check
entirely.
Safe to run multiple times — merges into existing settings without overwriting.
Check if a file is Clay-generated (used internally by hooks)
echo '{"file_path": "/path/to/file.ts"}' | clay check-generated
Reads JSON from stdin, checks the .clay manifest, and
exits with code 2 if the file is generated (blocking the edit).
Exits 0 otherwise. This command is called automatically by the Claude
Code hook — you don't need to run it manually.
Add the Clay MCP server to your AI platform's MCP configuration
clay init-mcp
Interactively asks which AI platforms you use, with auto-detection
of platforms already present in your project (e.g. .vscode/,
.claude/, .cursor/).
Supported platforms:
.vscode/mcp.json.mcp.json.cursor/mcp.jsonMerges into existing config files without overwriting other servers. Safe to run multiple times.
Generate code from your model
clay generate <model_path> <output_path>
clay generate # Uses .clay file
Examples:
# Explicit paths
clay generate ./clay/model.json ./src
# Using .clay file (recommended)
clay generate
# Verbose output
clay generate -v
Remove all generated files
clay clean <model_path> <output_path>
clay clean # Uses .clay file
Examples:
# Explicit paths
clay clean ./clay/model.json ./src
# Using .clay file
clay clean
Watch for model changes and regenerate automatically
clay watch <model_path> <output_path>
clay watch # Uses .clay file
Examples:
# Watch the clay directory
clay watch ./clay/model.json ./src
# Using .clay file
clay watch
Clay will monitor the model directory and regenerate when files change.
Test JSONPath expressions against your model
clay test-path <model_path> <json_path>
Examples:
# Get all types
clay test-path ./clay/model.json "$.model.types[*]"
# Get all fields
clay test-path ./clay/model.json "$.model.types[*].fields[*]"
# Filter by property
clay test-path ./clay/model.json "$.model.types[?(@.isActive)]"
# Get array-type fields
clay test-path ./clay/model.json "$.model.types[*].fields[?(@.type=='array')]"
The .clay file tracks generated files and stores
configuration. It's created with clay init.
Structure:
{
"model": "clay/model.json",
"output": ".",
"files": [
"src/models/user.model.js",
"src/models/order.model.js",
"src/controllers/user.controller.js"
]
}
Benefits:
# 1. Create project directory
mkdir my-project && cd my-project
# 2. Initialize Clay
clay init
# 3. Create model directory
mkdir -p clay
# 4. Create your model
cat > clay/model.json << 'EOF'
{
"name": "my-app",
"generators": ["./generators/api"],
"model": {...}
}
EOF
# 5. Generate code
clay generate
# Terminal 1: Watch for changes
clay watch
# Terminal 2: Edit model and templates
vim clay/model.json
vim clay/generators/api/templates/model.js
# Files regenerate automatically!
# Test a selector before using in generator
clay test-path ./clay/model.json "$.model.types[*]"
# Verify filtered results
clay test-path ./clay/model.json "$.model.types[?(@.isActive)]"
# Check nested paths
clay test-path ./clay/model.json "$.model.types[*].commands[*].parameters[*]"
# Remove all generated files
clay clean
# Regenerate from scratch
clay generate
Clay respects these environment variables:
NODE_ENV - Can affect formatter behaviorDEBUG - Set to "clay:*" for debug output| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error (invalid args, file not found, etc.) |
| 2 | Template or generator error |
-v flag to see detailed output during generation
watch during active development for instant
feedback
.clay to version control for team consistency
.gitignore if they're always
regenerated
alias cg="clay generate"
alias cw="clay watch"
alias cc="clay clean"