create-cli4ai
v1.0.0
Published
Create fully typed and validated cli4ai tools
Maintainers
Readme
create-cli4ai
Create fully typed and validated cli4ai tools with a single command.
Usage
# Interactive mode
npx create-cli4ai
# With package name
npx create-cli4ai my-awesome-tool
# Quick mode with defaults
npx create-cli4ai my-tool -yWhat it generates
A complete cli4ai package with:
run.ts- CLI entry point with Commander.jslib.ts- Core logic separated from CLI handlingschema.ts- Zod schemas for input validation (optional)lib.test.ts- Vitest test suitecli4ai.json- Package manifestpackage.json- npm package configtsconfig.json- TypeScript configREADME.md- Documentation
Interactive prompts
The CLI will ask you:
- Package name - lowercase, hyphens allowed (e.g.,
my-tool) - Description - what your tool does
- Author - optional
- Use Zod? - for input validation
- Commands - define each command with:
- Name
- Description
- Arguments (name, required, type)
- Environment variables - if your tool needs API keys, etc.
Example
$ npx create-cli4ai
create-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 --helpGenerated 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
└── .gitignoreOptions
| Option | Description |
|--------|-------------|
| -y, --yes | Skip prompts, use defaults |
| -d, --dir <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:
- Testable - Easy to unit test without CLI overhead
- Reusable - Import functions in other projects
- Clean - Clear separation of concerns
- 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
// Generated schema.ts
export const envSchema = z.object({
GITHUB_TOKEN: z.string().optional(),
});
// Generated lib.ts
export const reposInputSchema = z.object({
username: z.string(),
});License
MIT
