# pi-daily-cost

Daily spend tracker for the [Pi coding agent](https://pi.dev). Shows your total API cost across **all sessions today** in the footer status bar — not just the current session.

```
today: $1.24
```

## Why

Pi's built-in footer shows per-session cost. If you run multiple sessions in a day (different projects, resuming earlier sessions, etc.) there's no easy way to see your total daily spend at a glance. This extension adds that.

## Install

```bash
pi install npm:pi-daily-cost
```

## How it works

On session start, the extension scans all JSONL session files under `~/.pi/agent/sessions/` for today's date and sums assistant message costs. New costs in the active session are accumulated live via the `message_end` event. The footer updates in real time as you work.

**Handles:**
- Multiple sessions across different projects
- Resumed or forked sessions (no double-counting)
- Sessions that span midnight (costs are attributed to the local date of each message)
- Fresh installs with no prior sessions

## Display

The status appears in your footer as `today: $X.XX`. Works best alongside [`pi-powerline-footer`](https://www.npmjs.com/package/pi-powerline-footer), which styles footer status segments.

Cost format:
- `$0.00` — nothing spent yet
- `<$0.001` — sub-millicent amounts  
- `$0.0423` — fractions of a cent
- `$0.142` — cents range
- `$1.24` — dollar range

## Notes

- Costs are read from Pi's local session files — no network calls, no external tracking
- If a session file is unreadable or malformed, it's skipped silently
- Branched/abandoned conversation paths are included in the cost total (the API cost was incurred either way)
