Chuyển đến nội dung
Skillpedia
Khác81k · #1609

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-session/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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.

  1. Resolve session jsonl: --session-id <id> (scans ~/.claude/projects/*/) or --latest (default; picks most-recently-modified jsonl).
  2. Parse all assistant messages with usage blocks.
  3. Cost each message via shared PRICING (_prices.mjs).
  4. Sort descending by cost_usd, surface top-N (default 20).
  5. Compute p50/p90/p99 of message costs for in-session percentile context.
  6. 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-id not found in any project's jsonls → exit 2 with error.
  • --top must 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự