How rtk-ai/rtk works
RTK is a Rust CLI proxy that rewrites supported shell commands, runs command-specific filters, and returns compact output to an AI agent. Its main workflow is complemented by agent hook installation, command discovery and learning, savings analytics, and recall storage. README statements establish the user-facing flow; source-index references support selected internal links. Many command handlers and subsystem implementations were not sampled, so their internal call paths are not inferred.
Main entry points: main.rs RTK CLI · hook_cmd.rs Hook runtime · cmds Command handlers · shell.rs Shell execution
Components 17
CLI workflow
- RTK CLI
src/main.rs
Agent integration
- Hook runtime
src/hooks/hook_cmd.rs - Rewrite registry
src/discover/registry.rs - Agent setup
src/hooks/init/mod.rs
Command filtering
- Command handlers
src/cmds - Shell execution
src/core/shell.rs - Output filters
src/core/filter.rs - Output formatting
src/parser/formatter.rs
Discovery and learning
- Session discovery
src/discover/mod.rs - Command learning
src/learn/mod.rs
Settings and analytics
- Configuration
src/core/config.rs - Usage tracking
src/core/tracking.rs - Savings analytics
src/analytics/gain.rs - Output recall
src/core/retriever.rs - Telemetry commands
src/core/telemetry_cmd.rs
Other components
- AI agent
- Shell commands
Connections 18
- AI agent → Hook runtime: submits commands
README.md - Hook runtime → Rewrite registry: checks rewrite
src/hooks/hook_cmd.rs - Hook runtime → RTK CLI: rewrites to
README.md - RTK CLI → Command handlers: dispatches commands
src/main.rs - Command handlers → Shell execution: executes commands
src/cmds/system/search.rs - Shell execution → Shell commands: runs process
README.md - Command handlers → Output filters: filters output
README.md - Output filters → Output formatting: formats results
- RTK CLI → Agent setup: installs hooks
README.md - RTK CLI → Configuration: loads settings
src/core/config.rs - RTK CLI → Usage tracking: records usage
src/core/tracking.rs - Savings analytics → Usage tracking: reads metrics
- RTK CLI → Savings analytics: reports savings
README.md - RTK CLI → Output recall: recalls output
src/core/retriever.rs - RTK CLI → Session discovery: discovers commands
src/main.rs - Session discovery → Rewrite registry: matches commands
src/discover/mod.rs - RTK CLI → Command learning: learns commands
src/main.rs - RTK CLI → Telemetry commands: manages telemetry
src/main.rs