ctroenv init
Scaffold a new ctroenv configuration file interactively from the CLI.
ctroenv init
Scaffold a new CtroEnv configuration file.
Usage
ctroenv init [options]
Options
| Option | Default | Description |
|---|---|---|
--ts | default | Generate TypeScript config (ctroenv.config.ts) |
--js | Generate JavaScript config (ctroenv.config.js) | |
--json | Generate JSON config (ctroenv.json) | |
--minimal | Generate minimal config without optional fields | |
--from-env <path> | Path to a .env file to infer schema from and generate src/env.ts |
Examples
TypeScript config (default)
ctroenv init
# Creates: ctroenv.config.ts
JavaScript config
ctroenv init --js
# Creates: ctroenv.config.js
JSON config
ctroenv init --json
# Creates: ctroenv.json
Minimal config
ctroenv init --minimal
# Creates: ctroenv.config.ts with only the schema field
ctroenv init --json --minimal
# Creates: ctroenv.json with only the schema field
From .env file
Generate a schema stub from an existing .env file to bootstrap validation:
ctroenv init --from-env .env
# Reads .env, infers types (number, boolean, string), creates src/env.ts
The generator infers types heuristically: numeric values become number(), boolean-like values become boolean(), everything else becomes string(). Always review the generated schema and adjust refinements (.url(), .min(), .secret()) as needed.
Generated Files
When using --ts or --js:
import { defineConfig } from "@ctroenv/cli"
export default defineConfig({
schema: "./src/env.ts",
// ...
})
When using --json:
{
"schema": "./src/env.ts",
"sources": {
"default": ".env"
},
"output": {
"example": ".env.example",
"docs": "ENVIRONMENT.md"
},
"secrets": {
"mask": [],
"maskWith": "***"
}
}How is this guide?
Last updated on Jun 30, 2026