Scaffold a new Cobra CLI command

VerifiedSafe

Scaffold a new Cobra CLI command following project patterns. Reads an existing command to match style, then registers it, handles errors, and verifies the build.

Sby Skills Guide Bot
DevelopmentIntermediate
8/8/2026
Claude Code
#cli#go#cobra#scaffolding#code-generation

Recommended for

Automated summary

Scaffolds a new Cobra CLI command that follows a specific Go project's existing conventions.

Strengths

  • Requires reading a comparable existing command first so the generated code matches current style
  • Spells out file placement, command registration, and which error-handling helpers to call
  • Bans project-forbidden patterns (`log.Fatal`, `os.Exit`, `logger.Log().FatalErr()`) inside `cmd/`
  • Includes a build check through the MCP `mcp__flow__execute` tool instead of a raw shell call

Limitations

  • Tightly coupled to one project layout (`cmd/internal/`, `pkg/context`, `internal/services`) and not portable as-is
  • Relies on internal packages (`errhandler`, `flags/`, `response/`) and project-specific MCP tooling
  • Covers only Go and Cobra, with no guidance for other CLI frameworks
When to use it

Use it when adding a command or subcommand to a Go/Cobra CLI that already follows these project conventions.

When not to use it

Avoid it on projects with a different directory layout or error-handling scheme, or for CLIs written in another language.

Security analysis

Safe
Quality score86/100

The skill only instructs scaffolding a Cobra command, reading existing files for style, and verifying the build via an MCP build/execute call or `go build`/`flow build` scoped Bash permissions. No destructive commands, credential handling, network exfiltration, obfuscation, or safety-disabling instructions are present, and the declared tool set is appropriately narrow for the task.

No concerns found

How this analysis is made

Examples

Add a simple verb command
/new-command validate — check that the workspace configuration is valid and report the first error
Add a noun/verb subcommand
/new-command vault rotate — rotate the encryption key for the current vault and print a confirmation
Add a command with structured output
/new-command workspace list — list all workspaces, respecting the --output text/json/yaml flag

name: new-command description: Scaffold a new Cobra CLI command following the project's patterns. disable-model-invocation: true argument-hint: "<verb> [noun] — what the command does" allowed-tools: mcp__flow__execute, mcp__flow__run_command, mcp__flow__list_executables, Bash(flow build:), Bash(go build:), Read

Scaffold a new Cobra CLI command for: $ARGUMENTS

Before writing any code, read a similar existing command to match the exact style:

  • Simple verb commands: cmd/internal/exec.go
  • Noun/verb subcommands: cmd/internal/workspace.go or cmd/internal/vault.go — each groups its subcommands in a single file rather than a directory

Then follow these patterns:

  1. File location: cmd/internal/<noun>.go. Only root.go lives directly in cmd/; every command handler is under cmd/internal/. Shared helpers go in cmd/internal/helpers.go, flags in cmd/internal/flags/, output shaping in cmd/internal/response/.
  2. Command registration: register on the parent command, or add to rootCmd in cmd/root.go
  3. Error handling:
    • Runtime errors → errhandler.HandleFatal(ctx, cmd, err)
    • Flag/arg misuse → errhandler.HandleUsage(ctx, cmd, "message", args...)
    • Never use log.Fatal, os.Exit, or logger.Log().FatalErr() in cmd/
  4. Context: resolve workspace context via pkg/context before delegating to internal/services
  5. Output: respect --output flag (text/json/yaml) for structured responses

After scaffolding, verify it builds — prefer mcp__flow__execute with ref build binary and argument ./bin/flow over a raw shell call.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/scaffold-a-new-cobra-cli-command-msjwk4qf/download' --output '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md.part' && mv '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md.part' '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): mcp__flow__execute, mcp__flow__run_command, mcp__flow__list_executables, Bash(flow build:*), Bash(go build:*), Read

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md' && test -s '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/new-command' && cp -R '.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf' '.claude/skills/new-command'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf'

openskills read 'scaffold-a-new-cobra-cli-command-msjwk4qf'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/scaffold-a-new-cobra-cli-command-msjwk4qf/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills