Repomix + VFS: Bộ đôi tối ưu token cho AI coding
Links
TL;DR
Repomix và VFS không cạnh tranh — chúng bổ sung cho nhau trong AI coding workflow:
- Repomix = Onboarding: AI hiểu codebase từ đầu session
- VFS = Navigation: AI tìm code nhanh trong lúc làm việc
Dùng cả hai = AI vừa hiểu big picture, vừa tìm code chuẩn xác, tiết kiệm token tối đa.
Bài này dành cho ai?
1. Người dùng AI coding agents
Vấn đề: AI không hiểu codebase → code sai pattern, hoặc tốn token đọc cả file chỉ để tìm 1 function.
Được gì: Workflow chuẩn — AI hiểu context từ đầu, tìm code nhanh khi cần.
2. Người build AI-powered dev tools
Vấn đề: Agent tiêu tốn token cho việc exploration thay vì execution.
Được gì: Pattern tối ưu: context dump + signature search.
Hai bài toán khác nhau
| Repomix | VFS | |
|---|---|---|
| Bài toán | ”AI cần hiểu codebase của tôi" | "AI cần tìm function X ở đâu” |
| Khi dùng | Đầu session, 1 lần | Liên tục trong lúc code |
| Input | Cả repo | Search query |
| Output | 1 file XML/MD chứa everything | Signatures + line numbers |
| So với | Copy-paste thủ công | grep/ripgrep |
Không nên so sánh metrics trực tiếp:
- Repomix giảm ~50% tokens vs raw code (cùng scope)
- VFS giảm ~90% tokens vs grep (cùng query)
- Khác scope → không comparable
Workflow kết hợp
┌─────────────────────────────────────────────────────────────┐
│ PHASE 1: ONBOARDING (đầu session) │
│ │
│ $ repomix --compress -o context.xml │
│ │
│ → Paste vào AI: "Đây là codebase, giúp tôi hiểu structure" │
│ → AI biết: tech stack, patterns, modules, conventions │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ PHASE 2: CODING (liên tục) │
│ │
│ User: "Thêm validation cho payment" │
│ │
│ AI dùng VFS MCP: │
│ → vfs.search("payment") │
│ → Returns: src/payments/handler.go:45 │
│ → AI đọc đúng file, đúng dòng │
│ → Viết code đúng pattern (vì đã hiểu từ Phase 1) │
└─────────────────────────────────────────────────────────────┘
Ví dụ thực tế: Refactor authentication
Bước 1: Onboard AI (Repomix)
# Pack toàn bộ auth-related code
repomix src/auth src/middleware --compress -o auth-context.xml
Paste vào Claude:
Đây là authentication module của project. Tôi muốn refactor
từ session-based sang JWT. Phân tích code và đề xuất plan.
AI hiểu:
- Đang dùng express-session
- Middleware check session ở đâu
- Routes nào cần auth
- Pattern hiện tại
Bước 2: Tìm tất cả usages (VFS)
vfs . -f "req.session" --stats
Output:
src/routes/user.ts:23: function getProfile(req: Request)
src/routes/admin.ts:15: function dashboard(req: Request)
src/middleware/auth.ts:8: function requireAuth(req: Request)
...
Tokens saved: 2,847 (vs grep)
AI biết chính xác 12 chỗ cần sửa, không cần đọc 50 files.
Bước 3: Implement từng file (VFS tiếp tục)
# AI cần xem chi tiết 1 file
vfs src/middleware -f "requireAuth"
# → Đọc đúng function đó, implement JWT version
Setup nhanh
Repomix
# Install
npm install -g repomix
# Pack current repo
repomix --compress
# Pack specific dirs
repomix src/api src/models --include "*.ts" -o api-context.xml
# Pack remote repo (không cần clone)
repomix --remote owner/repo
VFS
# Install
go install github.com/TrNgTien/vfs/cmd/vfs@latest
# Search
vfs . -f "handlePayment"
MCP server cho Claude Code:
// ~/.claude/settings.json
{
"mcpServers": {
"vfs": {
"command": "vfs",
"args": ["mcp"]
}
}
}
Thêm rule để AI tự dùng VFS:
# CLAUDE.md
When searching for code:
1. Use vfs.search() first to find signatures
2. Only read specific files/lines returned
3. Never grep or read entire files for search
Khi nào dùng tool nào
| Scenario | Tool | Lý do |
|---|---|---|
| Bắt đầu project mới | Repomix | AI cần hiểu toàn bộ |
| Tìm function | VFS | Nhanh, tiết kiệm token |
| Code review PR | Repomix | AI cần xem all changes |
| Debug error | VFS | Locate error source nhanh |
| Viết documentation | Repomix | AI cần hiểu để document |
| Refactor | Cả hai | Hiểu context + tìm usages |
| Add feature | Cả hai | Hiểu patterns + tìm related code |
Takeaway
Mental model:
- Repomix = Đưa AI bản đồ thành phố (đầu trip)
- VFS = Cho AI GPS để tìm địa chỉ (trong trip)
Workflow chuẩn:
- Session mới →
repomix --compress→ AI hiểu codebase - Trong lúc code → VFS MCP → AI tìm nhanh, đọc ít
- Kết quả: AI code đúng pattern, tiết kiệm token
Không phải either/or — dùng cả hai.
Đang tải nội dung...