紧身牛仔裤👖
把你的背景塞进紧身牛仔裤里。
一个透明地向以下对象提供文件的MCP服务器 克劳德代码 JSON文件缩小了约40-60%。Markdown下降了约15-30%。代码失去了注释膨胀。每次文件读取都会自动消耗更少的令牌。
为什么
在Claude代码中读取的每个文件都会消耗API配额中的令牌。Markdown很冗长(封面、徽章、空行)。JSON在每个对象中重复字段名。代码中的注释对人类有帮助,但对已经理解代码的LLM来说是噪音。
紧身牛仔裤作为MCP服务器,位于Claude和文件系统之间,实时压缩内容:
Claude Code ──> skinny-jeans (MCP) ──> reads file from disk
│
├── .json/.jsonl → TOON encoding ~40-60% savings
├── .md/.mdx → markdown minify ~15-30% savings
├── .ts/.js/.py → comment stripping ~10-20% savings
└── other text → whitespace cleanup ~5% savings运作原理
紧身牛仔裤使用 卡通 JSON的(面向令牌的对象表示法)——一种专为LLM消费而构建的格式,可减少约40%的令牌 *更好* LLM理解准确率(73.9%对JSON的69.7%)。
之前(JSON,~96个令牌):
{
"hikes": [
{"id": 1, "name": "Blue Lake Trail", "distanceKm": 7.5, "difficulty": "moderate"},
{"id": 2, "name": "Ridge Overlook", "distanceKm": 9.2, "difficulty": "hard"},
{"id": 3, "name": "Meadow Loop", "distanceKm": 3.1, "difficulty": "easy"}
]
}之后(TOON,约51个代币——减少47%):
hikes[3]{id name distanceKm difficulty}:
1 Blue Lake Trail 7.5 moderate
2 Ridge Overlook 9.2 hard
3 Meadow Loop 3.1 easy快速开始
安装
npm install skinny-jeans使用克劳德代码注册
claude mcp add --scope user --transport stdio skinny-jeans -- node /path/to/node_modules/skinny-jeans/dist/index.js或者克隆并从源代码构建:
git clone https://github.com/jordan112/skinny-jeans.git
cd skinny-jeans
npm install && npm run build
claude mcp add --scope user --transport stdio skinny-jeans -- node $(pwd)/dist/index.js添加到CLAUDE.md
将此添加到您的项目 CLAUDE.md (或复制其中一份):
# Token Optimization (skinny-jeans)
Prefer `toon_read_file` over built-in Read for files > 50 lines.
Use `toon_read_json` for any JSON/data file.
Use `toon_list_files` instead of ls/Bash for directory listings.
Use `toon_estimate_tokens` before reading large files.验证它是否正常工作
启动Claude Code会话并运行 /mcp --你应该看看 skinny-jeans 列出了5种工具。
MCP工具
| 工具 | 目的 | |
|---|---|---|
toon_read_file(path) | 读取任何优化形式的文件。自动检测类型,应用正确的转换,报告节省。 | |
toon_read_json(path) | JSON/JSONL到TOON,带有编码选项(分隔符、键折叠)。 | |
| `toon_estimate_tokens(path\ | text)` | 在不读取完整文件的情况下估计令牌计数。 |
toon_list_files(path) | 压缩目录列表为缩进树(没有详细的元数据)。 | |
toon_batch_estimate(paths) | 跨文件/目录的批量令牌节省报告。 |
toon_read_file
主要工具。读取任何文件并自动应用正确的优化:
toon_read_file({ path: "data.json" })
→ [skinny-jeans: 47% smaller, ~51 tokens (was ~96)]
→ TOON-encoded content
toon_read_file({ path: "README.md" })
→ [skinny-jeans: 22% smaller, ~145 tokens (was ~186)]
→ Minified markdown (no badges, frontmatter, excess blanks)
toon_read_file({ path: "app.ts" })
→ [skinny-jeans: 15% smaller, ~171 tokens (was ~201)]
→ Code with comments stripped参数:
path(string,必填)--文件路径maxTokens(number,可选)--在此令牌计数处截断输出raw(布尔值,可选)--跳过优化,返回原始内容
toon_read_json
专门用于JSON,具有编码选项:
delimiter—"tab"(默认),"comma",或"pipe"对于表格行keyFolding—"safe"(默认)崩溃{"a": {"b": 1}}进入a.b: 1
toon_estimate_tokens
在提交完整阅读之前快速检查:
toon_estimate_tokens({ path: "big-dataset.json" })
→ File: big-dataset.json
→ Size: 245891 bytes, 4521 lines
→ Estimated tokens: ~52340
→ Category: json
→ Expected savings with skinny-jeans: 40-60%toon_batch_估计
分析整个项目:
toon_batch_estimate({ paths: ["src/", "data/"] })
→ Token Savings Report (47 files)
→ json: 12 files, ~45200 tokens → save ~20340 tokens (45%)
→ code: 28 files, ~31000 tokens → save ~4650 tokens (15%)
→ markdown: 7 files, ~8900 tokens → save ~1780 tokens (20%)
→ Total: ~85100 tokens
→ Estimated savings: ~26770 tokens (31%)命令行界面
紧身牛仔裤也可以作为一个独立的CLI:
# Read a file with optimization
skinny-jeans read data.json
# Estimate tokens for a file
skinny-jeans estimate large-file.ts
# Batch savings report
skinny-jeans batch src/ data/ docs/变换
JSON/JSONL→ TOON
使用 @卡通格式/卡通 编码器。对象数组变成具有共享标题的表格行。嵌套的键被折叠成虚线路径。制表符的标记效果优于逗号。
Markdown缩小
逐行剥离状态机:YAML frontmatter、HTML注释、徽章图像、尾随 # 标题、多余的空行、尾随空格。保留:代码块(从未接触过)、表、链接、块引号。
代码注释剥离
删除整行 // 和 /* */ 评论(C风格语言)和 # 注释(Python、Ruby、shell)。保留内联注释(它们携带上下文)和包含注释式语法的字符串文字。
通用压缩
其他文本文件的回退:将3行以上连续的空白行折叠为1行,去掉尾随的空白。
预期代币节省
| 文件类型 | 典型节省 |
|---|---|
| JSON(表格/数组数据) | 40-60% |
| JSON(嵌套配置) | 20%-35% |
| Markdown(带徽章的自述文件) | 15-30% |
| Types/JavaScript | 10-20% |
| Python | 10-25% |
| 其他文本 | 5-10% |
发展
git clone https://github.com/jordan112/skinny-jeans.git
cd skinny-jeans
npm install
npm run build
npm test本地运行
# Test the MCP server directly
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | node dist/index.js
# Register for development
claude mcp add --scope user --transport stdio skinny-jeans -- node $(pwd)/dist/index.js它如何与Claude Code集成
紧身牛仔裤是 MCP服务器 它通过stdio进行通信。当在Claude Code注册时,它的工具会与Claude的内置工具一起出现。这 CLAUDE.md 该文件指示Claude更喜欢使用紧身牛仔裤工具进行文件读取,因此优化过程是透明的。
这是Claude Code中透明令牌优化的唯一可行方法——钩子可以在工具使用前/后运行命令,但不能修改工具输出。
许可证
麻省理工学院
