* fix: remove all decorative emojis from CLI output (#687) * fix: remove decorative emojis from CLI output (#511) Replace decorative emojis with plain text to reduce token waste. Keep functional symbols (⚠️ ✓ ❌ ✅ ℹ️) that convey meaning in fewer tokens. Signed-off-by: Patrick Szymkowiak <patrick@rtk.ai> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: remove remaining decorative emojis from find_cmd and formatter Missed in initial emoji cleanup pass: 📁 in find_cmd.rs and parser/formatter.rs Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: remove all decorative emojis from CLI output (#511) Replace emojis with plain text tokens across all production files for better LLM compatibility. Test fixtures and external tool detection patterns (e.g. Black's "All done!") are preserved. Signed-off-by: Patrick Szymkowiak <patrick@rtk-ai.app> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: remove last decorative emoji from next_cmd.rs Remove ⚡ from Next.js Build header, missed in previous passes. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: remove remaining emojis from gh_cmd.rs and init.rs Replace production emojis: - gh_cmd.rs: 🟣→[merged], ⚪→[unknown]/[pending], ⭐→removed, 🔱→removed - init.rs: ⚪→[--] for "not found" status indicators Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix: remove all checkmark emojis from CLI output Replace ✓ (U+2713) with plain text across 19 files: - "ok ✓" → "ok" (git add/commit/push/pull) - "✓ cargo test: ..." → "cargo test: ..." (all tool summaries) - Preserved ✓ in input detection patterns and test fixtures LLMs cannot interpret emoji semantics; plain text is clearer. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> --------- Signed-off-by: Patrick Szymkowiak <patrick@rtk.ai> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Signed-off-by: Patrick Szymkowiak <patrick@rtk-ai.app> * feat: OpenClaw plugin for transparent exec rewriting (#358) * feat: add OpenClaw plugin for transparent exec rewriting Adds an OpenClaw plugin that intercepts exec tool calls via the before_tool_call hook and rewrites commands to their RTK equivalents. This is the OpenClaw equivalent of hooks/rtk-rewrite.sh for Claude Code. The plugin: - Registers a before_tool_call hook on the exec tool - Rewrites git, grep, find, ls, gh, docker, kubectl, and test commands - Guards against rewriting piped/compound commands and heredocs - Returns properly typed PluginHookBeforeToolCallResult - Supports enabled/verbose config options Measured savings: 48-87% token reduction on common commands. Files: - openclaw/index.ts — plugin source - openclaw/openclaw.plugin.json — plugin manifest - openclaw/README.md — installation and usage docs * refactor: delegate OpenClaw plugin to rtk rewrite Replace 60+ hardcoded regex rules with a single call to `rtk rewrite`, matching the OpenCode plugin pattern (hooks/opencode-rtk.ts). Benefits: - Zero maintenance: new RTK filters work automatically - Single source of truth: rewrite logic in Rust (src/discover/registry.rs) - 122 → 73 lines, no rule duplication Also: rebase on develop, fix homepage URL, bump version to 1.0.0. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add package.json for npm publishing Enables `openclaw plugins install @rtk-ai/rtk-rewrite` for OpenClaw users. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> --------- Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Co-authored-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add Gemini CLI support via rtk init --gemini (#573) - Add `rtk hook gemini` command: native Rust hook processor for Gemini CLI BeforeTool hooks. Reads JSON from stdin, delegates to `rewrite_command()` (single source of truth), outputs Gemini-format JSON response. - Add `--gemini` flag to `rtk init`: installs hook wrapper script, GEMINI.md, and patches ~/.gemini/settings.json with BeforeTool hook entry. - Add `rtk init -g --gemini --uninstall`: clean removal of all Gemini artifacts. - 6 unit tests covering hook format, rewrite delegation, and exclusions. Replaces PR #174 which had too many conflicts after upstream restructuring. Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> * feat(init): add Codex CLI support via AGENTS.md + RTK.md workflow (#377) * feat(init): add Codex CLI support via AGENTS.md + RTK.md workflow Add --codex mode to rtk init for Codex CLI integration using AGENTS.md + RTK.md, while keeping the newer develop init/opencode flow intact. Includes Codex install/show/uninstall handling, ASCII status output, stricter flag validation, and expanded tests for Codex AGENTS lifecycle and patch-mode rejection. Signed-off-by: Zacaria <havesomecode@gmail.com> * docs: fix validation metadata Signed-off-by: Zacaria <havesomecode@gmail.com> --------- Signed-off-by: Zacaria <havesomecode@gmail.com> * feat(copilot): add Copilot hook support (VS Code + CLI) (#605) Add `rtk hook copilot` command that handles both VS Code Copilot Chat (updatedInput rewrite) and GitHub Copilot CLI (deny-with-suggestion). - Auto-detects format: snake_case (VS Code) vs camelCase (Copilot CLI) - Delegates to `rtk rewrite` (single source of truth) - 14 hook tests (format detection, rewrite gating, output shape) - .github/hooks/rtk-rewrite.json for repo-scoped hook config - .github/copilot-instructions.md for RTK awareness - Test script: hooks/test-copilot-rtk-rewrite.sh Rebased on develop (includes Gemini #573, Codex #377, OpenClaw #358). Original work by @jeziellopes, cleaned up and rebased by maintainer. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Co-authored-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add Cursor Agent support via --agent flag (#595) Add `rtk init -g --agent cursor` to install RTK hooks for Cursor Agent. Cursor's preToolUse hook supports command rewriting via updated_input, functionally identical to Claude Code's PreToolUse. Works with both the Cursor editor and cursor-cli (they share ~/.cursor/hooks.json). Changes: - New `--agent <name>` flag (claude|cursor) on `rtk init`, extensible for future agents. Default is claude (backward compatible). - Cursor hook script (hooks/cursor-rtk-rewrite.sh) outputs Cursor's JSON format: {permission, updated_input} vs Claude's hookSpecificOutput. - `rtk init --show` reports Cursor hook and hooks.json status. - `rtk init -g --uninstall` removes Cursor artifacts. - `rtk discover` notes that Cursor sessions are tracked via `rtk gain` (Cursor transcripts lack structured tool_use/tool_result blocks). - Unit tests for Cursor hooks.json patching, detection, and removal. Made-with: Cursor Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Co-authored-by: Moisei <1199723+moisei@users.noreply.github.com> * feat: add Windsurf support via rtk init --agent windsurf (#695) (#697) Install RTK rules in .windsurfrules (project-scoped) so Cascade prefixes shell commands with rtk for token savings. Windsurf hooks don't support command rewriting (only blocking), so RTK uses the rules-based approach (like Codex with AGENTS.md). Tested: Windsurf Cascade correctly uses rtk git status after install. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * feat: add Cline/Roo Code support via rtk init --agent cline (#701) (#702) Install RTK rules in .clinerules (project-scoped) so Cline prefixes shell commands with rtk for token savings. Same rules-based approach as Windsurf and Codex. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> * fix(skill/rtk-triage): increase PR/issue limit to 200 with pagination hint (#717) * fix(skill/rtk-triage): increase PR/issue limit to 200 with pagination hint Raise gh pr list limit from 60 to 200 to match gh's max per call. Add inline comment explaining how to paginate for repos with >200 open PRs. Update threshold warning from >60 to >200 PRs/issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com> * docs(architecture): update module count to 67 (hook_cmd added in #573) hook_cmd.rs was added in feat: add Gemini CLI support (#573) but ARCHITECTURE.md was not updated. Fixes pre-push validation failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com> --------- Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Signed-off-by: Patrick Szymkowiak <patrick@rtk.ai> Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu> Signed-off-by: Patrick Szymkowiak <patrick@rtk-ai.app> Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com> Signed-off-by: Zacaria <havesomecode@gmail.com> Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com> Co-authored-by: Alex <a.neyman17@gmail.com> Co-authored-by: Ben Younes <benyounes.ousama@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Zacaria Chtatar <Zacaria@users.noreply.github.com> Co-authored-by: Jeziel Lopes <jeziellcarvalho@gmail.com> Co-authored-by: Moisei Rabinovich <moisei@users.noreply.github.com> Co-authored-by: Moisei <1199723+moisei@users.noreply.github.com> Co-authored-by: Florian BRUNIAUX <florian@bruniaux.com>
5.4 KiB
Copilot Instructions for rtk
rtk (Rust Token Killer) is a CLI proxy that filters and compresses command outputs before they reach an LLM context, saving 60–90% of tokens. It wraps common tools (git, cargo, grep, pnpm, go, etc.) and outputs condensed summaries instead of raw output.
Using rtk in this session
Always prefix commands with rtk when running shell commands — this is the entire point of the project and reduces token consumption for every operation you perform.
# Instead of: Use:
git status rtk git status
git log -10 rtk git log -10
cargo test rtk cargo test
cargo clippy --all-targets rtk cargo clippy --all-targets
grep -r "pattern" src/ rtk grep -r "pattern" src/
rtk meta-commands (always use these directly, no prefix needed):
rtk gain # Show token savings analytics for this session
rtk gain --history # Full command history with per-command savings
rtk discover # Scan session history for missed rtk opportunities
rtk proxy <cmd> # Run a command raw (no filtering) but still track it
Verify rtk is installed before starting:
rtk --version # Should print: rtk X.Y.Z
rtk gain # Should show a dashboard (not "command not found")
⚠️ Name collision:
rtk gainfailing means you havereachingforthejack/rtk(Rust Type Kit) installed instead of this project. Runwhich rtkand check the binary source.
Build, Test & Lint
# Development build
cargo build
# Run all tests
cargo test
# Run a single test by name
cargo test test_filter_git_log
# Run all tests in a module
cargo test git::tests::
# Run tests with stdout
cargo test -- --nocapture
# Pre-commit gate (must all pass before any PR)
cargo fmt --all --check && cargo clippy --all-targets && cargo test
# Smoke tests (requires installed binary)
bash scripts/test-all.sh
PRs target the develop branch, not main. All commits require a DCO sign-off (git commit -s).
Architecture
main.rs ← Clap Commands enum → specialized module (git.rs, *_cmd.rs, etc.)
↓
execute subprocess
↓
filter/compress output
↓
tracking::TimedExecution → SQLite (~/.local/share/rtk/tracking.db)
Key modules:
main.rs— ClapCommandsenum routes every subcommand to its module. Each arm callstracking::TimedExecution::start()before running, then.track(...)after.filter.rs— Language-aware filtering withFilterLevel(none/minimal/aggressive) andLanguageenum. Used byreadandsmartcommands.tracking.rs— SQLite persistence for token savings, scoped per project path. Powersrtk gain.tee.rs— On filter failure, saves raw output to~/.local/share/rtk/tee/and prints a one-line hint so the LLM can re-read without re-running the command.utils.rs— Shared helpers:truncate,strip_ansi,execute_command, package-manager auto-detection (pnpm/yarn/npm/npx).
New commands follow this structure: one file src/<cmd>_cmd.rs with a pub fn run(...) entry point, registered in the Commands enum in main.rs.
Key Conventions
Error handling
- Use
anyhow::Resultthroughout (this is a binary, not a library). - Always attach context:
operation.context("description")?— never bare?without context. - No
unwrap()in production code;expect("reason")is acceptable only in tests. - Every filter must fall back to raw command execution on error — never break the user's workflow.
Regex
- Compile once with
lazy_static!, never inside a function body:lazy_static! { static ref RE: Regex = Regex::new(r"pattern").unwrap(); }
Testing
- Unit tests live inside the module file in
#[cfg(test)] mod tests { ... }— not intests/. - Fixtures are real captured command output in
tests/fixtures/<cmd>_raw.txt, loaded withinclude_str!("../tests/fixtures/..."). - Each test module defines its own local
fn count_tokens(text: &str) -> usize(word-split approximation) — there is no shared utility for this. - Token savings assertions use
assert!(savings >= 60.0, ...). - Snapshot tests use
assert_snapshot!()from theinstacrate; review withcargo insta review.
Adding a new command
- Create
src/<cmd>_cmd.rswithpub fn run(...). - Add
mod <cmd>_cmd;at the top ofmain.rs. - Add a variant to the
Commandsenum with#[arg(trailing_var_arg = true, allow_hyphen_values = true)]for pass-through flags. - Route the variant in the
matchblock, wrapping execution withtracking::TimedExecution. - Write a fixture from real output, then unit tests in the module file.
- Update
README.md(command list + savings %) andCHANGELOG.md.
Exit codes
Preserve the underlying command's exit code. Use std::process::exit(code) when the child process exits non-zero.
Performance constraints
- Startup must stay under 10ms — no async runtime (no
tokio/async-std). - No blocking I/O at startup; config is loaded on-demand.
- Binary size target: <5 MB stripped.
Branch naming
fix(scope): short-description
feat(scope): short-description
chore(scope): short-description
scope is the affected component (e.g. git, filter, tracking).