DEV Community

Tanvir Aunjum
Tanvir Aunjum

Posted on AI-assisted

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

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.

Top comments (0)