Cost Tracking logo

Cost Tracking

Community
mturac
cost-tracking

ローカルのコスト追跡データベースからOpenAI Codexのトークン使用量、支出、予算を追跡・レポートします。コスト、支出、使用量、トークン、予算、またはプロジェクト、ツール、セッション、日付によるコスト内訳について質問する場合に使用します。

Overview

Publishermturac
Repositoryeverything-openai-codex
Skill namecost-tracking
Stars
91
Forks
2
Bundled files
Instructions only
LicenseMIT
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 mturac on GitHub. Read the source before you install it.

Installation

Install the Cost Tracking 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.
  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/mturac/everything-openai-codex.git /tmp/everything-openai-codex
mkdir -p .claude/skills
cp -r /tmp/everything-openai-codex/docs/ja-JP/skills/cost-tracking .claude/skills/cost-tracking
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cost Tracking 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 Cost Tracking 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 Cost Tracking 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.

コスト追跡

このスキルを使用して、ローカルSQLiteデータベースからOpenAI Codexのコストと使用履歴を分析します。これは、~/.codex-cost-tracker/usage.dbに使用行を書き込むコスト追跡フックまたはプラグインをすでに持っているユーザーを対象としています。

出典: MayurBhavsarによるコミュニティのPR #1304から救済されました。

使用時期

  • ユーザーが「いくら使いましたか?」「このセッションのコストは?」「トークン使用量は?」と尋ねる場合
  • ユーザーが予算、支出制限、超過、またはコスト管理について言及する場合
  • ユーザーがプロジェクト、ツール、セッション、モデル、または日付ごとのコスト内訳を求める場合
  • ユーザーが今日と昨日を比較したい、または最近のトレンドを確認したい場合
  • ユーザーが最近の使用記録のCSVエクスポートを求める場合

動作方法

まず前提条件を確認します:

bash
command -v sqlite3 >/dev/null && echo "sqlite3 available" || echo "sqlite3 missing"
test -f ~/.codex-cost-tracker/usage.db && echo "Database found" || echo "Database not found"

データベースが見つからない場合、使用データを作成しません。ユーザーにコスト追跡が設定されていないことを伝え、信頼できるローカルコスト追跡フック/プラグインのインストールまたは有効化を提案します。

期待されるusageテーブルには通常、ツール呼び出しまたはモデルインタラクションごとに1行が含まれます。列名はトラッカーによって異なりますが、以下の例では次のように仮定します:

意味
timestamp使用イベントのISOタイムスタンプ
projectプロジェクトまたはリポジトリ名
tool_nameツールまたはイベント名
input_tokens記録された場合の入力トークン数
output_tokens記録された場合の出力トークン数
cost_usdUSDで事前計算されたコスト
session_idOpenAI Codexセッション識別子
modelイベントに使用されたモデル

cost_usdを使用して手動で価格計算するよりも優先します。モデルの価格とキャッシュ価格は時間とともに変化し、トラッカーが各行の価格設定の信頼できる情報源であるべきです。

クイックサマリー

bash
sqlite3 ~/.codex-cost-tracker/usage.db "
  SELECT
    'Today: $' || ROUND(COALESCE(SUM(CASE WHEN date(timestamp) = date('now') THEN cost_usd END), 0), 4) ||
    ' | Total: $' || ROUND(COALESCE(SUM(cost_usd), 0), 4) ||
    ' | Calls: ' || COUNT(*) ||
    ' | Sessions: ' || COUNT(DISTINCT session_id)
  FROM usage;
"

プロジェクト別コスト

bash
sqlite3 -header -column ~/.codex-cost-tracker/usage.db "
  SELECT project, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls
  FROM usage
  GROUP BY project
  ORDER BY cost DESC;
"

ツール別コスト

bash
sqlite3 -header -column ~/.codex-cost-tracker/usage.db "
  SELECT tool_name, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls
  FROM usage
  GROUP BY tool_name
  ORDER BY cost DESC;
"

過去7日間

bash
sqlite3 -header -column ~/.codex-cost-tracker/usage.db "
  SELECT date(timestamp) AS date, ROUND(SUM(cost_usd), 4) AS cost, COUNT(*) AS calls
  FROM usage
  GROUP BY date(timestamp)
  ORDER BY date DESC
  LIMIT 7;
"

セッション詳細

bash
sqlite3 -header -column ~/.codex-cost-tracker/usage.db "
  SELECT session_id,
    MIN(timestamp) AS started,
    MAX(timestamp) AS ended,
    ROUND(SUM(cost_usd), 4) AS cost,
    COUNT(*) AS calls
  FROM usage
  GROUP BY session_id
  ORDER BY started DESC
  LIMIT 10;
"

レポートガイダンス

コストデータを表示する場合、以下を含めます:

  1. 今日の支出と昨日の比較。
  2. 追跡されたデータベース全体の合計支出。
  3. コスト順にランク付けされた上位プロジェクト。
  4. コスト順にランク付けされた上位ツール。
  5. 十分なデータがある場合のセッション数とセッションごとの平均コスト。

少額の場合、通貨を小数点4桁でフォーマットします。大きな金額には2桁で十分です。

アンチパターン

  • cost_usdが存在する場合に生のトークン数からコストを推定しないこと。
  • 確認せずにデータベースが存在すると仮定しないこと。
  • 大規模なデータベースで無制限のSELECT *エクスポートを実行しないこと。
  • ユーザー向けの回答で現在のモデル価格をハードコードしないこと。
  • 任意のコードを実行する未審査のフックやプラグインのインストールを推奨しないこと。

関連

  • /cost-report - 同じデータベースを使用するコマンド形式のレポート。
  • cost-aware-llm-pipeline - モデルルーティングと予算設計のパターン。
  • token-budget-advisor - コンテキストとトークン予算の計画。
  • strategic-compact - 繰り返しのトークン支出を削減するためのコンテキスト圧縮。

Frequently asked questions

What does the Cost Tracking AI skill do?

ローカルのコスト追跡データベースからOpenAI Codexのトークン使用量、支出、予算を追跡・レポートします。コスト、支出、使用量、トークン、予算、またはプロジェクト、ツール、セッション、日付によるコスト内訳について質問する場合に使用します。

Why use Cost Tracking on TypingMind?

Because you install it once and use it with any model. Cost Tracking 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 Cost Tracking in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/mturac/everything-openai-codex/tree/main/docs/ja-JP/skills/cost-tracking. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Cost Tracking?

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 Cost Tracking?

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

Is the Cost Tracking AI skill free?

Yes. It is published on GitHub by mturac under the MIT license. 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 👇