tdd-rust
Skill82k starsChanged 2 months agoApache-2.0View on GitHub
TDD workflow for RTK filter development. Red-Green-Refactor with Rust idioms. Real fixtures, token savings assertions, snapshot tests with insta. Auto-triggers on new filter implementation.
1 other project uses a version of this.
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Most recently taken up by
- FlorianBruniaux/ccboardtheir own version, first seen Apr 29, 2026
Who's talking about rtk-ai/rtk
- mistralai/mistral-vibe“feat: add BeforeTool hook to intercept bash commands before execution”GitHub · Mar 24, 2026 · 31 reactions
- A Hacker News story“Rtk – reduce Claude Code token usage”Hacker News · Feb 28, 2026 · 18 points
- @midu.dev“¡Ojo a esto para ahorrar tokens! Intercepta comandos de terminal y comprime la salida ANTES de llegar al …”Bluesky · Sep 5, 2026 · 16 likes
- @jasonmulligan.com“github.com/rtk-ai/rtk”Bluesky · Mar 13, 2026 · 10 likes
- NixOS/nixpkgs“Build failure: rtk”GitHub · Jul 24, 2026 · 9 reactions
The biggest 5 of 110 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 110
Talked about on GitHub, Bluesky and Hacker News (110 times).
On GitHub · 50
- Mar 24, 2026feat: add BeforeTool hook to intercept bash commands before execution — mistralai/mistral-vibe31 reactions · 8 comments
- Jul 24, 2026Build failure: rtk — NixOS/nixpkgs9 reactions · 1 comment
- Apr 9, 2026[Performance]: reduce token usage & improve performance, such as with rust token killer rtk — tailcallhq/forgecode8 reactions · 8 comments
- Mar 24, 2026feat(hooks): add BeforeToolCallback to intercept tool calls before execution — mistralai/mistral-vibe6 reactions · 5 comments
- Jun 26, 2026Integrate Headroom, RTK, and Ponytail agent optimization tools — vzwjustin/cc-switch4 reactions
45 more on GitHub
- May 26, 2026[FEATURE]: add rtk to bash arity dictionary — anomalyco/opencode4 reactions · 3 comments
- Apr 21, 2026Agregar RTK como componente opcional para reducir 60-90% de tokens en outputs de shell — Gentleman-Programming/gentle-ai4 reactions · 11 comments
- Apr 21, 2026`cargo install rtk` installs the wrong package (Rust Type Kit instead of Rust Token Killer) — martinstannard/openrtk4 reactions
- Mar 29, 2026feat(components): add RTK (Rust Token Killer) token optimization component — Gentleman-Programming/gentle-ai3 reactions · 4 comments
- Oct 15, 2026[BUG] Auto mode on a Max plan: a PreToolUse `updatedInput` rewrite sends the call to the local classifier, with no notice and no entry in `modelUsage` or `total_cost_usd` — anthropics/claude-code2 reactions · 2 comments
- Jul 7, 2026docs: add README_zh-TW.md translation — doggy8088/rtk2 reactions
- May 9, 2026Codex hook support — edouard-claude/snip2 reactions · 1 comment
- Mar 31, 2026Consider using Rust Token Killer — yologdev/yoyo-evolve2 reactions · 9 comments
- Mar 1, 2026Stats via CLI? — mksglu/context-mode2 reactions · 5 comments
- Feb 13, 2026I saved 10M tokens (89%) on my Claude Code sessions with a CLI proxy — router-for-me/CLIProxyAPI2 reactions
- Nov 4, 2026RTK or caveman to reduce token consumption by default in just code ? — etalab-ia/codebox1 reaction · 1 comment
- Oct 15, 2026[FEATURE] Cheaper auto-mode re-check for Bash commands rewritten by a PreToolUse hook — anthropics/claude-code1 reaction · 1 comment
- Oct 2, 2026COR-1553 add resolve_command for Windows command execution — metalbear-co/mirrord1 reaction · 3 comments
- Sep 30, 2026Support Devin CLI as an agent (cmux hooks devin) — manaflow-ai/cmux1 reaction · 1 comment
- Sep 27, 2026v2: tool.execute.before rewrite executes but chat shows pre-hook input — anomalyco/opencode1 reaction · 3 comments
- Aug 31, 2026adopt core: pick the right shell for a command instead of hardcoding cmd /C (upstream #3618) — kylehgc/rtk1 reaction
- Aug 31, 2026adopt discover/search: Windows absolute paths never classify (upstream #3617) — kylehgc/rtk1 reaction
- Aug 31, 2026adopt hooks: keep the hook protocol channel free of the setup nag (upstream #3614) — kylehgc/rtk1 reaction
- Jul 17, 2026Adopt upstream vitest cluster: #2982 + #1497 + #1922 — kylehgc/rtk1 reaction · 2 comments
- Jul 9, 2026feat(community-tool): add RTK (Rust Token Killer) as community tool — Gentleman-Programming/gentle-ai1 reaction · 1 comment
- Jul 8, 2026Task(docs): Telemetry & Privacy page(s) — Kong/kongctl1 reaction · 1 comment
- Jul 2, 2026feat(agent): compress Bash command output via RTK when available — PostHog/code1 reaction · 4 comments
- Jun 4, 2026[feature] add Whale agent support on RTK — usewhale/Whale1 reaction · 2 comments
- May 29, 2026Add optional rtk (Rust Token Killer) support across the retrieval marketplace — mbeacom/context-kit1 reaction · 1 comment
- May 20, 2026[Bug]: `rtk` bypasses safety net — kenryu42/cc-safety-net1 reaction · 2 comments
- May 15, 2026Tool install — get-vix/vix1 reaction · 3 comments
- May 15, 2026feat: Add comparative to rtk and others in README.md — yvgude/lean-ctx1 reaction · 2 comments
- May 13, 2026docs: add RTK CLI proxy documentation — FabienGB69/qitconcierge1 reaction
- May 13, 2026"CLI hooks support for PreToolUse (similar to Claude Code) to enable RTK integration" — kirodotdev/Kiro1 reaction · 6 comments
- May 7, 2026rtk — JyrgenSuvalov/wtf-ai1 reaction
- Apr 18, 2026feat(hooks): support updatedInput for transparent command rewriting — MoonshotAI/kimi-cli1 reaction · 5 comments
- Apr 11, 2026rtkの導入 — book000/dotfiles1 reaction
- Mar 13, 2026fix(hook): respect Claude Code deny/ask permission rules on rewrite — mpecan/tokf1 reaction · 1 comment
- Mar 10, 2026t1430: Integrate rtk CLI proxy for token-optimized output — marcusquinn/aidevops1 reaction · 10 comments
- Mar 2, 2026feat: Add tools.exec.shellInit config for transparent tool integration (RTK-AI use case) — openclaw/openclaw1 reaction · 2 comments
- Feb 20, 2026deps: add rtk dependency — shunkakinoki/dotfiles1 reaction · 4 comments
- Nov 30, 2026rtk 1.3.0 — Homebrew/homebrew-core0 reactions · 1 comment
- Nov 30, 2026rtk: 0.50.0 -> 1.3.0 — ekala-project/ekapkgs0 reactions
- Nov 30, 2026chore: update `rtk` from `1.2.1` to `1.3.0` — Glatzel/demon-forge0 reactions
- Nov 25, 2026agent-skills.github.rtk-ai.rtk: 1.2.1 → 0-unstable-2026-10-13 — sudosubin/agents.nix0 reactions
- Nov 23, 2026rtk: 0.50.0 -> 1.2.1 — ekala-project/ekapkgs0 reactions
- Nov 23, 2026chore(deps): bump rtk to v1.2.1 — RijksICTGilde/hackathon-claude-code0 reactions
- Nov 21, 2026rtk: 1.2.0 -> 1.2.1 — NixOS/nixpkgs0 reactions · 1 comment
- Nov 20, 2026summary.md: linked repos and releases, ticks, readable skip line — keelinfra/release-integrity0 reactions
- Nov 19, 2026agent-skills.github.rtk-ai.rtk: 1.2.0 → 1.2.1 — sudosubin/agents.nix0 reactions
On Bluesky · 50
- Sep 5, 2026¡Ojo a esto para ahorrar tokens! Intercepta comandos de terminal y comprime la salida ANTES de llegar al modelo. ✓-70% de ahorro ✓ Funciona… — @midu.devsays it tested it16 likes and reposts · 1 reply
- Mar 13, 2026github.com/rtk-ai/rtk — @jasonmulligan.com10 likes and reposts · 2 replies
- May 19, 2026🎉 50,000 ⭐ on GitHub. 5 months ago, a weekend hack. Huge thanks to the contributors and to everyone who starred, opened an issue, or… — @rtk-ai.app7 likes and reposts
- Apr 8, 2026RTK hit 20K stars ⭐ 300 billion tokens saved. 20B/day compressed. That's enough energy to power a town of 3,000 people for a year. One Rust… — @rtk-ai.app7 likes and reposts
- Apr 22, 2026rtk-ai / rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies ★32336… — @rusttrending.bsky.socialsays it tested it6 likes and reposts
45 more on Bluesky
- Oct 24, 2026My AI agents don't need every passing test "read out loud". I tried a small log filter (RTK) on saved output: 50 passing tests: 99 → 30… — @aethelgardshuman.bsky.social5 likes and reposts · 1 reply
- Oct 18, 2026rtk-ai / rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies ★83819… — @rusttrending.bsky.social4 likes and reposts
- Aug 31, 2026Coding agents burn a shocking number of tokens just reading shell output. rtk sits in front of every bash call and compresses the result… — @zupo.bsky.social4 likes and reposts
- May 3, 2026コーディングエージェントのトークン消費量を劇的に抑える(80-90%)とか。 出力結果をフィルターして不要な内容を減らしてからエージェントに渡すようにするっぽい RTKが使用するテレメトリの収集オプションもある(セットアップ時に聞かれる)けどデフォルトで無効。… — @anon5r.com4 likes and reposts
- Apr 10, 2026TIL — @gov.glados.computer4 likes and reposts
- May 17, 2026ちなみに、Rust token killerというツール(https://github.com/rtk-ai/rtk)があるんですけれど、これめっちゃいいです。どの生成AIでも非常に効率よくトークン消費を抑えることが出来るので、入れ得です。 — @tunsns.net3 likes and reposts
- Feb 2, 2026🎉 20 stars on rtk-ai in a few days! Thanks community! 🙏 RTK compresses command outputs before your LLM sees them - saving 60-90% tokens!… — @rtk-ai.app3 likes and reposts
- Nov 22, 2026Slash AI coding token costs fast AI coding agents burn through context fast on noisy terminal output. rtk is a single Rust binary CLI proxy… — @cherrypickedhq.bsky.social2 likes and reposts
- Jun 4, 2026rtkを導入したのだけど結構良い感じな気がする ちゃんとコマンドの出力結果を圧縮してくれているし、これを次のテックブログネタにしようか rtk-ai/rtk https://github.com/rtk-ai/rtk — @yug1224.com2 likes and reposts · 1 reply
- May 19, 2026There’s such an exciting opportunity to optimize token usage for local LLMs. Some other exciting token optimizations: * MTP for Qwen 3.6… — @clofresh.bsky.social2 likes and reposts
- May 14, 2026Économisez des tokens Claude code ou autre agent IA avec : github.com/rtk-ai/rtk — @djioliat.bsky.social2 likes and reposts
- Apr 11, 2026https://github.com/rtk-ai/rtk bmann (/bmann) starred rtk-ai/rtk (/rtk-ai/rtk) · April 11, 2026 07:00 rtk-ai/rtk (/rtk-ai/rtk) CLI proxy… — @bmannconsulting.com2 likes and reposts
- Apr 10, 2026Zwei Ansätze, um Token zu sparen: Tool-Output eindampfen https://github.com/rtk-ai/rtk Talk like caveman… — @timo.social.hetzel.net.ap.brid.gy2 likes and reposts
- Apr 5, 2026Checkout the github repo at github.com/rtk-ai/rtk — @navinpeiris.com2 likes and reposts
- Mar 9, 2026rtk — AI coding agent is drowning in CLI noise. RTK compresses outputs by 89%. #OpenSource, Rust. MIT Lic github.com/rtk-ai/rtk — @qdrddr.bsky.social2 likes and reposts
- Feb 12, 2026cargo test: 155 lines of noise rtk cargo test: 3 lines Your AI coding assistant doesn't need all that output. rtk saves 60-90% of tokens on… — @rtk-ai.app2 likes and reposts
- Oct 25, 2026One Rust binary that shrinks what your AI coding agent reads from the shell by up to 90 percent. 🔗 github.com/rtk-ai/rtk #rtk #rust… — @prosperflowio.bsky.social1 likes and repost
- Oct 3, 2026rtk-ai / rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies ★82278… — @rusttrending.bsky.social1 likes and repost
- Sep 26, 2026RTK: an open-source Rust tool that compresses LLM context to cut token consumption 60-90%. Free. github.com/rtk-ai/rtk — @theundergroundai.bsky.social1 likes and repost
- Sep 16, 2026I've already saved 35K tokens this week using rtk 💜 github.com/rtk-ai/rtk — @jaimeiniesta.com1 likes and repost
- Sep 3, 2026rtk-ai / rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies ★78449… — @rusttrending.bsky.social1 likes and repost
- Aug 20, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 rtk-ai / rtk ⭐ 76,756 (+165) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on common… — @github-trending-rs.bsky.social1 likes and repost
- Jun 12, 2026github.com/rtk-ai/rtk GitHub - rtk-ai/rtk: CLI proxy that reduces LLM token consumption by 60-90% on common dev comman... — @technews4869.bsky.social1 likes and repost
- Jun 10, 2026I tried one of those token savers (rtk) but claude decided it didn't like it, so it started piping all commands to /tmp and reading the… — @wilb.me1 likes and repost · 1 reply
- Jun 4, 2026コマンド実行時の出力を圧縮してLLMのトークン消費を大幅に削減するRust製ツールらしい AIコーディングを日常的に使っているなら導入してみると便利そう yug1224 starred rtk-ai/rtk https://github.com/rtk-ai/rtk — @yug1224.com1 likes and repost
- May 26, 2026Ohh my brain. Sorry it’s rtk. github.com/rtk-ai/rtk — @darth-vada.bsky.social1 likes and repost
- May 19, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 rtk-ai / rtk ⭐ 50,366 (+667) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social1 likes and repost · 1 reply
- May 19, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 rtk-ai / rtk ⭐ 50,366 (+667) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending.bsky.social1 likes and repost · 1 reply
- May 13, 2026rtk — Your AI coding agent is drowning in CLI noise. RTK compresses outputs by 89%. Open source, Rust. github.com/rtk-ai/rtk — @qdrddr.bsky.social1 likes and repost · 1 reply
- May 8, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 rtk-ai / rtk ⭐ 44,543 (+858) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social1 likes and repost · 1 reply
- May 4, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 rtk-ai / rtk ⭐ 41,011 (+678) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social1 likes and repost · 1 reply
- Apr 22, 2026da uma olhada no rtk, pode ajudar um pouco: github.com/rtk-ai/rtk — @reinaldorauch.dev.br1 likes and repost · 1 reply
- Apr 22, 2026🎉 Celebrating! 🎉 (500+ new stars) 📦 rtk-ai / rtk ⭐ 32,138 (+813) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social1 likes and repost · 2 replies
- Apr 21, 2026icymi — @gov.glados.computer1 likes and repost · 1 reply
- Mar 14, 2026⚡ My rtk gain: ___ tokens saved (___) over ___ commands. That's ___ less noise in my AI's context window. github.com/rtk-ai/rtk — @lv10one.bsky.social1 likes and repost
- Feb 28, 2026Rtk – reduce Claude Code token usage L: https://github.com/rtk-ai/rtk C: https://news.ycombinator.com/item?id=47189599 posted on 2026.02.27… — @hnws.bsky.social1 likes and repost
- Nov 2, 2026❯ rtk init --codex --global [--dry-run] RTK saved 666 tokens (68.6%), confirmed by rtk gain --history. github.com/rtk-ai/rtk — @foobar.eagleusb.com0 likes and reposts · 1 reply
- Oct 6, 2026rtkは、エージェントが打つシェルコマンドの出力を、LLMに渡す前に縮めるRust製のプロキシです。Apache-2.0。 git statusは短い形に、テスト結果は失敗だけ、ログの重複はまとめる。Claude… — @mint-echosphere.bsky.social0 likes and reposts · 1 reply
- Sep 12, 2026Nos devs consomment quelques centaines a milliers d'euros en token chaque mois. Malgré les réductions de token par des outils genre… — @timil.eurosky.social0 likes and reposts · 1 reply
- Sep 6, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 rtk-ai / rtk ⭐ 79,035 (+386) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social0 likes and reposts · 1 reply
- Aug 24, 2026i use github.com/rtk-ai/rtk to save up on tokens, mb some other tools out there — @gudulin.com0 likes and reposts · 1 reply
- Aug 12, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 rtk-ai / rtk ⭐ 75,841 (+233) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social0 likes and reposts · 1 reply
- Jul 25, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 rtk-ai / rtk ⭐ 73,198 (+300) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social0 likes and reposts · 1 reply
- Jul 21, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 rtk-ai / rtk ⭐ 72,220 (+248) 🗒 Rust CLI proxy that reduces LLM token consumption by 60-90% on… — @github-trending-rs.bsky.social0 likes and reposts · 1 reply
- Jul 9, 2026Five tools I now use that cut that waste fast: 1. RTK (Rust Token Killer). Filters git and shell output before the AI sees it. Cuts 60-90%… — @lennartnacke.com0 likes and reposts · 1 reply
On Hacker News · 10
- Feb 28, 2026Rtk – reduce Claude Code token usage18 points · 3 comments
- Apr 10, 2026CLI proxy that reduces LLM token consumption by 60-90% on common dev commandssays it tested it5 points · 2 comments
- Mar 29, 2026CLI proxy that reduces LLM token consumption by 60-90% on common dev commandssays it tested it4 points
- Feb 18, 2026Rtk – High-performance CLI proxy to minimize LLM token consumption4 points
- Feb 11, 2026Show HN: RTK – Wrap your CLI commands, save 60-90% of tokens in AI coding agentssays it tested it4 points · 4 comments
5 more on Hacker News
- Mar 17, 2026Rtk – CLI proxy that reduces LLM token consumption by 60-90%3 points
- Feb 19, 2026Rust Token Killer – High-performance CLI proxy to minimize LLM token consumption3 points · 1 comment
- Nov 6, 2026CLI proxy that reduces LLM token consumption by 60-90% on dev commands2 points
- May 19, 2026RTK: Rust Token Killer2 points · 2 comments
- Feb 13, 2026Rtk CLI Proxy2 points
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- FlorianBruniaux/ccboard★ 96same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository13 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- code-simplifierSkill
- design-patternsSkill
- issue-triageSkill
- performanceSkill
- pr-reviewSkill
- pr-triageSkill
- repo-recapSkill
- rtk-tddSkill
- rtk-triageSkill
- security-guardianSkill
- shipSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 36
Never write synthetic test data.
- Very specific: line 105
Run: cargo test → should fail (function doesn't exist yet).
- Distinctive: line 191
All 3 must pass. Zero clippy warnings.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
RTK TDD Workflow
Enforce Red-Green-Refactor for all RTK filter development.
The Loop
1. RED — Write failing test with real fixture
2. GREEN — Implement minimum code to pass
3. REFACTOR — Clean up, verify still passing
4. SAVINGS — Verify ≥60% token reduction
5. SNAPSHOT — Lock output format with instaStep 1: Real Fixture First
Never write synthetic test data. Capture real command output:
# Capture real output from the actual command
git log -20 > tests/fixtures/git_log_raw.txt
cargo test 2>&1 > tests/fixtures/cargo_test_raw.txt
cargo clippy 2>&1 > tests/fixtures/cargo_clippy_raw.txt
gh pr view 42 > tests/fixtures/gh_pr_view_raw.txt
# For commands with ANSI codes — capture as-is
script -q /dev/null cargo test 2>&1 > tests/fixtures/cargo_test_ansi_raw.txtFixture naming: tests/fixtures/<command>_raw.txt
Step 2: Write the Test (Red)
#[cfg(test)]
mod tests {
use super::*;
use insta::assert_snapshot;
fn count_tokens(s: &str) -> usize {
s.split_whitespace().count()
}
// Test 1: Output format (snapshot)
#[test]
fn test_filter_output_format() {
let input = include_str!("../tests/fixtures/mycmd_raw.txt");
let output = filter_mycmd(input).expect("filter should not fail");
assert_snapshot!(output);
}
// Test 2: Token savings ≥60%
#[test]
fn test_token_savings() {
let input = include_str!("../tests/fixtures/mycmd_raw.txt");
let output = filter_mycmd(input).expect("filter should not fail");
let input_tokens = count_tokens(input);
let output_tokens = count_tokens(&output);
let savings = 100.0 * (1.0 - output_tokens as f64 / input_tokens as f64);
assert!(
savings >= 60.0,
"Expected ≥60% token savings, got {:.1}% ({} → {} tokens)",
savings, input_tokens, output_tokens
);
}
// Test 3: Edge cases
#[test]
fn test_empty_input() {
let result = filter_mycmd("");
assert!(result.is_ok());
// Empty input = empty output OR passthrough, never panic
}
#[test]
fn test_malformed_input() {
let result = filter_mycmd("not valid command output\nrandom text\n");
// Must not panic — either filter best-effort or return input unchanged
assert!(result.is_ok());
}
}Run: cargo test → should fail (function doesn't exist yet).
Step 3: Minimum Implementation (Green)
// src/mycmd_cmd.rs
use anyhow::{Context, Result};
use regex::Regex;
use std::sync::LazyLock;
static ERROR_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^error").unwrap());
pub fn filter_mycmd(input: &str) -> Result<String> {
if input.is_empty() {
return Ok(String::new());
}
let filtered: Vec<&str> = input.lines()
.filter(|line| ERROR_RE.is_match(line))
.collect();
Ok(filtered.join("\n"))
}Run: cargo test → green.
Step 4: Accept Snapshot
# First run creates the snapshot
cargo test test_filter_output_format
# Review what was captured
cargo insta review
# Press 'a' to accept
# Snapshot saved to src/snapshots/mycmd_cmd__tests__test_filter_output_format.snapStep 5: Wire to main.rs (Integration)
// src/main.rs
mod mycmd_cmd;
#[derive(Subcommand)]
pub enum Commands {
// ... existing commands ...
Mycmd(MycmdArgs),
}
// In match:
Commands::Mycmd(args) => mycmd_cmd::run(args),// src/mycmd_cmd.rs — add run() function
pub fn run(args: MycmdArgs) -> Result<()> {
let output = execute_command("mycmd", &args.to_vec())
.context("Failed to execute mycmd")?;
let filtered = filter_mycmd(&output.stdout)
.unwrap_or_else(|e| {
eprintln!("rtk: filter warning: {}", e);
output.stdout.clone()
});
tracking::record("mycmd", &output.stdout, &filtered)?;
print!("{}", filtered);
if !output.status.success() {
std::process::exit(output.status.code().unwrap_or(1));
}
Ok(())
}Step 6: Quality Gate
cargo fmt --all && cargo clippy --all-targets && cargo testAll 3 must pass. Zero clippy warnings.
Arrange-Act-Assert Pattern
#[test]
fn test_filters_only_errors() {
// Arrange
let input = "info: starting build\nerror[E0001]: undefined\nwarning: unused\n";
// Act
let output = filter_mycmd(input).expect("should succeed");
// Assert
assert!(output.contains("error[E0001]"), "Should keep error lines");
assert!(!output.contains("info:"), "Should drop info lines");
assert!(!output.contains("warning:"), "Should drop warning lines");
}RTK-Specific Test Patterns
Test ANSI stripping
#[test]
fn test_strips_ansi_codes() {
let input = "\x1b[32mSuccess\x1b[0m\n\x1b[31merror: failed\x1b[0m\n";
let output = filter_mycmd(input).expect("should succeed");
assert!(!output.contains("\x1b["), "ANSI codes should be stripped");
assert!(output.contains("error: failed"), "Content should be preserved");
}Test fallback behavior
#[test]
fn test_filter_handles_unexpected_format() {
// Give it something completely unexpected
let input = "completely unexpected\x00binary\xff data";
// Should not panic — returns Ok() with either empty or passthrough
let result = filter_mycmd(input);
assert!(result.is_ok(), "Filter must not panic on unexpected input");
}Test savings at multiple sizes
#[test]
fn test_savings_large_output() {
// 1000-line fixture → must still hit ≥60%
let large_input: String = (0..1000)
.map(|i| format!("info: processing item {}\n", i))
.collect();
let output = filter_mycmd(&large_input).expect("should succeed");
let savings = 100.0 * (1.0 - count_tokens(&output) as f64 / count_tokens(&large_input) as f64);
assert!(savings >= 60.0, "Large output savings: {:.1}%", savings);
}What "Done" Looks Like
Checklist before moving on:
tests/fixtures/<cmd>_raw.txt— real command outputfilter_<cmd>()function returnsResult<String>- Snapshot test passes and accepted via
cargo insta review - Token savings test: ≥60% verified
- Empty input test: no panic
- Malformed input test: no panic
run()function with fallback pattern- Registered in
main.rsCommands enum cargo fmt --all && cargo clippy --all-targets && cargo test— all green
Never Do This
// ❌ Synthetic fixture data
let input = "fake error: something went wrong"; // Not real cargo output
// ❌ Missing savings test
#[test]
fn test_filter() {
let output = filter_mycmd(input);
assert!(!output.is_empty()); // No savings verification
}
// ❌ unwrap() in production code
let filtered = filter_mycmd(input).unwrap(); // Panic in prod
// ❌ Regex inside the filter function
fn filter_mycmd(input: &str) -> Result<String> {
let re = Regex::new(r"^error").unwrap(); // Recompiles every call
...
}Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

