Create fully typed and validated cli4ai tools
npm install create-cli4aiCreate fully typed and validated cli4ai tools with a single command.
``bashInteractive mode
npx create-cli4ai
What it generates
A complete cli4ai package with:
-
run.ts - CLI entry point with Commander.js
- lib.ts - Core logic separated from CLI handling
- schema.ts - Zod schemas for input validation (optional)
- lib.test.ts - Vitest test suite
- cli4ai.json - Package manifest
- package.json - npm package config
- tsconfig.json - TypeScript config
- README.md - DocumentationInteractive prompts
The CLI will ask you:
1. Package name - lowercase, hyphens allowed (e.g.,
my-tool)
2. Description - what your tool does
3. Author - optional
4. Use Zod? - for input validation
5. Commands - define each command with:
- Name
- Description
- Arguments (name, required, type)
6. Environment variables - if your tool needs API keys, etc.Example
`bash
$ npx create-cli4aicreate-cli4ai v1.0.0
? Package name: github-stats
? Description: Get GitHub repository statistics
? Author: yourname
? Use Zod for input validation? Yes
Commands
Define the commands for your tool. Press Enter with empty name to finish.
? Command 1 name: repos
? Description: List repositories for a user
Arguments (press Enter with empty name to finish):
? Arg 1 name: username
? Required? Yes
? Description: GitHub username
? Type: string
? Arg 2 name:
? Command 2 name: stats
? Description: Get stats for a repository
Arguments (press Enter with empty name to finish):
? Arg 1 name: repo
? Required? Yes
? Description: Repository name (owner/repo)
? Type: string
? Arg 2 name:
? Command 3 name:
Environment Variables
Define required env vars. Press Enter with empty name to finish.
? Env var 1 name: GITHUB_TOKEN
? Required? No
? Description: GitHub personal access token
? Env var 2 name:
Done! Created github-stats
Next steps:
cd github-stats
npm test
npx tsx run.ts --help
`Generated structure
`
github-stats/
├── cli4ai.json # cli4ai manifest
├── package.json # npm package
├── run.ts # CLI entry point
├── lib.ts # Core logic
├── lib.test.ts # Tests
├── schema.ts # Zod validation schemas
├── tsconfig.json # TypeScript config
├── vitest.config.ts # Test config
├── README.md # Documentation
└── .gitignore
`Options
| Option | Description |
|--------|-------------|
|
-y, --yes | Skip prompts, use defaults |
| -d, --dir | Output directory (defaults to package name) |
| --no-git | Skip git initialization |
| --no-install | Skip npm install |Why separate lib.ts?
Keeping business logic in
lib.ts separate from CLI handling in run.ts:1. Testable - Easy to unit test without CLI overhead
2. Reusable - Import functions in other projects
3. Clean - Clear separation of concerns
4. MCP-ready - Logic works the same via CLI or MCP
Zod validation
When you enable Zod, the generated code includes:
- Input validation for command arguments
- Environment variable validation
- Type inference from schemas
- Helpful error messages
`typescript
// Generated schema.ts
export const envSchema = z.object({
GITHUB_TOKEN: z.string().optional(),
});// Generated lib.ts
export const reposInputSchema = z.object({
username: z.string(),
});
``MIT