CtroEnv
ctroenvType-Safe Environment Variables
Getting StartedQuick StartCore Concepts
defineEnv()string()number()boolean()pick()Chainable MethodsRefinementsError HandlingSchema Composition
CLI Overviewctroenv validatectroenv generatectroenv checkctroenv docsctroenv initCLI Configuration
Node AdapterVite AdapterNext.js Adapter
Migration from t3-envMigration from envalidMigration from dotenv

CLI Configuration

Configure the ctroenv CLI with ctroenv.json or programmatic options.

  1. Docs
  2. CLI

CLI Configuration

Configure the CLI behavior with a config file in your project root.

Supported Formats

FormatFile NameType Safety
TypeScriptctroenv.config.tsFull autocomplete with defineConfig()
JavaScriptctroenv.config.jsJSDoc hints via @type
JSONctroenv.jsonSimple, no imports needed

The CLI auto-detects which file to load. If multiple exist, the first found in the order above is used.

TypeScript (recommended)

import { defineConfig } from "@ctroenv/cli"

export default defineConfig({
  // ... configuration
})

defineConfig() provides autocomplete and type checking. At runtime it simply returns the config object.

JSON

{
  "schema": "./src/env.ts",
  "sources": {
    "default": ".env"
  },
  "output": {
    "example": ".env.example",
    "docs": "ENVIRONMENT.md"
  },
  "secrets": {
    "mask": ["JWT_SECRET"],
    "maskWith": "***"
  }
}

JSON configs are parsed natively — no transformation or imports are needed. Use ctroenv init --json to generate one.

Configuration Options

interface CliConfig {
  schema?: string
  sources?: Record<string, string>
  output?: {
    example?: string
    docs?: string
  }
  secrets?: {
    mask?: string[]
    maskWith?: string
  }
}
OptionTypeDefaultDescription
schemastring"./src/env.ts"Path to the schema file
sources.defaultstring".env"Path to the default .env file
output.examplestring".env.example"Output path for generate
output.docsstring"ENVIRONMENT.md"Output path for docs command
secrets.maskstring[][]Keys to mask in output
secrets.maskWithstring"***"Mask string

ResolvedConfig

At runtime, defaults are applied to produce a ResolvedConfig:

interface ResolvedConfig {
  schema: string
  sources: Record<string, string>
  output: {
    example: string
    docs: string
  }
  secrets: {
    mask: string[]
    maskWith: string
  }
}

Example

import { defineConfig } from "@ctroenv/cli"

export default defineConfig({
  schema: "./src/env.ts",
  sources: {
    default: ".env",
  },
  output: {
    example: ".env.example",
    docs: "docs/environment-variables.md",
  },
  secrets: {
    mask: ["JWT_SECRET", "API_KEY", "PASSWORD"],
    maskWith: "••••••••",
  },
})

How is this guide?

Edit on GitHub

Last updated on Jun 24, 2026

Previousctroenv initNextNode Adapter

On this page

Supported FormatsTypeScript (recommended)JSONConfiguration OptionsResolvedConfigExample