Skip to content
OpenSmartRoute
Skillv1.0.0

context-attribution

Estimate per-turn token attribution across 6 categories in Claude Code sessions to show where context budget is spent

by oimiragieo(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from oimiragieo/agent-studio (.claude/skills/context-attribution/SKILL.md). Install upstream with npx skills add oimiragieo/agent-studio --skill context-attribution. Copyright stays with the author.

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

# Find most recent session
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:

# Count user messages (Category 6)
grep '"role":"user"' "$SESSION" | grep -v '"tool_result"' | wc -l

# Count tool results (Categories 2-3)
grep '"type":"tool_result"' "$SESSION" | wc -l

# Count assistant output (Category 4)
grep '"role":"assistant"' "$SESSION" | wc -l

# Check for team messages (Category 5)
grep 'teammate-message' "$SESSION" | wc -l

Step 3: Estimate Tokens Per Category

Use the usage field from each assistant turn for accurate counts. Fall back to chars/4 when unavailable.

Step 4: Output Attribution Table

Turn | CLAUDE.md | Files | Tools | AI Out | Team | User | Total
-----|-----------|-------|-------|--------|------|------|------
  1  |   12,400  |     0 |     0 |    800 |    0 |  200 | 13,400
  2  |        0  | 3,200 | 1,500 |  2,100 |    0 |  150 |  6,950
...  |      ...  |   ... |   ... |    ... |  ... |  ... |   ...

Step 5: Identify Top Consumers

Report which category consumes the most tokens and suggest optimizations (e.g., reduce CLAUDE.md size, compress tool outputs).

Memory Protocol (MANDATORY)

Before starting: ```bash cat .claude/context/memory/learnings.md cat .claude/context/memory/decisions.md ```

After completing:

  • New pattern -> `.claude/context/memory/learnings.md`
  • Issue found -> `.claude/context/memory/issues.md`
  • Decision made -> `.claude/context/memory/decisions.md`

ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/oimiragieo-agent-studio-context-attribution/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

oimiragieo-agent-studio-context-attribution.ocm.jsonjson
{
  "ocm": "1",
  "id": "oimiragieo-agent-studio-context-attribution",
  "kind": "skill",
  "name": "context-attribution",
  "description": "Estimate per-turn token attribution across 6 categories in Claude Code sessions to show where context budget is spent",
  "publisher": "oimiragieo",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "finance"
    ],
    "tags": [
      "skill-md",
      "context-analysis",
      "token-attribution",
      "observability",
      "cost-optimization",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Estimate per-turn token attribution across 6 categories in Claude Code sessions to show where context budget is spent"
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/oimiragieo/agent-studio",
      "path": ".claude/skills/context-attribution/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/oimiragieo/agent-studio/blob/HEAD/.claude/skills/context-attribution/SKILL.md",
      "key": "oimiragieo/agent-studio/.claude/skills/context-attribution/SKILL.md"
    }
  },
  "instructions": "# Context Attribution\n\nEstimate per-turn token attribution across 6 categories in Claude Code sessions. Based on [claude-devtools](https://github.com/matt1398/claude-devtools) visible context tracker.\n\n## When to Invoke\n\n```javascript\nSkill({ skill: 'context-attribution' });\n```\n\nUse when: context pressure is high, optimizing CLAUDE.md sizes, understanding which tool calls consume the most tokens, debugging context overflow.\n\n## The 6 Categories\n\n| Category          | Detection Pattern                                    | Typical % |\n| ----------------- | --------------------------------------",
  "cost": {
    "context_tokens": 734
  }
}

Fetch it by URL: GET /api/v1/registry/oimiragieo-agent-studio-context-attribution/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.

context-attribution - Skill - OpenSmartRoute