Context Optimization logo

Context Optimization

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

Overview

Publisherjbdamask
Repositoryjohn-claude-skills
Skill nameContext Optimization
Stars
29
Forks
3
Bundled files
1
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.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

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

Installation

Install the Context Optimization 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/jbdamask/john-claude-skills/tree/main/plugins/context-analyzer/skills/context-optimization
  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/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
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Context Optimization 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 Context Optimization 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 Context Optimization 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.

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

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Context Optimization AI skill do?

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.

Why use Context Optimization on TypingMind?

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

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jbdamask/john-claude-skills/tree/main/plugins/context-analyzer/skills/context-optimization. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Context Optimization?

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 Context Optimization?

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

Is the Context Optimization AI skill free?

Yes. It is published on GitHub by jbdamask 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 👇