mrkeyoor.com_
Mon 28 Sept 02:35 UTC
Dev Toolsevaluationupdated 26 Aug 2026

cobra review

Cobra is a Go library for building command-line programs with nested commands, flags, help text, suggestions, documentation, and shell completion. It handles the interface around a CLI so application code can focus on what each command does.

+34stars / 7d
Verdict

Our Cobra checkout built in 15 seconds and all 2 measured test packages passed in 9 seconds after installing only 7 packages. It remains the safe default for a Go CLI with nested commands, generated help, and several completion targets. Use a smaller struct-based parser or the standard library when the command tree is shallow, because Cobra's flexibility becomes extra code in a one-command tool.

We ran it

Lab card: what happened when we ran cobraScreenshot of cobra (cobra.dev)
Install✓ · 4s7 packages
Build✓ · 15s
Tests✓ · 9s2 passed · 0 failed of 2 (go test)
Repo66 files~16,801 lines of source · 0.7 MB · 2 CI workflows

Answers from our run

Does cobra build from source?

Dependencies installed in 4 seconds (7 packages), and the build succeeded in 15 seconds. We cloned commit adbc881 into a clean Debian container with 3 CPUs and no project-specific setup.

Do cobra's tests pass?

Yes: 2 of 2 passed when we ran the project's own test command (go test). Some failures need services or credentials a bare container does not have.

Who should not use cobra?

Tiny programs with one action and a handful of flags: Go's standard flag package may be easier to read and maintain.

What are the alternatives to cobra?

urfave/cli, Kong, go-arg. Our Cobra checkout built in 15 seconds and all 2 measured test packages passed in 9 seconds after installing only 7 packages.

Setup5/54-second install, 7 packages, and a direct Go module import
Docs5/5Focused README plus a detailed guide and API reference
Community5/5Current completion fixes and active issue discussion
Maturity5/5Established API, versioned releases, and broad production use

Discussed on

  1. hnCobra v1.5.0 Is Released4 points
  2. hnCobra: A Commander for Modern Go CLI Interactions3 points
  3. hnA modern CLI Commander for Go3 points

Who it’s for

Go developers building a CLI with several commands and shared flags.
Teams that need generated Bash, Zsh, Fish, and PowerShell completion.
Maintainers who want help text, aliases, man pages, and command docs from one tree.
Projects that value an established API already used by major Go command-line tools.

Who it’s NOT for

Tiny programs with one action and a handful of flags: Go's standard flag package may be easier to read and maintain.
Developers expecting configuration-file and environment-variable binding inside Cobra itself: the README describes Viper integration as optional.
Teams that need flawless shell completion without testing each target shell: current issues and pull requests cover Bash escaping, required flags, and PowerShell runtime errors.
Applications that frequently rebuild or reparent the command tree at runtime: a current fix addresses stale command-path padding after subtree changes.
Users who want a generator bundled into the library repository: scaffolding lives in the separate spf13/cobra-cli project.

Setup reality

Our sandbox installed 7 Go packages in 4 seconds at commit adbc881. The build succeeded in 15 seconds, and tests finished in 9 seconds with 2 passed and 0 failed out of 2.

The library itself needs only a Go module import. Optional scaffolding requires the separate cobra-cli binary, while configuration binding usually adds Viper. Generated completions and man pages need release steps appropriate to each target platform.

The checkout was 0.7 MB and had 2 CI workflows, with no Dockerfile or tests directory. The small measured dependency count supports an easy start, but completion scripts should still be tested in Bash, Zsh, Fish, and PowerShell if the product promises all four.

Cobra models a CLI as a tree of commands

Cobra's central type is Command. A command has a name, help text, argument rules, flags, an action, and optional child commands. That structure maps naturally to interfaces such as app server start or app config set. Persistent flags can flow down the tree, while local flags stay attached to one command. Aliases and suggestions help users recover when names change or a command is mistyped.

The library also generates the parts teams often neglect: usage text, help flags, shell completion, man pages, and Markdown documentation. Bash, Zsh, Fish, and PowerShell are supported. Projects can customize the output when the defaults do not fit. The result is a single command definition serving runtime parsing and release documentation instead of maintaining each representation separately.

The library and generator are separate choices

