Type-safe combinatorial CLI parser for TypeScript inspired by Haskell's optparse-applicative and TypeScript's Zod. Build composable parsers for command-line interfaces with full type safety, automatic type inference, and built-in shell completion support for Bash, zsh, fish, PowerShell, and Nushell, plus config file integration and man page generation from the same parser definitions.
[!NOTE] Optique is a parsing library that focuses on extracting and validating command-line arguments. It doesn't dictate your application's structure, handle command execution, or provide scaffolding—it simply transforms command-line input into well-typed data structures.
object(), or(), merge(), optional(),
multiple(), map(), conditional(), passThrough(), and more
for composable CLI parsingport(), ipv4(), hostname(), email(), etc.),
Temporal types (via @optique/temporal), Standard Schema validators (via
@optique/standard-schema), Zod schemas (via @optique/zod), and Valibot
schemas (via @optique/valibot)run() function including help,
version, and completion supportimport { option, constant } from "@optique/core/primitives";
import { object, or, merge } from "@optique/core/constructs";
import { optional } from "@optique/core/modifiers";
import { string, integer } from "@optique/core/valueparser";
import { run, print } from "@optique/run";
// Reusable parser components
const commonOptions = object({
verbose: option("-v", "--verbose"),
config: optional(option("-c", "--config", string())),
});
// Mutually exclusive deployment strategies
const localDeploy = object({
mode: constant("local" as const),
path: option("--path", string()),
port: option("--port", integer({ min: 1000 })),
});
const cloudDeploy = object({
mode: constant("cloud" as const),
provider: option("--provider", string()),
region: option("--region", string()),
apiKey: option("--api-key", string()),
});
// Compose parsers with type-safe constraints
const parser = merge(
commonOptions,
or(localDeploy, cloudDeploy)
);
const config = run(parser, { help: "both" });
// config: {
// readonly verbose: boolean;
// readonly config: string | undefined;
// } & (
// | {
// readonly mode: "local";
// readonly path: string;
// readonly port: number;
// }
// | {
// readonly mode: "cloud";
// readonly provider: string;
// readonly region: string;
// readonly apiKey: string;
// }
// )
// TypeScript knows exactly what's available based on the mode
if (config.mode === "local") {
print(`Deploying to ${config.path} on port ${config.port}.`);
} else {
print(`Deploying to ${config.provider} in ${config.region}.`);
}
Optique provides comprehensive documentation to help you get started quickly: https://optique.dev/.
New to Optique? Start with the tutorial and then explore the cookbook.
API reference documentation for each package is available on JSR (see below).
Optique is a monorepo which contains multiple packages. The main package is @optique/core, which provides the shared types and parser combinators. The following is a list of the available packages:
| Package | JSR | npm | Description |
|---|---|---|---|
| @optique/core | JSR | npm | Shared types and parser combinators |
| @optique/run | JSR | npm | Runner for Node.js/Deno/Bun |
| @optique/discover | JSR | npm | Runtime-aware command discovery |
| @optique/config | JSR | npm | Config file support with Standard Schema |
| @optique/clack | JSR | npm | Clack prompt support |
| @optique/derived-defaults | JSR | npm | Defaults derived from parsed values |
| @optique/env | JSR | npm | Environment variable integration |
| @optique/keyring | JSR | npm | OS credential-store password fallback |
| @optique/git | JSR | npm | Git reference parsers (branches, tags, etc) |
| @optique/logtape | JSR | npm | LogTape logging integration |
| @optique/man | JSR | npm | Man page generation from parsers |
| @optique/standard-schema | JSR | npm | Standard Schema value parser integration |
| @optique/temporal | JSR | npm | Temporal value parsers (date and time) |
| @optique/valibot | JSR | npm | Valibot schema integration for validation |
| @optique/zod | JSR | npm | Zod schema integration for validation |
| @optique/inquirer | JSR | npm | Inquirer.js prompt support |
| @optique/prompt | JSR | npm | Generic prompt adapter foundation |
| @optique/testing | JSR | npm | Parser, runner, and subprocess CLI tests |
Contributions are welcome! Read the contributing guide before working on a change. If you use an AI tool, also read the AI usage policy.
TypeScript
99.9%
Type-safe combinatorial CLI parser for TypeScript inspired by Haskell's optparse-applicative and TypeScript's Zod. Build composable parsers for command-line interfaces with full type safety, automatic type inference, and built-in shell completion support for Bash, zsh, fish, PowerShell, and Nushell, plus config file integration and man page generation from the same parser definitions.
[!NOTE] Optique is a parsing library that focuses on extracting and validating command-line arguments. It doesn't dictate your application's structure, handle command execution, or provide scaffolding—it simply transforms command-line input into well-typed data structures.
object(), or(), merge(), optional(),
multiple(), map(), conditional(), passThrough(), and more
for composable CLI parsingport(), ipv4(), hostname(), email(), etc.),
Temporal types (via @optique/temporal), Standard Schema validators (via
@optique/standard-schema), Zod schemas (via @optique/zod), and Valibot
schemas (via @optique/valibot)run() function including help,
version, and completion supportimport { option, constant } from "@optique/core/primitives";
import { object, or, merge } from "@optique/core/constructs";
import { optional } from "@optique/core/modifiers";
import { string, integer } from "@optique/core/valueparser";
import { run, print } from "@optique/run";
// Reusable parser components
const commonOptions = object({
verbose: option("-v", "--verbose"),
config: optional(option("-c", "--config", string())),
});
// Mutually exclusive deployment strategies
const localDeploy = object({
mode: constant("local" as const),
path: option("--path", string()),
port: option("--port", integer({ min: 1000 })),
});
const cloudDeploy = object({
mode: constant("cloud" as const),
provider: option("--provider", string()),
region: option("--region", string()),
apiKey: option("--api-key", string()),
});
// Compose parsers with type-safe constraints
const parser = merge(
commonOptions,
or(localDeploy, cloudDeploy)
);
const config = run(parser, { help: "both" });
// config: {
// readonly verbose: boolean;
// readonly config: string | undefined;
// } & (
// | {
// readonly mode: "local";
// readonly path: string;
// readonly port: number;
// }
// | {
// readonly mode: "cloud";
// readonly provider: string;
// readonly region: string;
// readonly apiKey: string;
// }
// )
// TypeScript knows exactly what's available based on the mode
if (config.mode === "local") {
print(`Deploying to ${config.path} on port ${config.port}.`);
} else {
print(`Deploying to ${config.provider} in ${config.region}.`);
}
Optique provides comprehensive documentation to help you get started quickly: https://optique.dev/.
New to Optique? Start with the tutorial and then explore the cookbook.
API reference documentation for each package is available on JSR (see below).
Optique is a monorepo which contains multiple packages. The main package is @optique/core, which provides the shared types and parser combinators. The following is a list of the available packages:
| Package | JSR | npm | Description |
|---|---|---|---|
| @optique/core | JSR | npm | Shared types and parser combinators |
| @optique/run | JSR | npm | Runner for Node.js/Deno/Bun |
| @optique/discover | JSR | npm | Runtime-aware command discovery |
| @optique/config | JSR | npm | Config file support with Standard Schema |
| @optique/clack | JSR | npm | Clack prompt support |
| @optique/derived-defaults | JSR | npm | Defaults derived from parsed values |
| @optique/env | JSR | npm | Environment variable integration |
| @optique/keyring | JSR | npm | OS credential-store password fallback |
| @optique/git | JSR | npm | Git reference parsers (branches, tags, etc) |
| @optique/logtape | JSR | npm | LogTape logging integration |
| @optique/man | JSR | npm | Man page generation from parsers |
| @optique/standard-schema | JSR | npm | Standard Schema value parser integration |
| @optique/temporal | JSR | npm | Temporal value parsers (date and time) |
| @optique/valibot | JSR | npm | Valibot schema integration for validation |
| @optique/zod | JSR | npm | Zod schema integration for validation |
| @optique/inquirer | JSR | npm | Inquirer.js prompt support |
| @optique/prompt | JSR | npm | Generic prompt adapter foundation |
| @optique/testing | JSR | npm | Parser, runner, and subprocess CLI tests |
Contributions are welcome! Read the contributing guide before working on a change. If you use an AI tool, also read the AI usage policy.
TypeScript
99.9%