cost-session
Skill này làm gì
Skill này phân tích một phiên AI theo từng tin nhắn, cho thấy những câu trả lời nào tốn kém nhất. Nó dành cho người muốn hiểu vì sao một phiên cụ thể lại đắt.
Khi nào nên dùng
- ✓Khi một phiên bị đánh dấu là đắt bất thường và bạn muốn biết lý do.
- ✓Khi bạn muốn xem các tin nhắn tốn kém nhất trong phiên gần nhất.
- ✓Khi bạn muốn biết việc ghi cache có chiếm phần lớn chi phí hay không.
Liên kết skill
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-session/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
“Những tin nhắn nào trong phiên AI gần nhất của tôi tốn kém nhất, và vì sao?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill đọc nhật ký phiên, tính giá từng câu trả lời theo các loại token và sắp xếp các câu trả lời từ chi phí cao nhất đến thấp nhất. Nó cũng đánh dấu những câu trả lời cao hơn hẳn mức thông thường trong phiên đó.
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.
When cost-anomaly flags a session as a >3.5σ outlier, the next question is "which MESSAGES were expensive?". cost-session answers that.
| Question | Skill |
|---|---|
| "Which sessions cost the most?" | cost-conversation |
| "Which sessions are outliers?" | cost-anomaly |
| "Which messages in THIS session were expensive?" | cost-session ← this |
Algorithm
Implementation: scripts/session.mjs.
- Resolve session jsonl:
--session-id <id>(scans~/.claude/projects/*/) or--latest(default; picks most-recently-modified jsonl). - Parse all assistant messages with
usageblocks. - Cost each message via shared PRICING (
_prices.mjs). - Sort descending by
cost_usd, surface top-N (default 20). - Compute p50/p90/p99 of message costs for in-session percentile context.
- Flag the top message if it's >2× the p99 — that's an in-session outlier.
Why this matters: cache writes are the silent cost
Example real session, top message:
| # | Model | In | Out | Cache W | Cache R | Cost |
| 1 | opus-4-7 | 6 | 569 | 881898 | 0 | $16.58 |
Without the Cache W column it looks like "569 output tokens cost $16" — that's wrong by 380×. The actual cost is ephemeral 1h cache write at opus pricing: 881,898 tokens × $18.75/1M = $16.54.
Operators reading the table see immediately: "the model wrote 881K tokens to ephemeral cache". From there the question becomes "why did we cache 881K tokens of context for a 6-input request?" — that's a real engineering signal.
Drill-down workflow
# Step 1: find outliers across all sessions
cost anomaly --alert-on-outliers 1 || cost anomaly # see which session-ids
# Step 2: drill into the flagged session
cost session --session-id <flagged-id> --top 10
# Step 3: open that jsonl at the timestamp the top message reports,
# inspect the prompt + tool calls
Percentile context
Top of output:
| p50 (median) message | $0.85 |
| p90 message | $1.45 |
| p99 message | $1.74 |
Lets operators ask "is this top message a 2× outlier or a 380× one?" without having to compute it themselves. The "top is >2× p99" footer fires when the answer is "yes, this is an in-session outlier worth investigating".
--since filter
Useful for drilling into a specific time range within a long session:
cost session --since 2026-06-16T13:00:00Z --top 5
Only messages with timestamp >= --since are considered.
Edge cases
- No costed assistant messages → "No costed assistant messages" + exit 0.
--session-idnot found in any project's jsonls → exit 2 with error.--topmust be a positive integer → exit 2.
Câu hỏi thường gặp
Tôi có thể chọn một phiên cụ thể không?
Có. Bạn có thể đưa ID phiên, hoặc để skill dùng phiên vừa thay đổi gần nhất theo mặc định.
Nó hiển thị bao nhiêu tin nhắn?
Mặc định là 20 tin nhắn đắt nhất, và bạn có thể chọn số khác.
Vì sao việc ghi cache quan trọng?
Ghi cache có thể thêm một khoản chi phí lớn mà dễ bị bỏ qua nếu bạn chỉ nhìn vào độ dài đầu ra.
Chi tiết
Mô tả gốc của tác giả
Per-message cost breakdown within a single session. The drill-down companion to cost-anomaly — when an outlier session is flagged, this surfaces the specific expensive messages so operators can see whether the cost came from output tokens, cache writes, or model escalations.
repo: ruvnet/ruflo
Độ phổ biến
- Sao GitHub
- 81k
- Vị trí xếp hạng
- #1609
- 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ủ.