diff --git a/CHANGELOG.md b/CHANGELOG.md index caee3bc9..fdbcbc9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to rtk (Rust Token Killer) will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Features + +* **init:** add Cursor support (`rtk init --cursor`) ([#213](https://github.com/rtk-ai/rtk/issues/213)) + * Hook script supports both Claude Code and Cursor preToolUse (auto-detect payload) + * Installs hook + rules (rtk.mdc) + hooks.json for global (~/.cursor) or project (.cursor) + * `rtk init --cursor --show` and `rtk init --cursor -g --uninstall` +* **init:** refactor for multi-agent: `InitTarget` enum, shared `patch_json_registry`, `ensure_agent_hook_installed` (enables adding Codex, OpenCode, etc.) + ## [0.22.2](https://github.com/rtk-ai/rtk/compare/v0.22.1...v0.22.2) (2026-02-20) diff --git a/CLAUDE.md b/CLAUDE.md index b8cf94f0..760143ab 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -128,9 +128,10 @@ main.rs (CLI entry) - Priority: env var > config file > default location **4. Configuration System** (src/config.rs, src/init.rs) -- Manages CLAUDE.md initialization (global vs local) +- Manages CLAUDE.md initialization (global vs local) and Cursor (hooks + rules) - Reads ~/.config/rtk/config.toml for user preferences -- `rtk init` command bootstraps LLM integration +- `rtk init` bootstraps Claude Code; `rtk init --cursor` bootstraps Cursor (hooks.json + rtk.mdc) +- **Adding a new agent (Codex, OpenCode, etc.)**: Add an `InitTarget` variant in init.rs, implement `run__mode` (reuse `ensure_agent_hook_installed`, `patch_json_registry` with agent-specific is_present/insert), and branch in `show_config`/`uninstall`. See doc comment on `InitTarget` in src/init.rs. - **New**: `tracking.database_path` field for custom DB location **5. Tee Output Recovery** (src/tee.rs) diff --git a/README.md b/README.md index b6537eab..2b3f6f9a 100644 --- a/README.md +++ b/README.md @@ -373,6 +373,8 @@ Four strategies applied per command type: | `rtk init -g --claude-md` | Global | ❌ | ❌ | Full (137 lines) | ~2000 | Legacy compatibility | | `rtk init -g --hook-only` | Global | ✅ | ❌ | Nothing | 0 | Minimal setup, hook-only | | `rtk init` | Local | ❌ | ❌ | Full (137 lines) | ~2000 | Single project, no hook | +| `rtk init --cursor` | Project | Cursor hook | rtk.mdc | .cursor/hooks.json | 0 | Cursor Agent (preToolUse) | +| `rtk init --cursor -g` | Global | Cursor hook | rtk.mdc | ~/.cursor/hooks.json | 0 | Cursor Agent, all projects | ```bash rtk init --show # Show current configuration @@ -401,6 +403,15 @@ rtk init -g --hook-only # Hook only, no RTK.md rtk init -g --uninstall # Remove all RTK artifacts ``` +**Cursor** (Agent / Cmd+K): +```bash +rtk init --cursor # Project: .cursor/hooks + .cursor/rules/rtk.mdc + .cursor/hooks.json +rtk init --cursor -g # Global: ~/.cursor/ (same layout) +rtk init --cursor --show # Show Cursor RTK status (global + project) +rtk init --cursor -g --uninstall # Remove global Cursor RTK +``` +Uses the same rewrite hook (preToolUse for Shell); Cursor runs it via `hooks.json` and gets rules from `rtk.mdc`. Restart Cursor after init. + **What is settings.json?** Claude Code configuration file that registers the RTK hook. The hook transparently rewrites commands (e.g., `git status` → `rtk git status`) before execution. Without this registration, Claude won't use the hook. diff --git a/hooks/rtk-cursor-rules.mdc b/hooks/rtk-cursor-rules.mdc new file mode 100644 index 00000000..9f4b6711 --- /dev/null +++ b/hooks/rtk-cursor-rules.mdc @@ -0,0 +1,39 @@ +--- +description: Use rtk (Rust Token Killer) to wrap CLI commands for token-optimized output (60-90% savings) +globs: ["**/*"] +alwaysApply: true +--- + +# RTK Command Proxy + +When running shell commands, prefer `rtk ` over raw commands for token-optimized output. rtk is a CLI proxy that reduces LLM token consumption by 60-90% through smart filtering. + +Leading env var assignments should be preserved (e.g., `FOO=bar cargo test` → `FOO=bar rtk cargo test`). + +## Custom Rules (rtk err — errors-only wrapper) + +These commands have no native rtk filter. Wrap with `rtk err` to show only stderr/errors: + +- `pre-commit ...` → `rtk err pre-commit ...` +- `make ...` → `rtk err make ...` +- `go generate ...` → `rtk err go generate ...` +- `pnpm run