Pi Costs logo

Pi Costs

Community
butttons
pi-costs

Analyze pi session costs. Use when the user asks about spending, costs, token usage, or session statistics.

Overview

Publisherbutttons
Repositorypi-kit
Skill namepi-costs
Stars
36
Forks
1
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by butttons on GitHub. Read the source before you install it.

Installation

Install the Pi Costs AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/butttons/pi-kit/tree/main/skills/pi-costs
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/butttons/pi-kit.git /tmp/pi-kit
mkdir -p .claude/skills
cp -r /tmp/pi-kit/skills/pi-costs .claude/skills/pi-costs
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Pi Costs in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Pi Costs on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Pi Costs is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Pi Session Cost Analysis

Analyze cost, token usage, and session statistics from pi session files stored in ~/.pi/agent/sessions/.

Session File Format

Sessions are stored as JSONL files at ~/.pi/agent/sessions/<project-dir>/<timestamp>_<uuid>.jsonl.

Each line is a JSON object. Assistant messages have this structure:

json
{
  "type": "message",
  "message": {
    "role": "assistant",
    "model": "claude-opus-4-6",
    "usage": {
      "input": 2450,
      "output": 351,
      "cacheRead": 0,
      "cacheWrite": 0,
      "cost": {
        "input": 0.01225,
        "output": 0.008775,
        "cacheRead": 0,
        "cacheWrite": 0,
        "total": 0.021025
      }
    }
  }
}

Instructions

  1. Run the analysis script below via bash with python3.
  2. Present results as a clean summary.
  3. If the user asks for a specific breakdown (by model, by project, by date), adjust the script accordingly.

Analysis Script

bash
find ~/.pi/agent/sessions -name '*.jsonl' -exec grep -h '"cost"' {} \; | python3 -c "
import sys, json
from collections import defaultdict

total_cost = 0
by_model = defaultdict(float)
by_project = defaultdict(float)
message_count = 0
total_input = 0
total_output = 0

for line in sys.stdin:
    try:
        e = json.loads(line.strip())
        if e.get('type') != 'message': continue
        msg = e.get('message', {})
        if msg.get('role') != 'assistant': continue
        usage = msg.get('usage', {})
        cost = usage.get('cost', {})
        t = cost.get('total', 0)
        if t > 0:
            total_cost += t
            message_count += 1
            total_input += usage.get('input', 0)
            total_output += usage.get('output', 0)
            by_model[msg.get('model', 'unknown')] += t
    except: pass

print(f'Total cost: \${total_cost:.2f}')
print(f'Assistant messages: {message_count}')
print(f'Tokens: {total_input:,} input / {total_output:,} output')
print()
print('By model:')
for model, cost in sorted(by_model.items(), key=lambda x: -x[1]):
    pct = (cost / total_cost * 100) if total_cost > 0 else 0
    print(f'  {model}: \${cost:.2f} ({pct:.1f}%)')
"

Per-Project Breakdown

bash
find ~/.pi/agent/sessions -name '*.jsonl' | while read f; do
  dir=$(basename "$(dirname "$f")")
  cost=$(grep '"cost"' "$f" 2>/dev/null | python3 -c "
import sys, json
total = 0
for line in sys.stdin:
    try:
        e = json.loads(line.strip())
        if e.get('type') == 'message' and e.get('message',{}).get('role') == 'assistant':
            total += e['message'].get('usage',{}).get('cost',{}).get('total',0)
    except: pass
print(f'{total:.4f}')
" 2>/dev/null)
  echo "$cost $dir"
done | python3 -c "
import sys
from collections import defaultdict
by_proj = defaultdict(float)
for line in sys.stdin:
    parts = line.strip().split(' ', 1)
    if len(parts) == 2:
        cost, proj = float(parts[0]), parts[1]
        name = proj.replace('--', '/').strip('/')
        name = name.split('/')[-1] if '/' in name else name
        by_proj[name] += cost

print('By project:')
for proj, cost in sorted(by_proj.items(), key=lambda x: -x[1]):
    if cost >= 0.01:
        print(f'  {proj}: \${cost:.2f}')
"

Session Count

bash
echo "Sessions: $(find ~/.pi/agent/sessions -name '*.jsonl' | wc -l | tr -d ' ')"
echo "Projects: $(find ~/.pi/agent/sessions -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')"

Adapting Queries

  • Filter by date: Add find flags like -newer or -newermt '2026-01-01'
  • Single project: Replace find path with ~/.pi/agent/sessions/--Users-*-<project>--/
  • Daily breakdown: Parse the timestamp from the session filename or from message.timestamp

Frequently asked questions

What does the Pi Costs AI skill do?

Analyze pi session costs. Use when the user asks about spending, costs, token usage, or session statistics.

Why use Pi Costs on TypingMind?

Because you install it once and use it with any model. Pi Costs is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Pi Costs in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/butttons/pi-kit/tree/main/skills/pi-costs. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Pi Costs?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Pi Costs?

As many as you like. As long as a model supports skills, you can use Pi Costs with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Pi Costs AI skill free?

It is published on GitHub by butttons. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