token-optimizer
Skill0 starsChanged 54 days agoMITView on GitHub
Operational protocol for minimizing LLM token consumption and context window bloat during agent coding workflows. Use when: exploring large codebases, inspecting functions, classes, or structs without reading entire files, performing line-range slice viewing (StartLine/EndLine), budgeting context windows for multi-step reasoning, or avoiding context eviction and reasoning degradation on long coding sessions.
27 other projects use a version of this.
Adopted by
Most recently taken up by
- mustafayilmazart/kesif-claude-skillstheir own version, first seen Nov 22, 2026
- aayushostwal/nexustheir own version, first seen Nov 20, 2026
- arturseo-geo/token-optimizer-skilltheir own version, first seen Nov 16, 2026
- tokensafe-dev/tokensafetheir own version, first seen Nov 15, 2026
- tingyulu/MyR2D2their own version, first seen Nov 10, 2026
- blinkboxhq/Blinkboxtheir own version, first seen Nov 8, 2026
Used with
Projects with it also use mcp-builder, webapp-testing and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillmcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Also in 4 projects that use this
JetBrainsSkillwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Also in 3 projects that use this
SentrySkillskill-creator
Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.
Also in 6 projects that use this
Other versions27 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 27
- alexgreensh/token-optimizer★ 3.2ksame name
- nitinjain999/platform-skills★ 71same name
- tokensafe-dev/tokensafe★ 47same name
- georgekhananaev/claude-skills-vault★ 32same name
- tingyulu/MyR2D2★ 20same name
- aayushostwal/nexus★ 19same name
- thesaifalitai/claude-setup★ 9same name
- GPire/claude-skills-swarm★ 8same name
- ZhouYinLong-lab/Dog-Skills★ 7same name
- samibajwaisking/Token-Optimizer-Skill★ 6same name
17 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- templates/AGENTS.mdAGENTS.md
- appstore-privacy-auditorSkill
- ci-cd-automationSkill
- codebase-bootstrapSkill
- code-hygiene-auditorSkill
- git-atomic-curatorSkill
- iphone-duo-migratorSkill
- swift-concurrency-doctorSkill
- swiftui-layout-debuggerSkill
- xcode-ci-doctorSkill
- zero-secret-sanitizerSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 4 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 20 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 74
Never run unconstrained recursive find .
- Distinctive: line 84
Before viewing any file, locate the exact line number of the symbol:
- Distinctive: line 99
Avoid full-file rewrites. Replace only the targeted contiguous block:
- Distinctive: line 162
Read a 45-line slice:
- Very specific: line 180
Check ARCHITECTURE.md or package manifests:
- Distinctive: line 192
Before dispatching tools or writing code:
“Common” is measured: kept by at least 6 in 10 of the 20 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Token Optimizer (LLM Context Economics & Surgical Navigation) ⚡️🧠
The definitive operational manual for AI coding agents tasked with navigating, inspecting, modifying, and verifying large codebases while consuming the absolute minimum number of tokens and preserving model reasoning bandwidth.
1. Executive Summary & Core Philosophy
Large Language Models (LLMs) operate with finite context windows and experience attention diffusion and reasoning degradation as context windows fill with hundreds of thousands of irrelevant tokens. When an agent opens an entire 2,000-line file merely to inspect a 15-line function, it exhausts valuable token budgets, increases latency, and significantly degrades its ability to perform sound multi-step reasoning.
- Failure Modes of AI Agents:
- Greedy File Reads: Using
view_fileon entire files without specifyingStartLineandEndLine. - Blind Repository Greps: Running unconstrained searches across
node_modules/,.build/, or generated lockfiles, flooding the context window with minified javascript or binary artifacts. - Full-File Overwrites: Regenerating a 1,000-line file with
write_to_filewhen only a 3-line surgical patch was needed viareplace_file_content. - Chat Code Echoing: Pasting large duplicate blocks of code back to the user when a concise diff or GitHub file link was sufficient.
- Greedy File Reads: Using
- The Optimizer's Mandate:
- Documentation-First Routing: Inspect
AGENTS.mdandARCHITECTURE.mdto identify the exact 1–2 target files before opening any source files. - Targeted Symbol Navigation: Pinpoint symbols using line-numbered grep (
git grep -n "func execute"), then read a tight 30–50 line window slice (StartLine=X, EndLine=Y). - AST & Interface-First Inspection: Inspect protocol and header definitions rather than full method implementations.
- Surgical Diff Editing: Apply contiguous edits via
replace_file_content.
- Documentation-First Routing: Inspect
2. Mathematical Token Budgeting Framework
+-------------------------------------------------------------------------+
| CONTEXT WINDOW ALLOCATION RULES |
+-------------------------------------------------------------------------+
| Phase 1: Problem Definition & Architecture Routing | 10% - 15% Max |
| Phase 2: Surgical Target Symbol Inspection | 10% - 15% Max |
| Phase 3: Active Code Reasoning & Synthesis | 40% - 50% Core |
| Phase 4: Local Verification Execution & Tool Feedback | 20% - 25% |
| Reserve Buffer (Prevents Context Truncation) | 10% Constant |
+-------------------------------------------------------------------------+3. The 4 Golden Rules of Surgical Codebase Navigation
[Target Investigation Initiated]
│
▼
1. Check ARCHITECTURE.md or AGENTS.md
├── YES ──► Route directly to target directory
└── NO ──► Locate target file using shallow find
│
▼
2. Locate Exact Symbol Line Number:
git grep -n "class TargetClass" Sources/
│
▼
3. Slice Read (30-50 lines max):
view_file StartLine=target-5 EndLine=target+35
│
▼
4. Apply Contiguous Patch:
replace_file_content StartLine=X EndLine=Y
│
▼
5. Verify via Scoped Fast TestRule 1: Shallow Directory Surveys
Never run unconstrained recursive find . or ls -R. Always limit depth and prune heavy directories:
# ✅ CORRECT: Shallow taxonomy mapping
find . -maxdepth 2 -not -path '*/.*' -not -path './node_modules*' -not -path './.build*'
# ✅ CORRECT: Tree with depth constraint
tree -L 2 -I "node_modules|.build|DerivedData|.git"Rule 2: Line-Numbered Targeted Grep
Before viewing any file, locate the exact line number of the symbol:
# ✅ CORRECT: Pinpoint line number with zero context bloat
git grep -n "class AuthenticationService" Sources/
# Output: Sources/Services/AuthenticationService.swift:42: class AuthenticationServiceRule 3: Precise Line Slicing
Once the line number is known, view only the surrounding context:
# ✅ CORRECT: Consumes ~250 tokens instead of 10,000+ tokens
view_file AbsolutePath="/path/to/AuthenticationService.swift" StartLine=40 EndLine=85Rule 4: Surgical Contiguous Editing
Avoid full-file rewrites. Replace only the targeted contiguous block:
{
"StartLine": 55,
"EndLine": 65,
"TargetContent": "...",
"ReplacementContent": "..."
}4. Context-Saving Shell One-Liners & Output Filters
Unfiltered shell output is one of the primary drivers of context window bloat. Always truncate and filter tool output:
4.1 Git Status & Log Filters
# ❌ BAD: Dumps hundreds of lines
git log
git status
# ✅ CORRECT: Compact one-line summary
git status --short
git log --oneline -n 5
git diff --name-only4.2 Test Output Triage
# ❌ BAD: Dumps 20,000 lines of raw compiler and test output
swift test
# ✅ CORRECT: Filter to test failures only
swift test 2>&1 | grep -E "error:|failed|FAILED|FAILURE" | head -n 25
# ✅ CORRECT: Target specific test class
swift test --filter AuthenticationTests4.3 Search Output Filtering
# ❌ BAD: Thousands of matches across minified bundles
grep -r "token" .
# ✅ CORRECT: Scoped search ignoring build and vendor artifacts
git grep -n -E "auth_token|authToken" -- 'Sources/**/*.swift' ':!*.resolved'5. Real-World Architectural Case Studies
Case Study 1: Diagnosing a Monolithic Parser Bug
Scenario: A 3,500-line compiler parser (Sources/Parser/SwiftASTParser.swift) exhibits a crash during operator precedence parsing. A naive agent would read the entire 3,500 lines (~28,000 tokens), exhausting its context window.
Surgical Execution:
- Locate the operator parsing function via git grep:
git grep -n "func parseOperatorPrecedence" Sources/Parser/ # Output: Sources/Parser/SwiftASTParser.swift:1840: func parseOperatorPrecedence() throws -> OperatorNode - Read a 45-line slice:
view_file AbsolutePath=".../SwiftASTParser.swift" StartLine=1838 EndLine=1883 - Identify the missing nil check at line 1862 and replace using
replace_file_contentacross lines 1858–1868. - Run targeted test:
swift test --filter OperatorPrecedenceTests - Total Tokens Consumed: Under 850 tokens (97% savings compared to full file reading).
Case Study 2: Monorepo Target Discovery
Scenario: A monorepo contains 85 packages. A feature requires modifying the caching layer of the auth service.
Surgical Execution:
- Check
ARCHITECTURE.mdor package manifests:find packages/ -maxdepth 2 -name "package.json" | grep auth # Output: packages/auth-service/package.json - Inspect dependencies inside
packages/auth-service/package.json(StartLine=1, EndLine=35). - Directly edit the targeted module without traversing the remaining 84 packages.
6. Pre-Flight Token Conservation Checklist
Before dispatching tools or writing code:
- Target Confirmed: Did I identify the specific file and line number before calling
view_file? - Bounded View Window: Did I specify
StartLineandEndLine(≤ 50 lines) inview_file? - Filtered Shell Output: Are long-running or verbose commands piped to
head,tail, orgrep? - Surgical Edits: Am I using
replace_file_contentinstead of rewriting entire files? - Concise Communication: Are my explanations concise and referencing file links rather than repeating large blocks of source code?
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

