| name | context-attribution |
| description | Estimate per-turn token attribution across 6 categories in Claude Code sessions to show where context budget is spent |
| version | 1.1.0 |
| model | sonnet |
| invoked_by | both |
| user_invocable | true |
| tools | ["Read","Bash","Grep","TaskUpdate"] |
| agents | ["developer","architect"] |
| category | Memory & Context |
| tags | ["context-analysis","token-attribution","observability","cost-optimization"] |
| best_practices | ["Classify every message into exactly one of the 6 categories","Use chars/4 for token estimation when usage fields are missing","Present results as a table with cumulative totals"] |
| error_handling | graceful |
| streaming | supported |
| source | builtin |
| trust_score | 100 |
| provenance_sha | 31dc087efe2d9636 |
Context Attribution
Estimate per-turn token attribution across 6 categories in Claude Code sessions. Based on claude-devtools visible context tracker.
When to Invoke
Skill({ skill: 'context-attribution' });
Use when: context pressure is high, optimizing CLAUDE.md sizes, understanding which tool calls consume the most tokens, debugging context overflow.
The 6 Categories
| Category | Detection Pattern | Typical % |
|---|
| CLAUDE.md files | System messages with claudeMd or CLAUDE.md content | 20-40% |
| @-mentioned files | Read tool results triggered by user file references | 10-20% |
| Tool outputs | All tool_result content blocks | 15-30% |
| AI thinking/text | Assistant message content (text + thinking blocks) | 10-25% |
| Team coordination | Messages containing <teammate-message> XML | 0-15% |
| User messages | User role messages (prompts, follow-ups) | 5-15% |
Workflow
Step 1: Load Session JSONL
SESSION=$(ls -t ~/.claude/projects/$(pwd | sed 's|/|-|g; s|^-||')/*.jsonl | head -1)
Step 2: Extract Per-Turn Token Data
For each message, classify into one of the 6 categories and estimate tokens:
grep '"role":"user"' "$SESSION" | grep -v '"tool_result"' | wc -l
grep '"type":"tool_result"' "$SESSION" | -l
grep | -l
grep | -l