关于
This skill provides patterns for designing CLI output with features like color, Unicode icons, and multiple verbosity levels (human, JSON, quiet, verbose). It covers reporter architecture, status indicators, and cross-terminal compatibility. Use it when building a new CLI tool, adding narrative output, or standardizing output across commands.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/design-cli-output在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Design CLI Output
Consistent, multi-level terminal output for a command-line tool.
When Use
- Build new reporter module for CLI tool
- Add warm or narrative output alongside transactional output
- Standardize output format across many commands
- Design JSON machine output parallel to human output
- Pick colors, glyphs, verbosity levels for new terminal tool
Inputs
- Required: CLI tool name + primary audience (devs, operators, end users)
- Required: Commands that need output formatting
- Optional: Ceremony/narrative output variant wanted?
- Optional: Brand constraints (color palette, tone)
Steps
Step 1: Set Color Palette
Use chalk. Make named palette object.
Standard palette (transactional output):
let chalk;
try { chalk = (await import('chalk')).default; }
catch { chalk = new Proxy({}, { get: () => (s) => s }); }
// Status colors
const ok = chalk.green; // success
const fail = chalk.red; // errors
const warn = chalk.yellow; // warnings
const info = chalk.cyan; // identifiers, names
const dim = chalk.dim; // secondary info, paths
const bold = chalk.bold; // headers
Warm palette (ceremony/narrative output):
const C = {
flame: chalk.hex('#FF6B35'), // active elements, fire
amber: chalk.hex('#FFB347'), // arriving items, warm highlights
spark: chalk.hex('#FFF4E0'), // individual items (sparks/skills)
ember: chalk.hex('#8B4513'), // cold/dormant states
warm: chalk.hex('#D4A574'), // neutral warm text
dim: chalk.dim, // background, secondary
fail: chalk.red, // errors stay red (honest)
};
Palette rules:
- Always provide no-color fallback (Proxy pattern above)
- Use hex colors for custom palettes (
chalk.hex('#FF6B35')) - Keep fail/error red no matter the theme
- Name palette by semantic role, not visual
Got: Palette object. Named entries. No-color fallback.
If fail: Chalk unavailable (piped, CI)? Proxy fallback returns strings unchanged. Test: NO_COLOR=1 env var.
Step 2: Pick Status Indicators
Unicode glyphs or ASCII chars for status.
ASCII (max compat):
+ created/installed (green)
- removed/deleted (red)
= skipped/unchanged (dim)
! error/warning (red)
Unicode (richer, needs UTF-8 terminal):
✦ item/skill/practice (spark)
◉ active/burning state
◎ cooling/embers state
○ cold/dormant state
◌ available/not installed
✗ failed item
✓ success (use sparingly — not all terminals render it well)
Rules:
- ASCII for CI or piped contexts
- Unicode for interactive terminal users
- Offer both via
--asciiflag orNO_COLORdetection - Test glyphs in: macOS Terminal, Windows Terminal, VS Code terminal, SSH
Got: Glyph set communicates status at a glance. No color needed.
If fail: Glyph renders as ? or box? Swap for ASCII. +/-/=/! works everywhere.
Step 3: Design Verbosity Levels
Every command supports 4 output levels:
| Level | Flag | Audience | Content |
|---|---|---|---|
| Default | (none) | Human at terminal | Formatted, colored, informative |
| Verbose | --verbose or --ceremonial | Human wanting detail | Per-item breakdown, arrival sequences |
| Quiet | --quiet | Scripts, CI | Minimal lines, status icons, no decoration |
| JSON | --json | Machine consumers | Structured, parseable, complete |
Pattern:
function output(data, options) {
if (options.json) {
console.log(JSON.stringify(data, null, 2));
return;
}
if (options.quiet) {
for (const item of data.items) {
const icon = item.ok ? '+' : '!';
console.log(`${icon} ${item.id}`);
}
return;
}
// Default (or verbose) human output
printFormatted(data, { verbose: options.verbose });
}
JSON rules:
- Always valid JSON (no mixing with human text)
- Include all data human output shows, plus machine fields
- Consistent key names across commands
- Exit 0 = success, 1 = err (any output mode)
Got: Four clear output levels. Consistent across commands.
If fail: Verbose too noisy? Make opt-in (--ceremonial) not graduated level.
Step 4: Set Voice Rules
Tone + style all output follows. Stops inconsistency.
Example voice rules (campfire reporter):
- Present tense, active voice: "mystic arrives" not "mystic has been installed"
- No exclamation marks: Quiet confidence. Tool doesn't shout.
- Metaphor replaces jargon: "practices" not "dependencies" (ceremony mode only)
- Failures honest, not catastrophic: "A spark was lost" not "ERROR: installation failed with exit code 1"
- Closing line shows state: Every op ends with status summary
- No emoji: Unicode glyphs carry visual weight without decoration
- Every word carries info: Word adds no understanding? Remove.
Voice rules for standard (non-ceremony) output:
- Concise, factual lines
- Status icon + item ID + context
- Summary line with counts
- Errors suggest fix
Got: Written set of 3-7 voice rules. Output funcs must follow.
If fail: Rules feel arbitrary? Test: write output with + without each rule. Removing rule doesn't change quality? Rule not needed.
Step 5: Build Reporter Functions
Organize output into reporter module. Focused functions.
// reporter.js — standard output
export function printResults(results) { ... }
export function printItemTable(items) { ... }
export function printDetections(detections) { ... }
export function printAudit(auditResults) { ... }
export function printDryRun() { ... }
export function warn(msg) { ... }
export function error(msg) { ... }
export { chalk };
Each function same structure:
- Handle empty/null input
- Compute layout (col widths, padding)
- Output with palette colors
- Summary line at bottom
Ceremony output? Separate module:
// campfire-reporter.js — warm narrative output
export function printArrival({ teamId, agents, results, ceremonial }) { ... }
export function printScatter({ teamId, agents, results }) { ... }
export function printTend(fires) { ... }
export function printCampfireList({ teams, state, reg }) { ... }
export function printFireSummary({ team, fireData, reg }) { ... }
export function printJson(data) { ... }
Got: Reporter functions independently usable. Each handles own formatting, no caller state dep.
If fail: Function > ~50 lines? Extract helpers. Reporter must be reviewable alone.
Step 6: Test Output Across Environments
Check output renders right in different contexts:
# With colors (interactive terminal)
node cli/index.js list --domains
# Without colors (piped)
node cli/index.js list --domains | cat
# With NO_COLOR environment variable
NO_COLOR=1 node cli/index.js list --domains
# JSON mode (parseable)
node cli/index.js campfire --json | jq .
# In CI (typically no TTY)
CI=true node cli/index.js audit
Check:
- Colors display right in interactive mode
- No ANSI escape codes leak into piped/redirected output
- JSON valid (pipe to
jq .) - Unicode glyphs render in target terminals
- Column alignment holds with varying content widths
Got: Output correct in all 5 contexts.
If fail: ANSI codes leak? Ensure chalk respects NO_COLOR. Unicode breaks? Provide ASCII fallback mode.
Checks
- Color palette has no-color fallback
- Status indicators work in both color + no-color modes
- All 4 verbosity levels produce useful output
- JSON output valid, parseable by
jq - Voice rules documented + followed
- Reporter funcs handle empty/null input
- Output tested in: terminal, piped, NO_COLOR, CI
Pitfalls
- Mixing human text with JSON: In
--jsonmode, only valid JSON. One stray line ("DRY RUN") breaks JSON parsers. If must show both, separate clearly or suppress human text in JSON mode. - Hardcoded column widths: Content length varies. Use
Math.max(...items.map(i => i.id.length))for dynamic padding. - Color without meaning: Color only way to tell success from failure? Colorblind users + piped output lose info. Always pair color with text indicator (
+,OK,ERR). - Ceremony in wrong context: Warm narrative output fits interactive terminal. In CI, scripts,
--quietmode = noise. Gate ceremony behind explicit flags. - Forgetting summary line: Users scan last line first. Every op ends with one-line summary (counts of success/failure/skipped).
See Also
scaffold-cli-command— commands that use this outputtest-cli-application— testing output matches expectationsbuild-cli-plugin— plugins report results through this output system
GitHub 仓库
常见问题
什么是 design-cli-output Skill?
design-cli-output 是一个 Claude Skill,作者为 pjt222。Skill 将 Claude 按需加载的说明和资源打包,让 Claude 无需额外提示即可执行与 design-cli-output 相关的任务。
如何安装 design-cli-output?
使用本页的安装命令:将 design-cli-output 作为插件添加到 Claude Code,或将其仓库克隆到 skills 目录,然后重启 Claude 以加载该 Skill。
design-cli-output 属于哪个分类?
design-cli-output 属于元分类。
design-cli-output 可以免费使用吗?
可以。design-cli-output 已收录在 AIMCP,可免费安装。
相关推荐技能
Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
