Skip to content
Back to skills

Cobra

ASecurity

Use when building CLI applications with spf13/cobra — creating commands, defining flags, argument validation, lifecycle hooks, help/usage customization, shell completions, or Viper integration. Triggers on: "cobra", "cobra command", "cobra flag", "cobra subcommand", "cobra completion", "cobra help", "cobra usage", "cobra hook", "cobra viper", "AddCommand", "PersistentFlags", "LocalFlags", "MarkFlagRequired", "RunE", "PreRun", "PostRun", "PersistentPreRun", "ValidArgs", "ValidArgsFunction", "R...

  • 2,009 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 7, 2026
toolsshellbashgitapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add carapace-sh/carapace-bin --skill cobra --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cobra?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cobra
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/carapace-sh-cobra/badge)](https://www.skillsdirectory.com/skills/carapace-sh-cobra)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cobra
description: >
  Use when building CLI applications with spf13/cobra — creating commands, defining flags,
  argument validation, lifecycle hooks, help/usage customization, shell completions, or
  Viper integration. Triggers on: "cobra", "cobra command", "cobra flag", "cobra subcommand",
  "cobra completion", "cobra help", "cobra usage", "cobra hook", "cobra viper",
  "AddCommand", "PersistentFlags", "LocalFlags", "MarkFlagRequired", "RunE", "PreRun",
  "PostRun", "PersistentPreRun", "ValidArgs", "ValidArgsFunction", "RegisterFlagCompletionFunc",
  "ShellCompDirective", "ExactArgs", "NoArgs", "MinimumNArgs", "MatchAll",
  "MarkFlagsRequiredTogether", "MarkFlagsMutuallyExclusive", "cobra-cli",
  "cobra completion", "cobra active help", "cobra plugin".
user-invocable: true
---

# Cobra CLI Application Reference

Reference for building CLI applications with [cobra](https://github.com/spf13/cobra). Covers the public API, common patterns, and best practices.

## Sub-Resources

Load the reference that matches your task. When in doubt, load multiple references.

| Keywords | Reference |
|----------|----------|
| Command, AddCommand, subcommand, root command, project structure, command fields, Use, Short, Long, Example, Aliases, Deprecated, Hidden, GroupID, Run, RunE | [references/commands.md](references/commands.md) |
| flag, PersistentFlags, LocalFlags, required flag, flag group, required together, mutually exclusive, one required, repeated flag, count flag, string slice, TraverseChildren, MarkFlagRequired, MarkPersistentFlagRequired | [references/flags.md](references/flags.md) |
| argument, positional arg, Args, NoArgs, ArbitraryArgs, MinimumNArgs, MaximumNArgs, ExactArgs, RangeArgs, OnlyValidArgs, NoDuplicateArgs, MatchAll, ValidArgs, ArgAliases, custom validator | [references/arguments.md](references/arguments.md) |
| hook, lifecycle, PreRun, PostRun, PersistentPreRun, PersistentPostRun, PreRunE, PostRunE, EnableTraverseRunHooks, execution order, inherited hooks | [references/hooks.md](references/hooks.md) |
| help, usage, template, SetHelpFunc, SetHelpTemplate, SetUsageFunc, SetUsageTemplate, version, SetVersionTemplate, help command, command grouping, GroupID, SetHelpCommandGroupId, SetCompletionCommandGroupId, ErrPrefix | [references/help-usage.md](references/help-usage.md) |
| completion, shell completion, ValidArgs, ValidArgsFunction, CompletionFunc, RegisterFlagCompletionFunc, ShellCompDirective, NoFileCompletions, FixedCompletions, active help, AppendActiveHelp, GetActiveHelpConfig, CompletionOptions, completion command, bash, zsh, fish, powershell | [references/completions.md](references/completions.md) |
| viper, config, OnInitialize, BindPFlag, config file, 12-factor, initConfig, AutomaticEnv | [references/viper-integration.md](references/viper-integration.md) |

## Quick Guide

- **How do I create a command or subcommand?** → [references/commands.md](references/commands.md)
- **How do I add flags (persistent, local, required, groups)?** → [references/flags.md](references/flags.md)
- **How do I validate positional arguments?** → [references/arguments.md](references/arguments.md)
- **How do lifecycle hooks work (PreRun, PostRun, etc.)?** → [references/hooks.md](references/hooks.md)
- **How do I customize help/usage/version output?** → [references/help-usage.md](references/help-usage.md)
- **How do I add shell completions?** → [references/completions.md](references/completions.md)
- **How do I integrate with Viper for config?** → [references/viper-integration.md](references/viper-integration.md)
- **How do I make a kubectl-style plugin?** → [references/commands.md](references/commands.md)
- **How do I add Active Help messages during completion?** → [references/completions.md](references/completions.md)
- **How do I make flags required-together or mutually-exclusive?** → [references/flags.md](references/flags.md)

## Cross-Project References

- For cobra internals (Command struct fields, ExecuteC dispatch, Find vs Traverse, flag resolution, completion engine, shell script generation, global state), use the **cobra-dev** skill.
- For pflag internals (flag set implementation, POSIX compliance, non-POSIX modes), use the **carapace-dev** skill → `references/pflag.md`.

Files in this skill

  • SKILL.md4.2 KB
  • references/arguments.md3.5 KB
  • references/commands.md6.4 KB
  • references/completions.md7.5 KB
  • references/flags.md6.3 KB
  • references/help-usage.md4.5 KB
  • references/hooks.md4.9 KB
  • references/viper-integration.md4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.