Hexbus
Use this skill to create good CLIs with hexbus, the opinionated TypeScript ESM CLI framework from https://github.com/inthhq/hexbus.
Start Here
- Do not assume the upstream
hexbusmonorepo exists in the user's workspace. - For public API intent, use the package docs if installed, or read https://github.com/inthhq/hexbus/blob/main/packages/hexbus/README.md.
- Use https://github.com/inthhq/hexbus/blob/main/examples/minimal-cli/src/index.ts as the canonical runnable consumer pattern.
- Check https://github.com/inthhq/hexbus/blob/main/packages/hexbus/src/index.ts for current exports instead of assuming an API exists.
- When editing this skill repo itself, a vendored snapshot may exist at
inrepo_modules/hexbus; treat GitHub as the portable source for agents that only receive the skill. - Keep
hexbusand@inth/hexbus-*packages free of product-specific imports and copy.
Consumer Pattern
Build CLIs around a small command table and one resolved context:
import {
createCliContext,
displayIntro,
globalFlags,
isVersionRequest,
printVersionInfo,
showHelpMenu,
startBackgroundUpdateCheck,
} from "hexbus";
import type { CliCommand } from "hexbus";
- Define
CliCommand[]with stablename,label,hint,description, and an asyncaction(context). - Handle
-v/--versionearly withisVersionRequestandprintVersionInfo. - Call
createCliContext({ rawArgs, commands, appName, configName })once. - Start update checks with
startBackgroundUpdateCheckduring normal command execution. - Render
--helpwithshowHelpMenu(context, appInfo, commands, globalFlags). - Route to the matched command via
context.commandName; show help for unknown commands.
Context Services
Prefer existing CliContext services over ad hoc utilities:
context.loggerfor user-facing output and progress steps.context.confirm()for prompts; it respects-y/--yes.context.config.loadConfig()andrequireConfig()for config loading.context.fsfor project-rooted package info and file access.context.packageManagerfor install, add, run, and exec command strings.context.frameworkfor detected framework/package metadata.context.telemetryfor best-effort lifecycle and command events.context.errorfor normalized cancellation and error exits.
Extend CliContext<TPackage> when a product CLI injects app-specific services, but keep command implementations typed against the smallest context they need.
Errors And UX
- Throw
CliErrorfor expected user-facing failures. - Use
extendErrorCatalogfor product-specific error codes. - Wrap top-level execution with
withErrorHandlingor usecontext.error.handleErrorfor consistent rendering and telemetry. - Use
displayIntro,createCliLogger,createSpinner,withSpinner, andshowHelpMenufor terminal UX. - Do not print raw stack traces for expected CLI failures.
Editing Hexbus
- If the user's workspace is a checkout of https://github.com/inthhq/hexbus, edit local files there. Otherwise, explain the relevant GitHub paths and provide patches or guidance against the upstream source.
- Keep public exports centralized in
packages/hexbus/src/index.tsin the upstream repo. - Add or update focused Vitest coverage when changing parser, context, detection, errors, telemetry, color, or update behavior.
- Preserve the framework-style boundary: shared CLI primitives belong in
hexbus; product decisions belong in consuming packages. - Prefer small explicit APIs over broad abstractions.
- Update
packages/hexbus/readie.jsonin the upstream repo when README-facing docs change, then regenerate docs with the repo script.
Bundled Resources
- Load
references/good-cli-checklist.mdwhen designing, reviewing, or improving CLI UX. - Load
references/testing-hexbus-clis.mdwhen adding tests or planning coverage. - Load
examples/cli-entrypoint.tswhen scaffolding a new production-style CLI entrypoint.
Commands
When working in an upstream hexbus checkout, use Bun from that repo root:
bun run test --filter=hexbusbun run check-types --filter=hexbusbun run lint --filter=hexbusbun run build --filter=hexbusbun run readiebun x ultracite fix