Aider — Pair Programming จริงจังกับ AI ใน Terminal
ผมเชื่อในสองเรื่อง:
- Pair Programming — มีใครสักคนนั่งข้าง ๆ คอยถาม คอยทัก คอยเสนอไอเดีย — มันทำให้โค้ดออกมาดีกว่าเขียนคนเดียวเงียบ ๆ
-
Atomic Commit — แต่ละ commit ควรทำเรื่องเดียว จบในตัว —
git logอ่านแล้วรู้เรื่อง ไม่ใช่ commit เดียวยาว 500 บรรทัดที่แก้ทุกอย่างตั้งแต่ database schema ยัน CSS
ปัญหาคือหาคนมานั่ง pair ด้วยตลอดเวลามันไม่ง่าย — และการจะรักษา atomic commit ให้สะอาดทุกครั้งก็ต้องใช้ความตั้งใจสูง
Aider คือเครื่องมือที่แก้ปัญหาสองเรื่องนี้ได้ในคราวเดียว
Aider คืออะไร
Aider เป็น AI pair programming tool ที่ทำงานใน terminal — คุณเปิด terminal, cd เข้า project, แล้วพิมพ์ aider
สิ่งที่เกิดขึ้น:
$ aider
──────────────────────────────────────────────────
Aider v0.80.0
Model: claude-sonnet-4-20250514 (Claude Sonnet 4.6)
Git repo: .git with 142 files
Repo map: using 1024 tokens
──────────────────────────────────────────────────
>
จากนั้นคุณก็... คุยกับมันเหมือนคุยกับคนที่นั่งข้าง ๆ
"help me add rate limiting to the API — per-user, 100 requests per minute, using Redis"
Aider จะ:
- อ่านโค้ดที่เกี่ยวข้อง (มันมี repo map — แผนที่ว่าไฟล์ไหนทำอะไร)
- เสนอวิธีแก้ — "I'll add middleware in
api/middleware/and a Redis client inpkg/redis/" - เขียนโค้ด — คุณเห็น diff ทุกบรรทัด
- Commit ให้ — atomic, descriptive commit message
นี่คือสิ่งที่ผมชอบที่สุด: มัน commit ให้อัตโนมัติ
Atomic Commit — อัตโนมัติ ไม่ใช่ Afterthought
ลองดู git log หลังจาก pair กับ Aider สักพัก:
$ git log --oneline
a3f2c1 Add rate limiting middleware with Redis backend
8b7d4e Refactor auth middleware to use context-based user extraction
2c1e9f Add user repository with FindByEmail method
f4a8b2 Create initial project structure with Go modules
ทุก commit:
- ทำเรื่องเดียว — เพิ่ม middleware → commit / refactor → commit / เพิ่ม repo → commit
- Message อ่านรู้เรื่อง — ไม่ใช่ "fix stuff" หรือ "update"
- แต่ละ commit รัน test ผ่าน — Aider จะรัน test ก่อน commit ให้ (ถ้ามันพัง มันจะแก้จนกว่าจะผ่าน)
เปรียบเทียบกับการทำงานคนเดียว:
- ❌ "เขียน API ใหม่" → แก้ 15 ไฟล์ → commit เดียว "implement new API"
+ ✅ คุยกับ Aider ทีละ feature → 15 commits เล็ก ๆ → แต่ละอันเข้าใจได้ใน 30 วิ
ตัวอย่างการทำงานจริง
สมมติเรามี Go API ง่าย ๆ แล้วอยากเพิ่ม feature "search users by email prefix"
1. เริ่ม session — เล่า requirement
> I need a search endpoint that finds users by email prefix.
GET /users/search?q=jo should return users whose email starts with "jo"
Use existing UserRepo, add the query method there
Aider ตอบ:
I'll add:
1. A `SearchByEmailPrefix` method to `UserRepo` in `internal/repo/user.go`
2. A search handler in `internal/handler/user.go`
3. Register the route in `cmd/server/main.go`
Let me start with the repository method.
2. Aider แก้ไฟล์ — คุณเห็น diff ทันที
// internal/repo/user.go
+func (r *UserRepo) SearchByEmailPrefix(ctx context.Context, prefix string) ([]User, error) {
+ rows, err := r.db.QueryContext(ctx,
+ "SELECT id, name, email FROM users WHERE email LIKE $1",
+ prefix+"%")
+ // ...
+}
คุณเห็น diff → กด y (yes) → Aider commit → ไปต่อข้อถัดไป
3. แก้ไป คุยไป — เหมือน pair จริง
> add input validation — prefix must be at least 2 chars
Aider เพิ่ม validation → commit
> wait, the SQL query should use parameterized LIKE properly
> it's $1 || '%' in PostgreSQL, not prefix+"%"
Aider แก้ query → commit
> now add a test file for the search handler using httptest
Aider สร้าง test → รัน test → test ผ่าน → commit
4 commits — ทุกอันทำเรื่องเดียว — git log สวย
ทำไม Aider ถึงพิเศษ — ไม่ใช่แค่ AI chatbot
1. Repo Map — มัน "รู้จัก" codebase ของคุณ
Aider สร้าง repo map — index ว่าแต่ละไฟล์ define อะไร, ถูก import โดยใคร, ใช้ symbol อะไร — ทำให้มันรู้ว่าต้องอ่านไฟล์ไหนแก้ feature นี้ โดยที่คุณไม่ต้องบอก
ไม่ต้อง copy-paste โค้ดให้ AI อ่าน — Aider รู้เองว่าต้องดู user.go, handler.go, main.go
2. Edit Formats — แก้โค้ดตรง ๆ ไม่ใช่ generate มาให้ copy
Aider ไม่ได้ print โค้ดให้คุณ copy-paste — มันใช้ edit format — ภาษาที่บอกว่า "ค้นหา block นี้, แล้วแทนที่ด้วย block นี้" — เหมือน sed แต่ฉลาดกว่า
ข้อดี: เร็วกว่าการ generate ไฟล์ใหม่ทั้งหมด และแม่นยำกว่า — แก้เฉพาะตรงที่ต้องแก้
3. Model-Agnostic — ใช้ Claude วันนี้, DeepSeek พรุ่งนี้
$ aider --model deepseek/deepseek-chat
$ aider --model openai/gpt-4o
$ aider --model anthropic/claude-sonnet-4-20250514
งานง่ายใช้ DeepSeek (ถูก) — งานยากใช้ Claude Opus (เก่ง) — ไม่ต้องเปลี่ยน tool
4. Voice Coding — พูดแทนพิมพ์
$ aider --voice
คุยกับ AI เหมือนคุยโทรศัพท์ — "add error handling for database connection failures" — Aider เขียนโค้ดให้
Aider vs Copilot vs Cursor vs Antigravity
| Aider | Copilot | Cursor | Antigravity | |
|---|---|---|---|---|
| Philosophy | Pair programming + atomic commit | Autocomplete + chat | AI-first IDE | Agentic platform |
| Interface | Terminal | IDE plugin | IDE (forked VS Code) | IDE, CLI, SDK |
| Atomic Commit | ✅ อัตโนมัติ | ❌ | ❌ | ❌ |
| Model Choice | เปลี่ยนได้ทุกค่าย | จำกัด | จำกัด | Gemini-focused |
| Repo Map | ✅ | ❌ | ใช้ codebase index | ❌ |
| ราคา | API key ตัวเอง | $10/月 | $20/月 | Free/Paid |
Aider ไม่ใช่คู่แข่งโดยตรง — มันคือ เครื่องมืออีกแบบ — สำหรับคนที่:
- ถนัด terminal มากกว่า IDE
- เชื่อใน atomic commit
- อยาก pair จริงจัง — คุยไปแก้ไป commit ไป
- อยากเลือกโมเดลเองตามงาน
เริ่มต้นใน 5 นาที
# ติดตั้ง
pip install aider-chat
# หรือใช้ uv
uv tool install aider-chat
# ตั้ง API key (เลือกค่ายที่ใช้)
export ANTHROPIC_API_KEY="sk-ant-..."
export DEEPSEEK_API_KEY="sk-..."
# เข้า project ที่มี git แล้ว
cd ~/my-go-project
aider
# เริ่มคุย!
> add health check endpoint at /healthz
Pro tip: ใช้ DeepSeek V4 Flash ($0.14/M input) สำหรับงาน routine — แล้วเปลี่ยนเป็น Claude Sonnet ($3/M) ตอนงานซับซ้อน — Aider รองรับ /model deepseek/deepseek-chat เปลี่ยนกลาง session ได้เลย
ข้อเสียตามตรง
-
Terminal-only — ไม่มี GUI (แต่มี
--browserโหมดทดลอง) - ต้องใช้ Git — project ที่ไม่ใช้ Git ใช้ Aider ไม่ได้ (แต่นั่นก็ดี — เราควรใช้ Git อยู่แล้ว)
- เรียนรู้ช่วงแรก — edit format ต้องเข้าใจว่า AI คิดยังไง แต่ผ่านไป 1-2 session ก็ชิน
สรุป
Aider คือสิ่งที่เกิดขึ้นเมื่อคุณเอา philosophy ของ pair programming + atomic commit มารวมกับ LLM — ผลลัพธ์คือ AI ที่นั่ง pair กับคุณใน terminal, เขียนโค้ด, โชว์ diff, และ commit ให้ — เหมือนมี senior dev นั่งข้าง ๆ ที่ git commit เก่งเป็นบ้า
และใช่ — ผมกำลังเชียร์ให้คุณลองใช้
pip install aider-chat && cd project && aider
📚 Source: Aider — AI pair programming in your terminal
Top comments (0)