hieudoanm/hieudoanm.github.io/click
Claude Code and agent skill by hieudoanm/hieudoanm.github.io
- community
Checking that the SKILL.md file is still in the repository.
Best practices for writing Python CLIs with Click — the composable command-line framework conventions. Use when writing, structuring, or reviewing Click tools — covers commands/groups, options/arguments, type handling, context, validation, error handling, and testing.
Install
npx vskill@latest install hieudoanm/hieudoanm.github.io/clickSKILL.md
The same SKILL.md was published earlier as hieudoanm/hieudoanm.github.io/click.
Click Best Practices
Click builds CLIs from decorators (@click.group, @click.command, @click.option) that wrap functions — the function signature becomes the CLI contract. Practical Click leans on small command functions with typed options/arguments, `@click.group` command clusters, `@click.option` with `type=` and `required`/`multiple`, and `ctx` (context) only for shared/stateful wiring. Click's grouping and ClickException flow keep the parsing layer thin and the tools testable via CliRunner.
1. Commands & Groups
- `@click.group()` for the root; `@click.command()` subcommands in the same module:
- `@click.group(chain=True)` for composable pipelines (a multi-step CLI where order matters) — only when the UX demands it.
- Group `invoke_without_command=True` for a root that does something with no subcommand; else the group is pure dispatch.
- `@cli.command()`-style decorator registration (decorate-and-register in one) keeps the command tree visible at the definition.
2. Options & Arguments
- Options = named flags, arguments = positional; typed via `type=`:
- `required=True` for the never-optional; `multiple=True` for repeatable; `count=True` for `-v -v`.
- `click.Path`/`click.File`/`click.Choice`/`click.IntRange` handle the common validation at the boundary:
- `show_default=True` on options so help states default values explicitly:
- Options parsed/env-variable fallback:
envvar="PORT"for secrets/config reads from the environment.
3. Types & Conversion
- Custom types via `click.ParamType` for the genuinely repeated shapes:
- `type=str` default; `ClickException` for clean error messages over raw raises — convert domain errors to
click.UsageError/ClickException.
4. Context & Shared State
- `@click.pass_context` to receive `ctx`; state shared via `ctx.obj` (a config object):
- `ctx.obj` for request-scoped wiring only — never business logic; subcommands read
ctx.objat the top:
- `click.get_current_context()` as the escape hatch — rare and named, not scattered.
5. Output & UX
- `click.echo` with `err=True` for diagnostics; `click.style`/`click.secho` for colored output where the platform supports it — the user interface consistency matters:
- `click.progressbar` for long tasks; `prompt`/`confirm` for interactive gates — keep the non-interactive path first (scriptable with flags, interactive as enhancement).
- Usage/help auto-generated; `epilog` for examples; every option documented with `help=`.
- Exit via `click.exceptions`/`return` from command functions — Click's CLI runner collects the exit code.
6. Testing
- `CliRunner` exercises the CLI end-to-end without subprocesses:
- Test the full group — the command tree is the CLI contract;
invokefrom the root. - Contract cases: missing argument, bad type/path, unknown option,
--helpoutput, and the error paths.
General Rules of Thumb
- Decorators declare the contract; function signatures are tested, not parsed twice.
- Options typed (`type=`/`Choice`/`Path`/custom); defaults in help.
- `ctx.obj` shared wiring only; domain logic stays in services.
- `click.echo` output with style; non-interactive path first.
- `CliRunner`-tested integration; happy + error paths covered.
Quick-Start Checklist
- [ ]
@click.group/@click.commandtree; one function per command - [ ] Typed options with
required/multiple/count;show_default=True - [ ]
click.Path/Choice/IntRange/customParamTypefor validation - [ ]
envvarfor config/secrets;ctx.objfor shared wiring only - [ ]
click.echooutput;click.style;epilog/help=documented - [ ]
CliRunner.invoketests incl. error paths and--help
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.skills/programming/languages/python/cli/click/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hieudoanm/hieudoanm.github.io/click)