Back to Skills

golang-cli

Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golan

1,807stars118forksUpdated 5/24/2026

Security Assessment

Safe(100/100)
Security Score100/100

About golang-cli

The golang-cli skill provides structured guidance for building, extending, and reviewing command-line applications in Go. It focuses on creating tools that behave like first-class Unix utilities: composable, predictable, and suitable for automation. The skill is designed for AI coding agents working in Go projects, helping them apply consistent patterns when designing CLI architectures, handling command hierarchies, and managing application configuration.

This skill emphasizes a standard Go CLI stack built around Cobra for command and flag orchestration and Viper for configuration management. It supports key CLI concerns such as argument parsing, flag binding, layered configuration (files, environment variables, and flags), version embedding via build-time flags, structured exit code handling, and separation of stdout and stderr for reliable scripting. It also includes best practices for signal handling, shell completion support, input/output discipline, and testing strategies for CLI behavior. For simpler tools, it allows fallback to the standard library flag package when subcommands are unnecessary.

The skill is intended for developers and AI agents building production-grade Go CLIs, such as developer tools, DevOps utilities, or internal automation commands. It is especially useful when working with existing Cobra/Viper-based projects or when auditing CLI correctness, ensuring proper usage of SilenceUsage/SilenceErrors, consistent command structure, and reliable configuration initialization. It helps maintain scalable CLI codebases that integrate cleanly into shell environments and automation pipelines.

FAQ

When should I use Cobra and Viper instead of the standard library flag package?

Use Cobra and Viper when building multi-command CLI applications that require subcommands, layered configuration, or environment-variable support. For simple single-purpose tools with minimal flags and no subcommands, the standard library flag package is sufficient.

What is the recommended project structure for a Go CLI using this skill?

The CLI should place commands under cmd/myapp/, with one file per command. The main.go file should remain minimal and only call Execute(). The root command handles initialization, while each subcommand is defined in its own file.

What are key best practices enforced by this skill?

It enforces using SilenceUsage and SilenceErrors in the root command, initializing configuration via PersistentPreRunE, separating stdout and stderr properly, and embedding version information using build flags. It also encourages structured command organization and consistent flag-to-configuration binding.

What types of users is this skill designed for?

It is designed for Go developers and AI coding agents building production-grade CLI tools, especially those working with automation, DevOps utilities, or Unix-style command-line applications.

All Files

14 files
assets/examples/config.go1.7 KB
View
SKILL.md9.7 KB
View
assets/examples/flags.go1.3 KB
View
assets/examples/args.go1.0 KB
View
assets/examples/main.go0.1 KB
View
assets/examples/cli_test.go1.2 KB
View
assets/examples/completion.go1.6 KB
View
assets/examples/exit_codes.go0.5 KB
View
assets/examples/signal.go0.8 KB
View
assets/examples/output.go1.7 KB
View
assets/examples/root.go1.8 KB
View
assets/examples/serve.go0.7 KB
View
assets/examples/version.go0.9 KB
View
evals/evals.json16.0 KB
View

Install golang-cli

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill