cost-track
Skill này làm gì
Skill này đọc nhật ký phiên lập trình AI hiện tại của bạn và lưu bản ghi về mức dùng token và chi phí. Nó dành cho người muốn theo dõi chi tiêu AI theo thời gian.
Khi nào nên dùng
- ✓Khi bạn hoàn thành một khối việc lớn và muốn ghi lại nó tốn bao nhiêu.
- ✓Khi bạn muốn lưu tổng cuối cùng khi kết thúc một phiên.
- ✓Khi bạn muốn kiểm tra chi tiêu theo lịch định kỳ trong một phiên dài.
Liên kết skill
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-track/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy ghi lại phiên này đã tốn bao nhiêu để sau này tôi xem được trong báo cáo.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill tìm nhật ký phiên đang hoạt động, cộng số token theo từng model, tính chi phí theo bảng giá rồi lưu các tổng. Bạn cũng có thể chạy nó ở chế độ thử, không lưu gì.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Cost Track
Reads the active Claude Code session jsonl (~/.claude/projects/<encoded-cwd>/<session>.jsonl), tallies assistant-message usage per model, computes USD cost using REFERENCE.md pricing, and writes a structured record to the cost-tracking AgentDB namespace. This is the producer that gives cost-report and cost-optimize real data to consume.
When to use
- After a meaningful chunk of work, to capture spend for the report.
- At session-end to persist the final tally.
- Periodically during long sessions (cron-friendly — see
/loop 30m).
Steps
Run the tracker from the project root:
node plugins/ruflo-cost-tracker/scripts/track.mjsThe script auto-discovers the session jsonl from the current working directory. To pin a specific session:
TRACK_SESSION=/path/to/session.jsonl. To dry-run (no memory write):TRACK_DRY_RUN=1.Inspect the markdown summary — total cost, per-model and per-tier breakdowns, and the persisted memory key.
Verify persistence —
mcp__plugin_ruflo-core_ruflo__memory_search({ query: "session-", namespace: "cost-tracking" })should list the new record.cost-reportstep 1 reads from this namespace.
Record shape (in cost-tracking namespace)
Key: session-<sessionId>. Value (JSON):
{
"sessionId": "1dba3b8c-...",
"cwd": "/Users/cohen/Projects/ruflo",
"startedAt": "2026-05-04T...",
"endedAt": "2026-05-05T...",
"messageCount": 234,
"byModel": {
"claude-opus-4-7": {
"tier": "opus",
"input_tokens": 12345,
"output_tokens": 6789,
"cache_creation_input_tokens": 800000,
"cache_read_input_tokens": 2000000,
"messages": 50,
"cost_usd": 1.23
}
},
"byTier": { "haiku": 0.0, "sonnet": 0.45, "opus": 1.23, "unknown": 0 },
"total_cost_usd": 1.68,
"capturedAt": "2026-05-05T..."
}
Pricing source of truth
The script's PRICING constant mirrors REFERENCE.md "Model pricing (USD per 1M tokens)". Update both together when prices change. Cache-write tokens are billed at cache_write rate; cache-read tokens at cache_read (per Anthropic billing docs).
Env overrides
| Env | Default | Purpose |
|---|---|---|
TRACK_CWD |
process.cwd() |
Override which project's sessions to scan |
TRACK_SESSION |
most-recent jsonl | Pin a specific session file |
TRACK_OUT |
unset | Also write the JSON summary to this path |
TRACK_DRY_RUN=1 |
unset | Skip the memory store call |
TRACK_QUIET=1 |
unset | Suppress markdown output |
TRACK_NAMESPACE |
cost-tracking |
Override target namespace |
Cross-references
cost-report(consumer) — reads records produced by this skill- REFERENCE.md "Cost attribution formula" — the math the script implements
cost-budget-check(consumer; landing in P2) — reads totals to evaluate alerts
Câu hỏi thường gặp
Nhật ký phiên nằm ở đâu?
Skill tìm trong thư mục Claude Code của dự án bạn đang làm, trừ khi bạn chỉ cho nó một file khác.
Tôi có thể thử mà không lưu không?
Có. Một cài đặt chạy thử sẽ in kết quả ra mà không ghi gì vào bộ nhớ.
Báo cáo nào dùng dữ liệu này?
Các skill báo cáo chi phí và tối ưu chi phí đọc các bản ghi mà skill này lưu.
Chi tiết
Mô tả gốc của tác giả
Auto-capture per-session token usage from the Claude Code session jsonl and persist to the cost-tracking namespace
repo: ruvnet/ruflo
Độ phổ biến
- Sao GitHub
- 81k
- Vị trí xếp hạng
- #1611
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agent-adaptive-coordinator
81kGiúp agent của bạn chia và cân bằng lại một nhóm agent AI khi khối lượng công việc thay đổi, chọn bố cục phù hợp với tác vụ.
agent-agent
81kDạy agent của bạn biến một mục tiêu lớn thành kế hoạch hành động có thứ tự, và lập lại kế hoạch khi điều kiện thay đổi.
agent-agentic-payments
81kGiúp agent của bạn quản lý ủy quyền chi tiêu cho mua sắm bằng AI, với hạn mức chi, khung thời gian, quy tắc người bán và phê duyệt có chữ ký.
agent-analyze-code-quality
81kGiúp agent của bạn rà soát chất lượng mã, tìm code smell, nợ kỹ thuật và gợi ý tái cấu trúc mà không thay đổi các file.
Skill tương tự
blucli
394kGiúp agent của bạn tìm, phát, tạm dừng, nhóm và chỉnh âm lượng loa Bluesound và NAD qua lệnh blu.
camsnap
394kGiúp agent của bạn chụp ảnh, quay clip ngắn hoặc lấy sự kiện chuyển động từ camera mạng và webcam nội bộ mà bạn đã thiết lập.
eightctl
394kGiúp agent của bạn kiểm tra và điều khiển thiết bị Eight Sleep pod, gồm nhiệt độ, báo thức và lịch ngủ.