This is a comprehensive reference for building production-grade Go CLIs with Cobra and Viper. It covers the full lifecycle: bootstrapping new tools with proper project structure, extending existing ones with subcommands and flags, and reviewing for common mistakes like leaking usage text on errors or mixing stdout and stderr. The exit code table, signal handling with context propagation, and the flags-to-Viper binding patterns are especially solid. Worth invoking whenever you're wiring up command trees, handling configuration layering, or need to remember whether `SilenceUsage` should be true (it should). Built by samber, who maintains a bunch of Go utilities, so the opinions here come from real CLI work.

skills.sh installs
41.1K
GitHub stars
3.8K
last updated
Aug 21, 2026

Install

$ npx -y skills add samber/cc-skills-golang --skill golang-cli --agent claude-code

Installs into .claude/skills of the current project.

Files

Persona: You are a Go CLI engineer. You build tools that feel native to the Unix shell — composable, scriptable, and predictable under automation.

Modes:

  • Build — creating a new CLI from scratch: follow the project structure, root command setup, flag binding, and version embedding sections sequentially.
  • Extend — adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.
  • Review — auditing an existing CLI for correctness: check the Common Mistakes table, verify SilenceUsage/SilenceErrors, flag-to-Viper binding, exit codes, and stdout/stderr discipline.

Go CLI Best Practices

Use Cobra + Viper as the default stack for Go CLI applications. Cobra provides the command/subcommand/flag structure and Viper handles configuration from files, environment variables, and flags with automatic layering. This combination powers kubectl, docker, gh, hugo, and most production Go CLIs.

When using Cobra or Viper, refer to the library's official documentation and code examples for current API signatures.

Sponsors

Details

Repository
github.com/samber/cc-skills-golang
Categories
Testing & QA, AI & Agent Building, Release Management, Go, CLI & Terminal
First seen
Apr 16, 2026

More from samber/cc-skills-golang

All 47
1convex avatarconvex-migrate-rehearseconvex/agent-skillsRehearse a live-app schema change + backfill on a snapshot-seeded preview deployment, verify, then promote the proven change to prod with the snapshot as rollba41.1Kskills.sh installs
2samber avatargolang-grpcsamber/cc-skills-golangProvides gRPC usage guidelines, protobuf organization, and production-ready patterns for Golang microservices. Use when implementing, reviewing, or debugging gR40.7Kskills.sh installs
3limrun-inc avatarlimrun-android-emulatorlimrun-inc/skillsDrive an app running on a Limrun cloud Android emulator: install an APK, launch and terminate apps with crash reports, tap, type, read the UI element tree, scre40.2Kskills.sh installs
4flutter avatarflutter-add-widget-previewflutter/agent-pluginsAdds interactive widget previews to the project using the previews.dart system. Use when creating new UI components or updating existing screens to ensure consi38.7Kskills.sh installs
5samber avatargolang-spf13-vipersamber/cc-skills-golangGolang configuration library using spf13/viper — layered precedence (flag > env > file > KV > default), BindPFlag/BindPFlags, SetEnvPrefix + SetEnvKeyReplacer +38.3Kskills.sh installs
6samber avatargolang-how-tosamber/cc-skills-golangGolang skills orchestrator — always active on any Golang coding, review, debug, or setup task. Reads the task context and loads the most relevant skills from sa37.9Kskills.sh installs