This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A TypeScript-first CLI argument parser wrapping Node.js util.parseArgs() with full type inference. Zero runtime dependencies.
npm test # Run all tests
npm run lint # Run all linters (ESLint, Prettier, types, knip, spelling, markdown, typedoc)
npm run fix # Auto-fix lint issues
npm run build # Build with zshy (dual CJS/ESM)
npm run lint:types # TypeScript check only
# Run a single test file
npm run test:base -- "test/parser.test.ts"
# Run tests matching a pattern
npm run test:base -- --test-name-pattern="parses string" "test/**/*.test.ts"For comprehensive architecture documentation including design philosophy, type inference flow diagrams, and the division of responsibilities between bargs and Node's
parseArgs(), seeARCHITECTURE.md.
src/index.ts exports bargs as a function with builder methods attached via Object.assign(parseAsync, opt). This allows:
import { bargs } from '@boneskull/bargs';
bargs({ ... }); // Call as function
bargs.string({ ... }); // Use as builder namespace-
types.ts - All type definitions. Key types:
OptionsSchema/PositionalsSchema- Schema definitionsInferOptions<T>/InferPositionals<T>- Type inference utilitiesBargsConfig(simple CLI) vsBargsConfigWithCommands(command-based CLI)CommandConfigvsCommandConfigInput- typed vs type-erased command configs
-
opt.ts - Builder functions (
opt.string(),opt.boolean(),opt.enum(), etc.). Uses function overloads for tuple type preservation inopt.options()andopt.positionals(). -
parser.ts -
parseSimple()andparseCommands()wraputil.parseArgs()with type coercion and validation. -
bargs.ts - Main entry point with overloaded signatures for simple vs command-based CLIs. Handles
--helpand--versionflags. -
help.ts - Generates help text with ANSI formatting.
The library uses several TypeScript patterns for type inference:
-
Const type parameters -
opt.enum()uses<const T extends readonly string[]>to infer literal types without requiringas const. -
Function overloads -
opt.options()andopt.positionals()have overloads up to 4 params to preserve tuple types. -
Discriminated unions - Option types use
typefield discriminator ('string' | 'boolean' | 'number' | 'enum' | 'array' | 'count'). -
Handler typing -
CommandConfig.handlerreceivesInferOptions<TOptions> & Record<string, unknown>so command-local options are typed while global options are accessible but untyped.
- Simple CLI: Uses
BargsConfig, supportspositionalsat top level, optionalhandler - Command-based CLI: Uses
BargsConfigWithCommands, no top-levelpositionals(each command has its own), supportsdefaultHandler
- Tests use Node.js built-in test runner (
node:test) withnode:assert/strict. Test files are intest/with.test.tsextension. - To check the test results or coverage, query the WallabyJS MCP server, if running. If not running, refer to the commands section for how to run tests.
Working examples in examples/:
greeter.ts- Simple CLI with options and positionalstasks.ts- Command-based CLI with global options, subcommands, and handlerstransforms.ts- Command-based CLI with global options, subcommands, and transformsnested-commands.ts- Command-based CLI with nested commands
When asked to perform work in a worktree:
- Create the Git worktree under
.worktrees/, creating a new feature branch for it - Navigate to the new worktree directory.
- Execute
npm installin the worktreedirectory.
When asked to create a plan document, place it in the .plans/ directory.