spf13/cobra

Published on Oct 18, 2026
★ 44.7k Go Apache-2.0

Build enterprise Go CLI apps with POSIX flags and subcommands

The Go framework powering kubectl, Docker, and GitHub CLI.

Cobra structures complex tools with nested subcommands and flags.

First, structure. Cobra breaks large CLI applications into commands, args, and flags. Subcommands can nest infinitely, letting you build clean patterns like app server start or git clone.

Hierarchical command routing · infinite subcommand nesting

Fully POSIX-compliant flags handle short, long, and cascading options.

Second, flags. Powered by the pflag library, Cobra gives you full POSIX compliance. You can define persistent flags inherited across every subcommand, or local flags scoped to a single action.

POSIX-compliant pflags · persistent and local scoping

Automatic shell completions support Bash, Zsh, Fish, and PowerShell.

Third, developer experience. Cobra generates lightning-fast autocompletions for Bash, Zsh, Fish, and PowerShell out of the box, complete with dynamic suggestions.

Shell completions · dynamic flag and argument suggestions

Intelligent typo suggestions prevent frustrating command-line mistakes.

Fourth, typo resistance. If a user types a wrong command, Cobra automatically computes Levenshtein distance and suggests the exact command they intended to run.

Smart error handling · Levenshtein distance typo suggestions

Cobra powers Kubernetes, Hugo, GitHub CLI, and the Go ecosystem.

With over 44,000 GitHub stars and an Apache license, Cobra is the foundation of modern infrastructure tooling. If you are building a CLI in Go, this is your starting point.

44.7k stars · Apache-2.0 · created by Steve Francia