Skip to content
Back to skills

Context Doctor

ASecurity

Keep the LLM context window lean and fast. Use when the conversation grows long, large content is pasted or produced by tools, the user asks "what's eating my context/tokens", asks to reduce cost or latency of LLM calls, or asks to profile/optimize/compact a conversation. Also triggers on "context doctor", "token usage", "context window", "prompt caching".

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added October 13, 2026
ai-agentsgoapi

Works with

  • claude code
  • claude desktop
  • cli
  • api
  • mcp

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add KushalP1/context-doctor --skill context-doctor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Context Doctor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Context Doctor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kushalp1-context-doctor/badge)](https://www.skillsdirectory.com/skills/kushalp1-context-doctor)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: context-doctor
description: Keep the LLM context window lean and fast. Use when the conversation grows long, large content is pasted or produced by tools, the user asks "what's eating my context/tokens", asks to reduce cost or latency of LLM calls, or asks to profile/optimize/compact a conversation. Also triggers on "context doctor", "token usage", "context window", "prompt caching".
---

# Context Doctor — context hygiene for this session and the user's LLM apps

You have two jobs when this skill triggers: (1) keep **this session's** context lean, and (2) help the user profile and optimize **their own** LLM conversations and apps using the context-doctor toolkit.

## Principles of a healthy context window

1. **Tool results are the #1 context killer.** After using a large tool result, carry forward only the extracted facts; never re-quote large outputs. If a tool returns >2k tokens and you need <10% of it, summarize the relevant part immediately in one sentence.
2. **Never duplicate.** If a document, file, or result already appears earlier in the conversation, reference it ("the pricing doc from earlier") instead of re-pasting it.
3. **Stable first, volatile last.** Prompt caches match byte-identical prefixes. Anything reusable (system prompts, tool definitions, reference docs) belongs before anything per-request. One changed byte early invalidates the cache for everything after it — this alone can be a 10x cost difference.
4. **No base64 in text.** Images and files go through file/image APIs, never inline as base64 text.
5. **Summarize old history.** Past ~30-40 turns, models lose the middle of the context. Proactively offer to compact: write a tight summary of the older turns, keep the recent ones verbatim.
6. **Fewer input tokens = faster responses.** Time-to-first-token scales with input size. Every token trimmed is latency and money saved on EVERY subsequent call.

## When the conversation you are in grows long

Proactively (do not wait to be asked):
- Summarize large tool outputs right after consuming them.
- Once, when the session first passes roughly 30 turns or contains several large pastes, offer: "This conversation is getting heavy — want me to compact the older history into a summary so responses stay fast and cheap?"
- When asked to summarize/compact, produce a dense factual summary (decisions made, current state, open items, key identifiers) — not a narrative.
- In a chat app (claude.ai, Claude Desktop, ChatGPT) the history cannot be edited: a summary stops further re-quoting, but the old turns are still re-read on every turn. The real cut is a new chat, so offer a **handoff** once instead: a ≤400-token brief (goal, decisions, current state, open items, key identifiers) plus only the blocks that must stay exact, saved with `save_handoff` when it is available, for the user to start a new chat from.

## Using the context-doctor tools

If the `context-doctor` MCP tools are available:
- `profile_context` — pass a conversation JSON (OpenAI or Anthropic format) or raw text; returns a token breakdown, largest messages, findings with estimated savings. In a chat app, where you cannot export the conversation, pass a `sketch` instead: the turn count plus the large, repeated or image blocks, one size hint each (~120 tokens to write).
- `save_handoff` — stores the handoff brief you wrote and the exact blocks, masks secret-looking strings, and returns the per-turn saving and how to continue (attach `handoff://latest` in a new chat, or paste it). Call it only when the user agrees.
- `optimize_context` — applies deterministic fixes (dedupe, trim stale tool results, strip base64; opt-in `trim-tool-calls` for big inline file writes and `prune-history`). When the result contains pruned-turn source material and asks for a summary, **you write that summary** (≤150 tokens, dense, factual) and place it where the stub indicates — this is how summarization works without any API key.
- `pack_context` — before reading a large document, log or folder to answer a question (not to edit it), pass `paths` and the `query`: it returns only the best-matching chunks within `max_tokens` (default 4000), each with an id and line range, plus the next-best ids. No query = an outline to pick from with `ids`.
- `context_best_practices` — provider-specific checklist to share with the user.
- `recall` — in Claude Code or Codex, when you need a detail from before a compaction or from tool output cleared from the context (an error, a path, a decision), pass a `query` with the words it would contain: it returns the best excerpts of this session's transcript on disk, with time and position, secrets masked. Use it before asking the user to repeat something. CLI: `npx context-doctor recall "<words>"`.

If the tools are not connected, the CLI does the same: `npx context-doctor analyze <file> --model <model>` and `npx context-doctor optimize <file>`, and `npx context-doctor pack <files> --query "<question>"` for big documents. `npx context-doctor session` profiles the user's latest Claude Code session from its transcript, with the API's own token counts, cache economics and subagent costs (`--list` to pick another). For the user's own API apps: `npx context-doctor proxy --autopilot`, then point `ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL` (add `/v1`) or `GOOGLE_GEMINI_BASE_URL` at it; it clears stale tool output only when the prompt cache is cold, so it never costs more.

## When the user pastes a conversation or asks about their token usage

1. Run `profile_context` (or suggest the CLI) rather than eyeballing.
2. Lead with the top finding and its dollar/latency impact, not the full dump.
3. Offer to apply the safe fixes via `optimize_context`; only suggest `prune-history` when the user confirms losing old detail is acceptable (and then write the replacement summary yourself).

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.