feat(tracking): per-agent token tracking with rtk gain --agent filter#1408
Open
Mithesh14 wants to merge 1 commit intortk-ai:developfrom
Open
feat(tracking): per-agent token tracking with rtk gain --agent filter#1408Mithesh14 wants to merge 1 commit intortk-ai:developfrom
Mithesh14 wants to merge 1 commit intortk-ai:developfrom
Conversation
Implements issue rtk-ai#1314. Each AI agent hook (claude, cursor, gemini, copilot) now injects RTK_AGENT=<agent> into every rewritten command. The proxy reads this env var and persists the agent name in a new agent column in the SQLite commands table (auto-migrated on first run). rtk gain --agent <name> filters all analytics by agent, enabling per-agent token savings breakdowns. Changes: - hooks/hook_cmd.rs: prepend_agent_env() helper; all 4 agent handlers (claude, cursor, gemini, copilot/vscode) inject RTK_AGENT=<agent> - core/tracking.rs: schema migration (ALTER TABLE + index), record() reads RTK_AGENT env var, all *_filtered() methods accept agent_filter - analytics/gain.rs: run() accepts agent param, title reflects scope, all print/export functions propagate agent_filter - main.rs: --agent flag on gain subcommand, dispatched to gain::run() Closes rtk-ai#1314
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #1314 — per-agent token tracking so you can see savings broken down by AI agent (Claude Code, Cursor, Gemini, Copilot, etc.).
claude,cursor,gemini,copilot/vscode) prependsRTK_AGENT=<agent>to every rewritten command via a newprepend_agent_env()helper inhook_cmd.rstracking.rsauto-migrates existing installs withALTER TABLE commands ADD COLUMN agent TEXT DEFAULT ''+ a compound index on(agent, timestamp)— silent no-op if column already existsrtk gain --agent <name>filters all stats (daily/weekly/monthly, JSON/CSV export) by agent; title reflects the active scope (Global / Project / Agent / Project+Agent)Usage
Test plan
cargo fmt --all— no formatting issuescargo clippy --all-targets— no warningscargo test --all— all 1590 existing tests pass (test helper passes empty agent to keep assertions unchanged)rtk gain --agent claudeandrtk gain --agent cursorboth return correct filtered statsScreenshot
Closes #1314
🤖 Generated with Claude Code