Skip to main content
This guide walks through the complete process of adding a new command to RTK, from planning to documentation.

Filter Development Checklist

From CLAUDE.md (lines 548-605), here’s the complete checklist:

Implementation

  • Create filter module in src/<cmd>_cmd.rs (or extend existing)
  • Add lazy_static! regex patterns for parsing (compile once, reuse)
  • Implement fallback to raw command on error (graceful degradation)
  • Preserve exit codes (std::process::exit(code) if non-zero)

Testing

  • Write snapshot test with real command output fixture (tests/fixtures/<cmd>_raw.txt)
  • Verify token savings ≥60% with count_tokens() assertion
  • Test cross-platform shell escaping (macOS, Linux, Windows)
  • Write unit tests for edge cases (empty output, errors, unicode, ANSI codes)

Integration

  • Register filter in main.rs Commands enum
  • Update README.md with new command support and token savings %
  • Update CHANGELOG.md with feature description

Quality Gates

  • Run cargo fmt --all && cargo clippy --all-targets && cargo test
  • Benchmark startup time with hyperfine (verify <10ms)
  • Test manually: rtk <cmd> and inspect output for correctness
  • Verify fallback: Break filter intentionally, confirm raw command executes

Documentation

  • Add command to CLAUDE.md Module Responsibilities table
  • Document token savings % (from tests)
  • Add usage examples to README.md

Module Creation Pattern

Step 1: Create Module File

Step 2: Implement Standard Template

Step 3: Register in main.rs

Add the module to main.rs:

Implementation Steps

1

Choose a filtering strategy

Select the appropriate strategy based on output type:
  • Stats Extraction: Count/aggregate (git status, pnpm list)
  • Error Only: Show stderr only (test failures)
  • Grouping by Pattern: Group by rule/file (lint, tsc)
  • Deduplication: Count repeated lines (logs)
  • Structure Only: Keys without values (JSON)
  • Code Filtering: Strip comments/bodies (read)
  • Failure Focus: Show only failures (vitest, playwright)
  • Tree Compression: Hierarchy view (ls)
  • Progress Filtering: Strip ANSI (wget, pnpm)
  • JSON/Text Dual: JSON when available (ruff, pip)
  • State Machine: Track state transitions (pytest)
  • NDJSON Streaming: Line-by-line JSON (go test)
See Architecture - Filtering Strategies for details.
2

Write the test first (TDD)

Create a fixture file with real command output:
Write a failing test:
Run the test (it should fail):
3

Implement the filter

Implement the filtering logic to pass the test:
Run the test again (it should pass):
4

Add Package Manager Detection (JS/TS only)

For JavaScript/TypeScript tools, add package manager auto-detection:
5

Add graceful fallback

Ensure the filter fails gracefully:
6

Add edge case tests

Test error conditions:
7

Run quality gates

All checks must pass before committing.
8

Benchmark performance

9

Manual testing

Test with real commands:
10

Update documentation

Update multiple files:README.md:
CHANGELOG.md:
CLAUDE.md (Module Responsibilities table):

Testing Requirements

Token Savings Verification

All filters must achieve ≥60% token savings:

Exit Code Preservation

Test that exit codes are properly preserved:

Fallback Testing

Verify graceful degradation:

Example Walkthrough: Adding rtk mypy

Let’s walk through adding Python type checker support:

1. Create fixture

mypy_raw.txt:

2. Write test

Run test (fails):

3. Implement filter

Run test (passes):

4. Complete the module

Add execution and tracking logic (see standard template above).

5. Register in main.rs

6. Test manually

7. Update docs

Add to README.md, CHANGELOG.md, and CLAUDE.md.

Common Pitfalls

Don’t recompile regex at runtime❌ Wrong: let re = Regex::new(r"pattern").unwrap(); inside function✅ Right: Use lazy_static! for regex compilation
Don’t panic on filter failureAlways fallback to raw command execution. Log error to stderr, execute original command unchanged.
Don’t skip manual testingRunning only automated tests without executing rtk <cmd> and inspecting output is an anti-pattern.

Next Steps