Cache Auditのロゴ

Cache Audit

コミュニティ
ussumant
cache-audit

Audit your Claude Code setup against prompt caching best practices. Checks ordering, tool stability, dynamic content handling, and hook injection patterns. Returns a scored report with specific fixes.

概要

公開者ussumant
リポジトリcache-audit
スキル名cache-audit
スター
60
フォーク
7
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    ussumantがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルCache AuditをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/ussumant/cache-audit/tree/main/cache-audit
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ussumant/cache-audit.git /tmp/cache-audit
mkdir -p .claude/skills
cp -r /tmp/cache-audit/cache-audit .claude/skills/cache-audit
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでCache Auditを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にCache Auditを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Cache Auditは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Prompt Cache Audit Skill

Trigger: /cache-audit or "audit my caching" or "check my cache setup" or "am I breaking the cache?"

What it does: Reads your live Claude Code configuration and checks it against the 6 prompt caching rules from Anthropic's engineering team. Returns a scored report with specific, actionable fixes.

Reference: Based on Thariq Shihipar's thread "Lessons from Building Claude Code: Prompt Caching Is Everything"


When Invoked

Run all checks automatically. Do not ask for confirmation. Read the relevant files and produce the full report in one pass.


The 6 Checks

Check 1 — Prompt Ordering (Static Before Dynamic)

Read: ~/.claude/settings.json, all active CLAUDE.md files in the project hierarchy

What to look for:

  • Does the system prompt load in the right order? Rule: static content first, dynamic content last
  • Correct order: System prompt → Tools → CLAUDE.md → Session context → Messages
  • Flag: Any dynamic content (timestamps, git status, current date, user stats) appearing in the system prompt itself
  • Flag: CLAUDE.md files that include session-specific or time-sensitive data
  • Pass: CLAUDE.md files that are purely static instructions, conventions, and file references

Scoring:

  • PASS: System prompt is fully static, dynamic data injected via messages
  • WARNING: Some dynamic data in system prompt but low-frequency change
  • FAIL: High-churn dynamic content (timestamps, file contents) in system prompt

Check 2 — Dynamic Updates via Messages (not System Prompt Edits)

Read: All hook files listed under SessionStart and UserPromptSubmit in ~/.claude/settings.json

What to look for:

  • Hooks should output dynamic data as additionalContext in their JSON response (which becomes a <system-reminder> message) — not by modifying the system prompt
  • Check each hook's output format: does it use hookSpecificOutput.additionalContext? ✅
  • Flag: Any hook that writes to a system prompt file, modifies CLAUDE.md, or injects into the static prefix
  • Pass: Hooks that return JSON with additionalContext key

Also check:

  • Is currentDate injected via message (memory.md context) or hardcoded in system prompt?
  • Is git status coming from a hook → message, or somewhere static?

Scoring:

  • PASS: All hooks use additionalContext pattern
  • FAIL: Any hook modifies system prompt or CLAUDE.md mid-session

Check 3 — Tool Set Stability (No Add/Remove Mid-Session)

