RTK Output Design
Use this skill to make CLI, skill, hook, and script output useful to an agent
without flooding its context. Treat output as a contract: preserve the signal
needed for the next action, make compression explicit, and keep raw detail
available on demand.
Core Contract
Design every command around this shape:
status: success | partial | failure
summary: one sentence with the important result
stats: counts, durations, paths, bytes, token estimates, or changed totals
items: only the highest-value errors, warnings, changed files, matches, or rows
omitted: what was hidden and why, with counts when possible
next_actions: concrete commands or fixes when the result is not done
provenance: command, mode, input scope, and source paths when relevant
For human output, render this shape as compact sections. For automation, expose
it as stable JSON.
Output Modes
Provide these modes when the tool has non-trivial output:
| Mode |
Purpose |
Rules |
| Default |
Agent-readable terminal output |
Compact summary first, failures before successes, bounded examples. |
--json |
Script and agent automation |
Print one valid JSON object to stdout. Put non-JSON diagnostics on stderr. |
--verbose / -v |
Debugging |
Add raw command, matched rules, and timing. Keep the default concise. |
--raw |
Escape hatch |
Show unfiltered upstream output for audits, parser bugs, or human inspection. |
--dry-run |
Preview changes |
Show planned writes or hook edits without mutating files. |
Preserve upstream exit codes unless the wrapper itself fails. If filtering fails,
prefer raw output plus a short filter warning over hiding command results.
Filtering Strategy
Choose the cheapest strategy that preserves the next useful action:
| Input Shape |
Strategy |
Keep |
| Successful build/test/install logs |
Progress filtering |
Final status, duration, warnings, changed artifacts. |
| Failed build/test/lint runs |
Failure focus |
Error blocks, failing test names, stack heads, file:line, repro command. |
| Repeated log lines |
Deduplication |
Unique message, count, first/last timestamp or location. |
| Search output |
Group by pattern |
Match counts by file or rule, then representative matches. |
| Large diffs or status |
Stats extraction |
File counts, additions/deletions, changed paths, conflict state. |
| Directory listings |
Tree compression |
Top-level structure, important files, counts for hidden children. |
| JSON or structured text |
Structure-only or summarized JSON |
Keys, types, counts, selected values needed for the task. |
| Language source dumps |
Code filtering |
Signatures, exports, imports, failing region, omitted body counts. |
| Streamed test output |
State-machine parsing |
Suite lifecycle, failures, skipped count, slow tests. |
| NDJSON or event streams |
Streaming aggregation |
Counts by event type plus the most actionable events. |
Never compress away:
- Non-zero status, panic, exception, traceback, failed assertion, or stderr.
- File paths, line numbers, command names, versions, config locations, or IDs
needed for the next command.
- Security, permission, data-loss, migration, or destructive-action warnings.
- The fact that output was omitted.
Default Text Template
Use this layout for CLI output that an agent will read:
<STATUS>: <one-sentence summary>
Stats:
- <count or metric>
- <duration or scope>
Findings:
- <file:line or id> <message>
- <group> <count> occurrences, example: <short sample>
Omitted:
- <count> low-signal lines hidden; use --raw or --verbose for details
Next:
- <single best next command or action>
Omit empty sections. Keep the default output small enough to scan in one screen;
for broad commands, prefer the top 10 to 20 actionable items plus counts.
JSON Schema
For --json, use one object with stable keys:
{
"status": "success",
"summary": "3 files changed, no failures",
"command": {
"argv": ["tool", "check"],
"cwd": "/repo",
"exit_code": 0,
"duration_ms": 1234
},
"stats": {
"files": 3,
"warnings": 0,
"errors": 0,
"omitted_lines": 248
},
"items": [
{
"kind": "change",
"path": "src/main.rs",
"line": 42,
"message": "updated parser"
}
],
"omitted": [
{
"kind": "progress",
"count": 248,
"reason": "progress and success lines hidden"
}
],
"next_actions": ["run cargo test"],
"meta": {
"schema": "rtk-output-design.v1",
"raw_available": true
}
}
Rules:
- Keep keys stable across versions. Add optional keys instead of renaming.
- Use arrays for repeated data even when there is one item.
- Use
null only when absence is meaningful; otherwise omit optional keys.
- Keep raw multiline blobs out of JSON unless explicitly requested.
- Include
schema when downstream agents or tests may depend on the shape.
Skill And Hook Output
For skills, prompts, and hooks:
- Start with the decision or result, then evidence. Do not make agents infer the
status from a long transcript.
- Include the minimum procedure needed to reproduce or continue.
- Put large references behind paths or commands the agent can open only when
needed.
- For generated plans or reports, label each item with status, owner/scope, and
verification evidence.
- For hook rewrites or suggestions, show the original command, rewritten
command, and reason in one compact block.
Example hook message:
RTK: rewrite suggested
original: pytest -q
rewrite: rtk pytest -q
reason: filter passing tests; preserve failures and exit code
CLI Development Checklist
Before shipping a CLI, skill helper, or script:
- Define the default text output and
--json schema before implementation.
- Decide which filtering strategy applies to each verbose command path.
- Preserve exit codes and stderr semantics.
- Add
--raw or an equivalent debug path for compressed output.
- Make omissions visible with counts and reasons.
- Sort findings by actionability: failures, unsafe warnings, changed paths,
grouped summaries, then success details.
- Bound examples and list lengths. Include totals so truncation is honest.
- Test success, partial, failure, no-match, huge-output, and parser-error
cases.
- Snapshot JSON shape or validate it with schema assertions.
- Verify the output from an agent perspective: can the next command be chosen
without asking for the raw transcript?
Anti-Patterns
- Printing banners, progress bars, spinners, dependency trees, or full passing
test logs by default.
- Hiding non-zero exits behind a friendly summary.
- Returning prose-only output for data another script must parse.
- Emitting invalid JSON with comments, log prefixes, or trailing text.
- Showing raw files or diffs when counts plus changed paths would answer the
question.
- Compressing output without saying what was omitted.
- Creating a skill that explains usage at length but does not define the output
contract agents should follow.
Acceptance Test
A tool follows this guide when an agent can answer these questions from default
output alone:
- Did it succeed, partially succeed, or fail?
- What changed or what was found?
- What exact file, line, command, or ID matters next?
- What was hidden, and how can raw detail be recovered?
- What command or edit should happen next?
If any answer requires scanning raw logs, redesign the output or add a focused
summary path.
1---2name: rtk-output-design3description: Design compact, failure-first CLI/skill/hook output for agents. Use when implementing or reviewing agent-facing output.4---56# RTK Output Design78Use this skill to make CLI, skill, hook, and script output useful to an agent9without flooding its context. Treat output as a contract: preserve the signal10needed for the next action, make compression explicit, and keep raw detail11available on demand.1213## Core Contract1415Design every command around this shape:1617```yaml18status: success | partial | failure19summary: one sentence with the important result20stats: counts, durations, paths, bytes, token estimates, or changed totals21items: only the highest-value errors, warnings, changed files, matches, or rows22omitted: what was hidden and why, with counts when possible23next_actions: concrete commands or fixes when the result is not done24provenance: command, mode, input scope, and source paths when relevant25```2627For human output, render this shape as compact sections. For automation, expose28it as stable JSON.2930## Output Modes3132Provide these modes when the tool has non-trivial output:3334| Mode | Purpose | Rules |35| --- | --- | --- |36| Default | Agent-readable terminal output | Compact summary first, failures before successes, bounded examples. |37| `--json` | Script and agent automation | Print one valid JSON object to stdout. Put non-JSON diagnostics on stderr. |38| `--verbose` / `-v` | Debugging | Add raw command, matched rules, and timing. Keep the default concise. |39| `--raw` | Escape hatch | Show unfiltered upstream output for audits, parser bugs, or human inspection. |40| `--dry-run` | Preview changes | Show planned writes or hook edits without mutating files. |4142Preserve upstream exit codes unless the wrapper itself fails. If filtering fails,43prefer raw output plus a short filter warning over hiding command results.4445## Filtering Strategy4647Choose the cheapest strategy that preserves the next useful action:4849| Input Shape | Strategy | Keep |50| --- | --- | --- |51| Successful build/test/install logs | Progress filtering | Final status, duration, warnings, changed artifacts. |52| Failed build/test/lint runs | Failure focus | Error blocks, failing test names, stack heads, file:line, repro command. |53| Repeated log lines | Deduplication | Unique message, count, first/last timestamp or location. |54| Search output | Group by pattern | Match counts by file or rule, then representative matches. |55| Large diffs or status | Stats extraction | File counts, additions/deletions, changed paths, conflict state. |56| Directory listings | Tree compression | Top-level structure, important files, counts for hidden children. |57| JSON or structured text | Structure-only or summarized JSON | Keys, types, counts, selected values needed for the task. |58| Language source dumps | Code filtering | Signatures, exports, imports, failing region, omitted body counts. |59| Streamed test output | State-machine parsing | Suite lifecycle, failures, skipped count, slow tests. |60| NDJSON or event streams | Streaming aggregation | Counts by event type plus the most actionable events. |6162Never compress away:6364- Non-zero status, panic, exception, traceback, failed assertion, or stderr.65- File paths, line numbers, command names, versions, config locations, or IDs66 needed for the next command.67- Security, permission, data-loss, migration, or destructive-action warnings.68- The fact that output was omitted.6970## Default Text Template7172Use this layout for CLI output that an agent will read:7374```text75<STATUS>: <one-sentence summary>7677Stats:78- <count or metric>79- <duration or scope>8081Findings:82- <file:line or id> <message>83- <group> <count> occurrences, example: <short sample>8485Omitted:86- <count> low-signal lines hidden; use --raw or --verbose for details8788Next:89- <single best next command or action>90```9192Omit empty sections. Keep the default output small enough to scan in one screen;93for broad commands, prefer the top 10 to 20 actionable items plus counts.9495## JSON Schema9697For `--json`, use one object with stable keys:9899```json100{101 "status": "success",102 "summary": "3 files changed, no failures",103 "command": {104 "argv": ["tool", "check"],105 "cwd": "/repo",106 "exit_code": 0,107 "duration_ms": 1234108 },109 "stats": {110 "files": 3,111 "warnings": 0,112 "errors": 0,113 "omitted_lines": 248114 },115 "items": [116 {117 "kind": "change",118 "path": "src/main.rs",119 "line": 42,120 "message": "updated parser"121 }122 ],123 "omitted": [124 {125 "kind": "progress",126 "count": 248,127 "reason": "progress and success lines hidden"128 }129 ],130 "next_actions": ["run cargo test"],131 "meta": {132 "schema": "rtk-output-design.v1",133 "raw_available": true134 }135}136```137138Rules:139140- Keep keys stable across versions. Add optional keys instead of renaming.141- Use arrays for repeated data even when there is one item.142- Use `null` only when absence is meaningful; otherwise omit optional keys.143- Keep raw multiline blobs out of JSON unless explicitly requested.144- Include `schema` when downstream agents or tests may depend on the shape.145146## Skill And Hook Output147148For skills, prompts, and hooks:149150- Start with the decision or result, then evidence. Do not make agents infer the151 status from a long transcript.152- Include the minimum procedure needed to reproduce or continue.153- Put large references behind paths or commands the agent can open only when154 needed.155- For generated plans or reports, label each item with status, owner/scope, and156 verification evidence.157- For hook rewrites or suggestions, show the original command, rewritten158 command, and reason in one compact block.159160Example hook message:161162```text163RTK: rewrite suggested164original: pytest -q165rewrite: rtk pytest -q166reason: filter passing tests; preserve failures and exit code167```168169## CLI Development Checklist170171Before shipping a CLI, skill helper, or script:1721731. Define the default text output and `--json` schema before implementation.1742. Decide which filtering strategy applies to each verbose command path.1753. Preserve exit codes and stderr semantics.1764. Add `--raw` or an equivalent debug path for compressed output.1775. Make omissions visible with counts and reasons.1786. Sort findings by actionability: failures, unsafe warnings, changed paths,179 grouped summaries, then success details.1807. Bound examples and list lengths. Include totals so truncation is honest.1818. Test success, partial, failure, no-match, huge-output, and parser-error182 cases.1839. Snapshot JSON shape or validate it with schema assertions.18410. Verify the output from an agent perspective: can the next command be chosen185 without asking for the raw transcript?186187## Anti-Patterns188189- Printing banners, progress bars, spinners, dependency trees, or full passing190 test logs by default.191- Hiding non-zero exits behind a friendly summary.192- Returning prose-only output for data another script must parse.193- Emitting invalid JSON with comments, log prefixes, or trailing text.194- Showing raw files or diffs when counts plus changed paths would answer the195 question.196- Compressing output without saying what was omitted.197- Creating a skill that explains usage at length but does not define the output198 contract agents should follow.199200## Acceptance Test201202A tool follows this guide when an agent can answer these questions from default203output alone:204205- Did it succeed, partially succeed, or fail?206- What changed or what was found?207- What exact file, line, command, or ID matters next?208- What was hidden, and how can raw detail be recovered?209- What command or edit should happen next?210211If any answer requires scanning raw logs, redesign the output or add a focused212summary path.