Adding Cobra to a Go module requires go get github.com/spf13/cobra. Developers can create the root command and children by hand, which is often clearer in an existing application. The separate cobra-cli program generates a new application or command file. That tool is convenient for a blank project, but it is not required at runtime and lives in its own repository.

This separation keeps scaffolding out of deployed binaries. It can confuse first-time users who install Cobra and then expect a cobra executable, so the README points to both installation paths. Teams should decide whether generated file layout fits their conventions before committing it. A small hand-written command tree can be easier to navigate than boilerplate spread across many files.

What happened when we ran it

Our sandbox tested commit adbc881 with Go 1.24 on Debian. Dependency installation finished in 4 seconds and added 7 packages. The build succeeded in 15 seconds. Tests completed in 9 seconds: Go reported 2 passed and 0 failed out of 2.

The checkout contained 66 files, about 16,801 lines of source, and occupied 0.7 MB. Two CI workflow files were present, with no Dockerfile and no tests directory. Go tests can live beside package code, so the missing directory is not a warning by itself. The small source and dependency footprint matches Cobra's role as an embedded library rather than a service.

Our run gives a clean baseline for the measured revision. It does not verify every generated completion script in an interactive shell. Completion behavior depends on the target shell, escaping, current arguments, and how an application defines valid values. Projects shipping completion should add their own fixtures around the actual command tree.

Completion is valuable and still the busiest edge

Current issue activity concentrates on the places where shells disagree. August 2026 work addressed PowerShell exceptions for empty or single-line output, Bash handling of required flags supplied in two-word form, escaping in partial completions, and suggesting flags after parse errors. These are narrow bugs, but completion is user-facing and hard to test by eye across four shells.

Cobra provides the generator and hooks; application authors still own semantic suggestions. A command that queries a network or reads a large database during completion can make every tab press slow. Keep completion functions bounded, handle missing credentials quietly, and test empty, one-item, and special-character results. Recent PowerShell fixes show why those small cases belong in a release checklist.

The same caution applies to command-tree mutation. A recent pull request recomputed cached path lengths when a subtree was reparented, while another avoided claiming -h when an application already used that shorthand. Most CLIs build their tree once at startup and will never hit the first case. Libraries that assemble plugins dynamically should exercise it.

Viper is optional, and that boundary is useful

Cobra parses commands and flags. Viper can bind configuration files and environment variables, but the README labels the integration optional. Keeping those concerns separate avoids forcing a configuration system on every CLI. A program with a few flags can read its own environment and remain simpler; a service-style CLI can add Viper when precedence across defaults, files, variables, and flags is worth the extra rules.

Flag parsing itself comes from spf13/pflag, which extends Go's familiar flag interface with POSIX-style short and long options. This gives users expected forms such as -p and --port. Persistent flags are powerful, though deep inheritance can make help output and precedence harder to reason about. Prefer local flags unless a setting genuinely applies to every child.

Maintenance remains active after the latest release

Version 1.10.2 was released on 2025-12-04. The repository's last push was 2026-07-11, while issues and pull requests continued through August. GitHub listed 434 open issues and pull requests combined. That count includes feature work, questions, documentation, and proposed fixes; it is not 434 confirmed defects.

The Apache 2.0 license suits commercial and open-source tools. Documentation is split sensibly between the short README, the Cobra website, the user guide, and Go's API reference. Existing users also benefit from command aliases, which can keep old names working during a migration.

Cobra is the right default once a Go program has a real command hierarchy or promises completion on several shells. Kong and go-arg offer a more compact struct-first style, while urfave/cli has a different declarative API. For one command with five flags, the standard library remains a respectable answer. Complexity should follow the interface users actually need.

Alternatives

ProjectWhat it isPick it when
urfave/cli gh↗A Go package for building command-line apps with commands, flags, and help.pick this instead when you prefer its declarative app structure and need less of Cobra's command-tree machinery.
KongA Go CLI parser that derives commands and flags from typed structs.pick this instead when a struct-first API and type-driven parsing are more appealing than manually assembling commands.
go-argA compact argument parser that maps command-line input into Go structs.pick this instead when the program is small and concise struct tags cover the interface.

What people are saying

  1. [github-trending] spf13/cobra

Sources

  1. Cobra README
  2. Cobra documentation
  3. Cobra v1.10.2 release
  4. Cobra issues and pull requests

More dev tools reviews

fyne · agent-manager · navi · exodium · Submarine · Madeira · the whole board →