Read: ~/.claude/settings.json, ~/.claude/skills/*.md, MCP server configurations

What to look for:

  • Tools should be identical at every turn of the conversation
  • Check: Do any skills explicitly add new tools when invoked? (tool definitions that only appear after a skill runs)
  • Check: Are MCP tools using defer_loading: true stubs rather than full schemas loaded conditionally?
  • Flag: Any skill that modifies the available tool set
  • Pass: MCP tools present as lightweight stubs in every request, full schemas only loaded on demand via ToolSearch

Note: The ToolSearch tool itself is the correct pattern — it lets the model discover tools without adding/removing from the base set.

Scoring:

  • PASS: Tool set is fixed at session start, all MCP tools deferred
  • WARNING: Some conditional tool loading that may cause cache misses
  • FAIL: Skills or hooks that add/remove tools mid-conversation

Check 4 — No Mid-Session Model Switches

Read: ~/.claude/settings.json, ~/.claude/skills/*.md, any agent/team configurations

What to look for:

  • The model field in settings.json should be set and stable
  • Check: Do any skills switch models in the same conversation thread? (e.g., running a quick haiku query inline)
  • Pass: Model switches are done via subagents with handoff messages — the Explore/Plan agent types running on Haiku are separate conversations, not inline switches
  • Flag: Any pattern where the main conversation calls a different model mid-turn

Scoring:

  • PASS: Single model per conversation, subagents used for model delegation
  • FAIL: Inline model switching in same conversation thread

Check 5 — Dynamic Content Size

Read: Hook files, git status injection, session-reminder outputs

What to measure:

  • Estimate the size of dynamic content injected per session/turn
  • Check the git status hook output — measure the typical size of the injected git diff/status
  • Check streak/quota hook output size
  • Check if granola meeting sync injects large content per turn

Thresholds:

  • < 2k chars injected per turn: ✅ PASS
  • 2k–10k chars: ⚠️ WARNING (still correct pattern, just expensive)
  • 10k chars: ❌ FLAG — consider trimming

Known issue to flag:

  • Git status with hundreds of untracked files (like the personalOS repo) can easily exceed 40k chars per session start. This is injected correctly via messages, but the raw token cost is high. Recommend: trim to branch name + changed file count + modified file list only.

Suggested fix for large git status:

bash
# Instead of full git status, inject only:
git branch --show-current
git diff --stat HEAD | tail -5
git status --short | grep "^[^?]" | head -20  # only tracked changes, no untracked

Check 6 — Fork Safety (Compaction & Subagent Calls)

Read: Any compaction configuration, skill invocations that fork context

What to look for:

  • When Claude Code runs compaction (context window fills), does the summary request reuse the same system prompt + tools as the parent?
  • When skills fork a subagent, do they pass through the same prefix?
  • This is partially an Anthropic infrastructure concern — Claude Code handles it correctly by default

Scoring:

  • PASS: Using Claude Code's built-in compaction (handled correctly)
  • MANUAL CHECK: Custom compaction or summarization flows — verify they use identical system prompt + tool definitions as parent

Output Format

After running all checks, output this report:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  PROMPT CACHE AUDIT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Score: X/6

✅ / ⚠️ / ❌  Rule 1 — Ordering: [PASS/WARNING/FAIL]
   → [Specific finding or "All good"]

✅ / ⚠️ / ❌  Rule 2 — Message injection: [PASS/WARNING/FAIL]
   → [Specific hooks checked and their pattern]

✅ / ⚠️ / ❌  Rule 3 — Tool stability: [PASS/WARNING/FAIL]
   → [MCP tool count, defer status]

✅ / ⚠️ / ❌  Rule 4 — Model switching: [PASS/WARNING/FAIL]
   → [Model in settings, any inline switches found]

✅ / ⚠️ / ❌  Rule 5 — Dynamic content size: [PASS/WARNING/FAIL]
   → [Estimated chars/turn for each injection point]

✅ / ⚠️ / ❌  Rule 6 — Fork safety: [PASS/MANUAL CHECK]
   → [Compaction pattern used]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  TOP FIX
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Single most impactful change with exact code/config to implement]

If everything passes: say so clearly and note the estimated cost savings from the current setup vs. a naive implementation.


Reference: The 6 Rules (Quick Cheatsheet)

RuleDoDon't
1. OrderingStatic system prompt → CLAUDE.md → messagesDynamic data in system prompt
2. UpdatesInject via <system-reminder> in messagesEdit system prompt mid-session
3. ToolsFixed tool set + deferred stubsAdd/remove tools per turn
4. ModelsOne model per conversation, subagents for switchesInline model switching
5. SizeTrim dynamic injections to minimum neededDump full git status (40k chars)
6. ForksSame prefix for compaction/subagentsDifferent system prompt for summary calls

よくある質問

AIスキル「Cache Audit」では何ができますか?

Audit your Claude Code setup against prompt caching best practices. Checks ordering, tool stability, dynamic content handling, and hook injection patterns. Returns a scored report with specific fixes.

TypingMindでCache Auditを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Cache Auditはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにCache Auditをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/ussumant/cache-audit/tree/main/cache-auditを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Cache Auditを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Cache Auditは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもCache Auditを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Cache Audit」は無料ですか?

ussumantがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