Builds command-line interfaces with Optique in TypeScript/JavaScript. Covers combinatorial parsers, subcommands, shell completion, async parsing, and integration packages.
Ships in optique. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Start at https://optique.dev/llms.txt online; these rules also work offline.
run() from @optique/run for apps, parse()/runParser() to embed.runParser(), onError(exitCode, error) supplies a structured
Message; help.onShow(exitCode, page) supplies the final DocPage. Both
follow output. Supply stdout: () => {} for custom help rendering. See
https://optique.dev/concepts/runners.md#structured-help-callbacks.parseArgs()/parseArgsSync() from @optique/testing/parser
for parser results, captureRun() from @optique/testing/run for runner
output/exits, captureProgramRun() from @optique/testing/discover for
dispatch, and createCliRunner() from @optique/testing/cli for real CLIs.
Pin colors/maxWidth in tests; defaults use terminal and environment.object(), tuple(), seq(), or(), merge(), and
modifiers. Do not hand-write argument scanners around Optique parsers.helpSections: { commands: "Commands", options: "Options" }.
It groups untitled entries only on pages with visible commands. See
https://optique.dev/cookbook.md#command-and-option-headings-in-help.optional(p) yields undefined; use
withDefault(p, value) or withDefault(flag("-v"), false) for fallbacks.message helpers; keep canonical errors unthemed. Since
1.3.0, theme/messageFormatter should preserve initialWidth, quoting,
and width options. flag() has static/callback errors.unexpectedValue
since 1.4.0. Mismatch callbacks may be skipped; avoid side effects.integer(), choice(), biject(), regExp(),
url(), origin(), and uuid() instead of validating raw strings after
parsing. Use regExp({ flags }) for user-supplied sources, biject() for
one-to-one mappings, transform() for mapped results, and
choice(values, { key }) for custom string matching that returns the
declared spelling. Use normalizeInput() to clean raw strings,
withSuggestions() to replace completions, and path() (@optique/run)
for paths. Write a custom value parser only when these do not fit.-p8080/-vp8080 accept attached values. Values consume
the literal suffix (-p=5 gives "=5"); full single-dash names win.run()/parse()/runParser() or, for bindKeyring(), runAsync().dependency() when one value parser controls another's valid values.
For a multi-level chain, wrap the middle derivation too:
dependency(source.deriveSync(...)). Optique resolves such chains by
dependency order, independently of object/tuple field order.derivePromptConfig(source, resolver) from @optique/prompt or its
adapters for choices/messages depending on parsed values; use
[sourceA, sourceB] for several sources. Async resolvers run at fallback
after sources resolve. Match the prompt kind to the parser's value type;
derive the CLI parser separately. A lone resolver fetches choices lazily;
forward its signal. Clack pendingMessage enables a resolver spinner.{ validate, maxAttempts, signal } as prompt()'s third argument.
Return undefined to accept or a structured Message to retry, sync/async.
Attempt limits are positive integers; retries default to unlimited.
Clack autocomplete also has sync native validation; Inquirer search
has sync/async native validation. Multi selections use shared validation.autocomplete filters one selection; autocomplete-multiselect
returns readonly string[]. Both take array options. Inquirer search
calls source(term, { signal }) per query; forward the signal to requests.
Empty search input gives undefined.execute(config, context) so retries can show
context.previousValidationMessage, and forward context.signal when the
prompt library supports aborting active work. Adapter-native validation
remains separate and completes inside one shared attempt.command() combined by or(); add a literal field
such as command: constant("serve") per branch for a discriminated union.
Show hidden aliases in help with showAliases on command() or runner.run(parser, { completion: "both" }) for completion, or the object form
with completion.errors for custom shell errors. Do not hand-write scripts.usageLine: [{ type: "ellipsis" }] for compact root full help and the
override on command() for subcommand help. errorUsage: "command" scopes
usage above errors with root fallback, ignoring help-only overrides.showUsage: false in runner options when full help should show the
brief and sections without Usage:. Set command()'s showUsage: true
to restore it; children inherit the nearest explicit ancestor setting.
Add commandList: "top-level" to list only first-level command groups.termWidth: "auto" in runner options when descriptions should align
after the widest visible help term. Optique measures terminal display
width after adding built-in help/version/completion entries.import { object } from "@optique/core/constructs";
import { message } from "@optique/core/message";
import { withDefault } from "@optique/core/modifiers";
import { argument, flag, option } from "@optique/core/primitives";
import { integer, string } from "@optique/core/valueparser";
import { run } from "@optique/run";
const parser = object({
input: argument(string({ metavar: "FILE" }), {
description: message`Input file to process.`,
}),
port: withDefault(
option("--port", integer({ min: 1, max: 65535 }), {
description: message`Port to listen on.`,
}),
3000,
),
verbose: withDefault(
flag("-v", "--verbose", { description: message`Enable verbose logging.` }),
false,
),
});
const config = run(parser, {
brief: message`Process a file.`,
completion: "both",
showDefault: true,
termWidth: "auto",
});
console.log(`Processing ${config.input} on port ${config.port}.`);
Use command() for each branch and or() to require exactly one matching
subcommand. Use optional(or(...)) only when no subcommand is valid.
import { object, or } from "@optique/core/constructs";
import { withDefault } from "@optique/core/modifiers";
import { parse } from "@optique/core/parser";
import { command, constant, flag, option } from "@optique/core/primitives";
import { integer } from "@optique/core/valueparser";
const parser = or(
command("build", object({
command: constant("build"),
watch: withDefault(flag("--watch"), false),
})),
command("serve", object({
command: constant("serve"),
port: withDefault(option("--port", integer({ min: 1 })), 3000),
})),
);
const result = parse(parser, ["serve", "--port", "8080"]);
if (result.success) {
switch (result.value.command) {
case "build":
result.value.watch;
break;
case "serve":
result.value.port;
break;
}
}
Prefer the built-in catalog first. If a one-to-one dictionary can describe the
input tokens and domain values, use biject(). If an existing parser already
accepts the right input syntax, wrap it with transform() before writing a
custom parser:
import { biject, choice, transform } from "@optique/core/valueparser";
const exitCode = biject({
ok: 0,
warning: 1,
error: 2,
});
const logLevel = transform(choice(["debug", "info", "warn", "error"] as const), {
map(value) {
return value.toUpperCase() as "DEBUG" | "INFO" | "WARN" | "ERROR";
},
unmap(value) {
return value.toLowerCase() as "debug" | "info" | "warn" | "error";
},
});
When a custom domain is needed, keep the validation in a value parser so help, errors, defaults, prompts, and completion all see the same typed value.
import { message } from "@optique/core/message";
import type { ValueParser, ValueParserResult } from "@optique/core/valueparser";
const levels = ["debug", "info", "warn", "error"] as const;
type Level = typeof levels[number];
function isLevel(input: string): input is Level {
return (levels as readonly string[]).includes(input);
}
function logLevel(): ValueParser<"sync", Level> {
return {
mode: "sync",
metavar: "LEVEL",
placeholder: "info",
parse(input: string): ValueParserResult<Level> {
if (isLevel(input)) return { success: true, value: input };
return { success: false, error: message`Invalid log level: ${input}.` };
},
format(value: Level): string {
return value;
},
};
}
const parser = logLevel();
run() for apps; pass args to parse(). Do not pre-parse argv.defineEmptyInputBehavior() in
@optique/core/extension; use inheritEmptyInputBehavior() for
transparent wrappers. See extension APIs.or(a, b) as “zero or more alternatives.” Wrap it in
optional() or withDefault() to allow no matching branch.or(command(...), command(...)) for mutually exclusive subcommands.flag("--x") in optional() or withDefault(..., false).multiple(p) accepts absence as []; use nonEmpty() to require values.seq() only for ordered grammars; most constructs use parser priority.
In wrappers, require the program name before greedy passThrough().message values for errors and descriptions.bindEnv(), bindConfig(), bindDerivedDefault(),
and bindKeyring() in the runner's contexts option.bindEnv().readFallback() for env/default in error handlers.showEnvironment for env-only help; set documentation.description.showDefault/showChoices to format them.dependency() graphs; avoid duplicate one-level factories.when, with typed otherwise; evaluate them
only at fallback, never eagerly during construction.For the detailed maintained guide, use https://optique.dev/pitfalls.md.
| Package | Use for | Docs |
|---|---|---|
@optique/env | Environment variable fallbacks | https://optique.dev/integrations/env.md |
@optique/keyring | Async OS credential-store password fallback | https://optique.dev/integrations/keyring.md |
@optique/config | Configuration file fallbacks | https://optique.dev/integrations/config.md |
@optique/derived-defaults | Defaults computed from first-pass results | https://optique.dev/concepts/derived-defaults.md |
@optique/prompt | Generic prompt adapter foundation | https://optique.dev/integrations/prompt.md |
@optique/clack | Clack interactive fallback prompts | https://optique.dev/integrations/clack.md |
@optique/inquirer | Inquirer.js interactive fallback prompts | https://optique.dev/integrations/inquirer.md |
@optique/standard-schema | Portable schema-backed value parsing | https://optique.dev/integrations/standard-schema.md |
@optique/zod | Zod-backed value parsing | https://optique.dev/integrations/zod.md |
@optique/valibot | Valibot-backed value parsing | https://optique.dev/integrations/valibot.md |
@optique/temporal | Temporal date and time parsers | https://optique.dev/integrations/temporal.md |
@optique/git | Async Git reference validation | https://optique.dev/integrations/git.md |
@optique/logtape | LogTape levels and formatter/output options | https://optique.dev/integrations/logtape.md |
@optique/man | Man pages and Markdown references | https://optique.dev/concepts/man.md |
@optique/discover | Command discovery; opt-in defaultCommand and help.bareGroup | https://optique.dev/concepts/discover.md |
@optique/testing | Layered CLI testing at a chosen boundary | https://optique.dev/concepts/testing.md |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/optique:optiquefrom optique
npx claudepluginhub dahlia/optique --plugin optiqueOther plugins' skills for the same job