Context Optimizationのロゴ

Context Optimization

コミュニティ
jbdamask
Context Optimization

This skill should be used when the user asks about "context window optimization", "reduce context usage", "context is filling up", "running out of context", "context bloat", "optimize my sessions", "why is context so large", or when providing advice on how to keep Claude Code sessions efficient. Provides knowledge about what consumes context and strategies to minimize waste.

概要

公開者jbdamask
リポジトリjohn-claude-skills
スキル名Context Optimization
スター
29
フォーク
3
同梱ファイル
1
ライセンスMIT
リンク
  • Markdown形式の指示

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

  • どのLLMでも利用可能

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

  • 1個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

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

インストール

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

1

TypingMindにインストール

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

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

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

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

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

TypingMindで使用

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

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

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

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

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

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

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

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

スキルの指示

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

Context Optimization for Claude Code

Overview

Claude Code sessions have a finite context window. Understanding what consumes context and how to minimize waste keeps sessions productive longer. This skill provides patterns and strategies for context-efficient workflows.

What Consumes Context

Every interaction in a Claude Code session adds to context. The main consumers, ranked by typical impact:

1. Message Metadata Overhead (30-40%)

Every message carries a JSON envelope with sessionId, uuid, cwd, gitBranch, version, and other fields. This is not directly controllable but is the largest single category.

2. Progress/Streaming Messages (20-30%)

Hook progress events and streaming data accumulate significantly in long sessions. Not directly controllable.

3. User-Pasted Images (10-20%)

Screenshots pasted into chat are encoded as base64 PNG, inflating size ~33% over raw bytes. A single full-screen PNG screenshot can consume 500 KB to 2 MB of context.

4. File Read Results (5-10%)

Every Read tool invocation returns the full file content into context. Re-reading the same file multiple times multiplies its impact.

5. Browser Screenshots (3-5%)

Claude-in-Chrome screenshots are JPEG (~50-80 KB each) but accumulate in browser-heavy sessions.

6. Edit/Write Payloads (2-3%)

File content included in Edit and Write operations.

7. Bash Output (1-3%)

Command output returned to context. Usually small per-call but adds up with heavy Bash usage.

Optimization Strategies

Compress Screenshots Before Pasting

  • Resize to ~800px wide before pasting
  • Use JPEG format instead of PNG where possible
  • Consider using Claude-in-Chrome's screenshot tool (produces ~50-70 KB JPEG) instead of pasting full-screen PNGs (500 KB-2 MB)
  • On macOS, use Preview or a keyboard shortcut to downscale clipboard images

Reduce File Re-Reads

  • Add structural summaries of frequently-referenced files to the project's CLAUDE.md
  • For infrastructure files (CloudFormation, Terraform, etc.), document resource names and relationships in CLAUDE.md
  • Keep documentation files (DEVLOG.md, CHANGELOG.md) concise; archive old content

Use /compact Proactively

  • Run /compact after browser automation sequences with many screenshots
  • Run /compact after completing a distinct phase of work
  • Run /compact when switching between different parts of the codebase

Optimize Bash Usage

  • Pipe verbose output through head or tail when full output is unnecessary
  • Redirect large outputs to files and read selectively
  • Use --quiet or --silent flags where available

Use .claudeignore

  • Add build artifacts, node_modules, and generated files
  • Add large data files that should not be searched
  • Add log files and temporary outputs

Prefer Edit Over Write

  • Edit replaces specific strings (small payload)
  • Write sends the entire file content (large payload)
  • For modifications to existing files, Edit is more context-efficient

Consolidate Subagent Usage

  • Each Task/subagent invocation adds its result to context
  • Combine related queries into a single subagent call when possible
  • Use targeted prompts that return concise results

Diagnosing Context Issues

To analyze what's consuming context in a specific project, run:

/context-analyzer:analyze-context

This parses the project's JSONL chat history files in ~/.claude/projects/ and produces a detailed breakdown with per-category sizes, most re-read files, and targeted recommendations.

For programmatic access, the analysis script supports JSON output:

bash
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/analyze_context.py --json

Common Anti-Patterns

Re-Reading the Same File Every Turn

Problem: Claude reads types.ts or api.ts every time it needs to reference types. Fix: Add key type definitions or API surface to CLAUDE.md.

Pasting Full-Screen Screenshots

Problem: Each PNG screenshot is 500 KB-2 MB in base64. Fix: Crop to the relevant area and resize before pasting.

Long Browser Automation Sequences Without Compacting

Problem: 20+ screenshots from scroll-screenshot-click sequences fill context. Fix: Run /compact after browser testing. Use read_page (accessibility tree) instead of screenshots when visual verification isn't needed.

Verbose Build/Test Output

Problem: Full test suite output or build logs dumped to context. Fix: Pipe through tail -20 or grep for failures only.

Large Documentation Files Read on Every Session

Problem: DEVLOG.md or similar grows over time and is read at session start. Fix: Keep it under 5 KB or move to Claude Code memory (~/.claude/projects/.../memory/).

Additional Resources

For detailed analysis methodology and report interpretation, see:

  • references/analysis-methodology.md — How the analysis script categorizes context consumption

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Context Optimization」では何ができますか?

This skill should be used when the user asks about "context window optimization", "reduce context usage", "context is filling up", "running out of context", "context bloat", "optimize my sessions", "why is context so large", or when providing advice on how to keep Claude Code sessions efficient. Provides knowledge about what consumes context and strategies to minimize waste.

TypingMindでContext Optimizationを使うメリットは何ですか?

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

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

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/jbdamask/john-claude-skills/tree/main/plugins/context-analyzer/skills/context-optimizationを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Context Optimizationを使えるAIモデルはどれですか?

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

Context Optimizationは何個のAIモデルで使えますか?

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

AIスキル「Context Optimization」は無料ですか?

はい。jbdamaskがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

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

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

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

すべて見る

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

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