跳到正文
DEV Community· Tanvir Aunjum·· 3 小時前AI 評分32

打造 AgentSpend:以 Rust 編寫的 AI Agent 用量追蹤 CLI

I Built AgentSpend: A Rust CLI That Automatically Tracks AI Agent Usage and Finds Wasted Tokens

AI 導讀

AgentSpend 是一款優先在本機運作的 Rust CLI,會掃描本機 Codex 工作階段檔案,並將去重後的 token 用量總計儲存至本機 SQLite 資料庫。目前尚未實作成本計算、浪費偵測及 AI 建議,Claude 和 Gemini 日誌解析亦未完成;提示詞和回應文字會被忽略,本機 API 憑證不會被觸及。

正文

Tanvir Aunjum

Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady Submission 🦥

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

What I Built

AgentSpend is a local-first Rust CLI that scans local Codex session files for token usage and saves deduplicated totals to a local SQLite database.

Digging through agent log files to figure out your usage is annoying and tedious. I built this to make collecting that data automatic and private—everything stays on your machine.

Note: This is an early MVP. Cost calculations, waste detection and AI recommendations aren't built yet.

Demo

If you have Codex session records on your machine, you can run:

agentspend doctor
agentspend scan
agentspend status

(I haven't attached a video or terminal recording yet since I still need to verify the build and run live CLI tests.)

Code

How I Built It

  • Rust & Clap: For building a fast, lightweight native CLI.
  • Serde: To parse event metadata from session logs.
  • SQLite: To store usage totals locally without duplicates.

The log connector uses turn-level counters so it doesn't double-count cumulative thread totals. To keep things secure, prompt and response text are ignored entirely and local API credentials are never touched.

Note on Gemma: I plan to integrate Gemma down the road, but since it’s not working yet I'm not submitting this for the Gemma prize category.

Why Does Open Innovation Matter?

Local, open-source dev tools give you complete control over your data. You can inspect exactly how log collection works, adapt connectors to your own workflow and ensure your usage data never leaves your hardware.

My Agent Session

Omitted—I haven't collected structured metrics on the agent session used to build this yet.

The Lazy Payoff

No more grepping through log folders or manually tallying up session files. The scanner runs in seconds and handles the tracking for you.

Prize Categories

  • Primary: Overall Hacktoberfest Challenge
  • Gemma Category: Skipped for now (waiting until integration is functional).

Limitations and testing

  • Imports: Claude and Gemini log parsing aren't implemented yet.
  • Features: Cost tracking, real-time TUI and Ollama/Gemma log analysis are still on the roadmap.
  • Testing: Needs broader testing across different real-world session setups.

來源:DEV Community · dev.to