Token audit

From ils15/pantheon-legacy · View interactive version

Token audit is an AI agent skill from the GitHub repository ils15/pantheon-legacy. Audit a repository for token waste — find redundant context files, measure baseline, recommend optimizations

How to use this skill

Skill file

Token Audit — Repository Context Optimization

Purpose

When Pantheon is installed in a new repository, run this skill to audit and optimize all AI context files for token efficiency.

Step 1: Discover Context Files

Scan the repository for ALL files that contribute to AI context:

# Auto-loaded files (every invocation)
AGENTS.md
CLAUDE.md
.gemini/AGENTS.md
.github/copilot-instructions.md
.github/instructions/*.md
.claude/CLAUDE.md
.cursor/rules/*.mdc
.windsurfrules
.kilocode/rules/*.md
.clinerules
.opencode/agents/*.agent.md

# Memory bank
docs/memory-bank/*.md
docs/adr/*.md

# Skills (lazy-load)
.github/skills/*/SKILL.md
.claude/skills/*/SKILL.md
.opencode/skills/*/SKILL.md

Step 2: Build Redundancy Map

Read all discovered files and map what information appears where:

| Information | Found in files | Lines duplicated |

|---|---|---|

| Tech stack | AGENTS.md, 00-overview.md, copilot-instructions.md | ~15 |

| Run commands | AGENTS.md, 03-tech-context.md, commands.md | ~10 |

| Agent roles | AGENTS.md, copilot-instructions.md, zeus.agent.md | ~20 |

| CI/CD rules | AGENTS.md, copilot-instructions.md, .github/workflows | ~12 |

| Coding standards | copilot-instructions.md, instructions/*.md | ~25 |

Step 3: Measure Baseline

Count lines and estimate tokens:

# Auto-loaded context (every invocation)
wc -l AGENTS.md .github/copilot-instructions.md /memories/repo/*.md 2>/dev/null

# On-demand context (read by agents)
wc -l docs/memory-bank/*.md 2>/dev/null

# Skills (lazy-load)
find .github/skills .claude/skills .opencode/skills -name "SKILL.md" 2>/dev/null | xargs wc -l 2>/dev/null

# Agent definitions
wc -l .github/agents/*.agent.md .opencode/agents/*.agent.md .claude/agents/*.agent.md 2>/dev/null

Estimate: 1 line ≈ 4 tokens (markdown average)

Step 4: Identify Red Flags

Check for content that should NOT be auto-loaded. Use specific patterns, not generic keywords:

Skip files where the keyword is expected:

Step 5: Recommendations

Generate a structured report:

Immediate Actions (high impact)

  1. Consolidate duplicated files — merge files with >50% content overlap
  2. Remove historical content — move delivery logs, wave tables to git/issues
  3. Compress verbose sections — convert prose to tables (40-60% token savings)
  4. Delete derivable content — router lists, entity tables that exist in code

Structural Changes (medium impact)

  1. Create lazy-load skills — move operational procedures from auto-loaded files to skills/
  2. Set up memory bank — 3 files max: project.md, active-context.md, progress-log.md
  3. Shorten descriptions — agent/command/skill descriptions under 100 chars

Ongoing (maintenance)

  1. Set line limits — AGENTS.md < 80, memory-bank files < 100
  2. Re-audit after major changes — run this skill quarterly or after big features

Step 6: Apply Optimizations

If user approves, execute:

  1. Merge redundant files
  2. Delete historical content
  3. Compress verbose sections (prose → tables)
  4. Create skills for heavy operational content
  5. Set up optimized memory bank structure
  6. Update cross-references

Output Format

## Token Audit Report

### Baseline
- Auto-loaded: X lines (~Y tokens)
- On-demand: X lines (~Y tokens)
- Skills: N files, X lines total
- Agents: N files, X lines total
- **Total baseline: ~Y tokens per invocation**

### Redundancy
- X instances of duplicated content found
- Estimated waste: ~Y tokens per invocation

### Red Flags
- X files with historical content
- X files with derivable content (exists in code)
- X files exceeding line limits

### Recommended Actions
1. [action] — saves ~Y tokens
2. [action] — saves ~Y tokens
...

### Projected After Optimization
- Auto-loaded: X lines (~Y tokens) — **Z% reduction**
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.