| name | analyze-context |
| description | Estimate total token usage and cost across conversation history, system prompts, and active rules. Use when the user asks how much context or how many tokens are in use, to audit context size, or to estimate session cost. |
| model | haiku |
| effort | low |
Analyze Context (Total Cost Estimation)
Instructions
-
Scope: Analyze ALL components that contribute to the context window and cost. This includes:
- Conversation History: User messages, Assistant responses, Tool calls, and Tool outputs.
- System Context:
- System Prompts: The core instructions defining the agent's behavior.
- Active Rules: Content from
AGENTS.md and any active .cursor/rules.
- Skill/Tool Definitions: The descriptions of available tools and skills (often a significant overhead).
- Attached Context: Any
<open_and_recently_viewed_files>, <git_status>, or other automatic context blocks.
-
Estimation Method:
- Calculate the token count based on the number of characters for each component.
- Formula:
Token Count = Character Count * Multiplier
- Multiplier: Use 0.3 (approx. 1 token per 3.3 characters).
-
Procedure:
- Conversation: Estimate chars in the visible chat history.
- System/Rules: Read
AGENTS.md and any active rule files to estimate their size.
- Overhead: Add a heuristic buffer for Tool/Skill definitions and hidden system prompts (typically 2000-5000 chars or ~1000 tokens depending on the number of tools).
- Total: Sum all components.
- Report: Provide a breakdown of the estimated usage.
-
Tools:
Examples
User: "How many tokens are we using?"
Action:
- Chat: ~5000 chars (User + AI messages).
- System:
AGENTS.md (~3000 chars) + Rules (~1000 chars).
- Overhead: ~3000 chars (Tool definitions).
- Total Chars: 12,000.
- Calc:
12,000 * 0.3 = 3,600 tokens.
- Report:
"Estimated Context Usage: ~3,600 tokens
- Conversation: ~1,500 tokens
- System & Rules: ~1,200 tokens
- Tool Definitions: ~900 tokens"