Khám phá Learn Stream About Jokes
Stream
Liên kết

Repomix + VFS: Bộ đôi tối ưu token cho AI coding

· github
  • Repomix — Pack repo thành 1 file AI-friendly
  • VFS — Trích function signatures, thay thế grep

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

RepomixVFS
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ầnLiên tục trong lúc code
InputCả repoSearch query
Output1 file XML/MD chứa everythingSignatures + line numbers
So vớiCopy-paste thủ cônggrep/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

ScenarioToolLý do
Bắt đầu project mớiRepomixAI cần hiểu toàn bộ
Tìm functionVFSNhanh, tiết kiệm token
Code review PRRepomixAI cần xem all changes
Debug errorVFSLocate error source nhanh
Viết documentationRepomixAI cần hiểu để document
RefactorCả haiHiểu context + tìm usages
Add featureCả haiHiể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:

  1. Session mới → repomix --compress → AI hiểu codebase
  2. Trong lúc code → VFS MCP → AI tìm nhanh, đọc ít
  3. Kết quả: AI code đúng pattern, tiết kiệm token

Không phải either/or — dùng cả hai.

#repomix #vfs #ai-coding #token-optimization #mcp #cli #workflow
0:00

Chia sẻ ảnh

Bắt đầu gõ để tìm kiếm...