šŸ”„ Diskon 40% — Kode SPECIAL40⚔ Promo terbatas!

Ralph: Teknik Menjalankan AI Coding dalam Loop

Ralph: Teknik Menjalankan AI Coding dalam Loop

Galih Pratama•

Ralph adalah teknik untuk menjalankan AI coding agent dalam loop. Konsepnya simpel:

  1. Kamu jalankan prompt yang sama berulang-ulang
  2. AI pilih sendiri task dari PRD
  3. AI commit setelah selesai setiap fitur
  4. Kamu balik, code udah jadi

Basically: kamu tinggal pergi, balik-balik udah ada commits.


Apa yang Kamu Butuhkan

  • Claude Code — CLI dari Anthropic untuk agentic coding
  • Docker Desktop (optional tapi recommended) — untuk sandbox yang aman

Step 1: Install Claude Code

# Install Claude Code
curl -fsSL https://claude.ai/install | sh

Kalau dapat error "command not found: claude", tambahkan ke PATH:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Via npm (Alternative)

npm i -g @anthropic-ai/claude-code

Setelah install, jalankan claude untuk authenticate dengan akun Anthropic kamu.


Docker Desktop bikin kamu bisa jalankan Claude Code di sandbox yang terisolasi. AI bisa execute commands, install packages, dan modify files tanpa nyentuh machine lokal kamu.

Install Docker Desktop 4.50+, lalu jalankan:

docker sandbox run claude

Pertama kali run, kamu akan authenticate dengan Anthropic. Credentials disimpan di Docker volume.

Kenapa Pakai Sandbox?

  • Working directory kamu di-mount di path yang sama dalam container
  • Git config otomatis di-inject (commit attribution bener)
  • Satu sandbox per workspace — state persist antar runs
  • Aman — AI nggak bisa rusak sistem kamu

Step 3: Buat Plan File (PRD)

Ralph butuh PRD (Product Requirements Document) untuk ambil task. Kamu bisa tulis manual, tapi lebih cepat pakai Plan Mode Claude.

Cara Buat PRD

# Jalankan Claude
claude

# Tekan Shift+Tab untuk masuk Plan Mode
# Iterate plan sampai kamu puas

Kalau udah puas dengan plan-nya, minta Claude save ke PRD.md.

Buat Progress File

touch progress.txt

PRD = End state yang kamu mau
progress.txt = Track apa yang udah selesai

Setiap loop iteration, Claude:

  1. Baca kedua file
  2. Cari task yang belum di-check
  3. Implement task tersebut
  4. Update progress

Format PRD bebas — markdown checklist, JSON, plain text. Yang penting: scope jelas dan agent bisa extract individual tasks.


Step 4: Buat Script ralph-once.sh

Sebelum full AFK, mulai dengan human-in-the-loop Ralph dulu. Kamu jalankan script, lihat apa yang Claude lakuin, jalankan lagi. Ini bikin kamu paham gimana loop-nya kerja.

Buat File

#!/bin/bash

claude --permission-mode acceptEdits "@PRD.md @progress.txt \\
1. Read the PRD and progress file. \\
2. Find the next incomplete task and implement it. \\
3. Commit your changes. \\
4. Update progress.txt with what you did. \\
ONLY DO ONE TASK AT A TIME."

Save sebagai ralph-once.sh.

šŸ“˜ Mau belajar lebih dalam?

Dapatkan panduan lengkap vibe coding di ebook "Memulai Vibe Coding".

Lihat Ebook →

Penjelasan

Element Fungsi
--permission-mode acceptEdits Auto-accept file edits supaya loop nggak stuck
@PRD.md Point Claude ke requirements doc
@progress.txt Track completed work antar runs
ONLY DO ONE TASK Penting! Paksa commits kecil dan incremental

Jalankan

# Bikin executable
chmod +x ralph-once.sh

# Run
./ralph-once.sh

Watch apa yang Claude lakuin. Cek commit-nya. Run lagi. Repeat sampai kamu comfortable.


Step 5: Buat Script afk-ralph.sh (Full Auto)

Kalau udah nyaman dengan human-in-the-loop, wrap dalam loop:

#!/bin/bash
set -e

if [ -z "$1" ]; then
  echo "Usage: $0 <iterations>"
  exit 1
fi

for ((i=1; i<=$1; i++)); do
  result=$(claude --permission-mode acceptEdits -p "@PRD.md @progress.txt \\
  1. Find the highest-priority task and implement it. \\
  2. Run your tests and type checks. \\
  3. Update the PRD with what was done. \\
  4. Append your progress to progress.txt. \\
  5. Commit your changes. \\
  ONLY WORK ON A SINGLE TASK. \\
  If the PRD is complete, output <promise>COMPLETE</promise>.")

  echo "$result"

  if [[ "$result" == *"<promise>COMPLETE</promise>"* ]]; then
    echo "PRD complete after $i iterations."
    exit 0
  fi
done

Penjelasan

Element Fungsi
set -e Exit kalau ada error
$1 (iterations) Cap loop supaya nggak runaway costs
-p Print mode — non-interactive, output ke stdout
<promise>COMPLETE</promise> Completion sigil — Claude output ini kalau PRD selesai

Jalankan

# Di dalam Docker sandbox
docker sandbox run claude ./afk-ralph.sh 20

# Atau langsung (kalau nggak pakai Docker)
./afk-ralph.sh 20

Pergi bikin kopi. Balik, udah ada commits. ā˜•


Step 6: Customization Ideas

Ralph itu cuma loop. Simplicity-nya bikin infinitely customizable.

Ganti Task Source

Instead of local PRD, pull tasks dari:

  • GitHub Issues
  • Linear tickets
  • Notion database
  • Apapun yang bisa di-read

Agent tetap pilih task sendiri — kamu cuma ganti di mana list-nya tinggal.

Ganti Output

Instead of commit ke main, setiap iteration bisa:

  • Bikin branch baru
  • Open PR
  • Useful untuk triaging backlog issues

Loop Types Lain

Ralph bisa dipakai untuk berbagai task yang fit pattern "look at repo → improve something → commit":

Loop Type Fungsi
Test Coverage Cari uncovered lines, tulis tests sampai coverage target
Linting Fix lint errors satu-satu
Duplication Hook ke jscpd, refactor clones jadi shared utilities
Entropy Scan code smells, clean up
Documentation Cari functions tanpa docs, tambahin
Dependency Update Update outdated packages satu-satu

Contoh PRD Sederhana

# PRD: Personal Todo App

## Features

- [ ] Setup project dengan Vite + React + TypeScript
- [ ] Buat komponen TaskList
- [ ] Buat komponen TaskItem
- [ ] Buat komponen AddTaskForm
- [ ] Implement add task functionality
- [ ] Implement delete task functionality
- [ ] Implement toggle complete functionality
- [ ] Add localStorage persistence
- [ ] Style dengan Tailwind CSS
- [ ] Add filter (All, Active, Completed)
- [ ] Add search functionality
- [ ] Responsive design
- [ ] Deploy ke Vercel

## Tech Stack
- React 18
- TypeScript
- Tailwind CSS
- Vite

## Notes
- Keep it simple
- One feature per commit
- Test sebelum commit

Tips untuk Ralph yang Efektif

1. PRD yang Jelas

Task yang ambigu = hasil yang ambigu. Tulis task dengan jelas:

  • āŒ "Improve UI"
  • āœ… "Add hover effect ke task cards dengan shadow dan slight lift"

2. Task Size yang Tepat

Terlalu besar = AI overwhelmed, hasil jelek Terlalu kecil = Banyak overhead, lambat

Sweet spot: 1-2 jam kerja manual per task.

3. Selalu Include Tests

Tambahin di prompt:

2. Run your tests and type checks.

Ini bikin AI verify kerjaan sendiri sebelum commit.

4. Set Iteration Limit

Jangan biarkan loop jalan tanpa batas. Set cap:

./afk-ralph.sh 20  # Max 20 iterations

Ini prevent runaway costs kalau ada yang stuck.

5. Review Commits

Setelah loop selesai, review semua commits. AI bisa aja bikin keputusan yang nggak ideal. Kamu masih owner of the codebase.


Workflow Lengkap

1. Brainstorm → Bikin PRD dengan Plan Mode
2. Review PRD → Pastikan tasks jelas dan atomic
3. Human-in-the-loop → Run ralph-once.sh beberapa kali, watch & learn
4. Full AFK → Run afk-ralph.sh dengan iteration limit
5. Review → Cek commits, fix kalau perlu
6. Deploy → Ship!

Kapan Pakai Ralph?

āœ… Cocok untuk:

  • Greenfield projects dengan PRD yang jelas
  • Repetitive tasks (linting, test coverage, docs)
  • Triaging backlog issues
  • Refactoring systematic

āŒ Kurang cocok untuk:

  • Complex architectural decisions
  • Tasks yang butuh banyak context dari discussions
  • Security-critical code (butuh human review lebih)
  • Vague requirements ("make it better")

Penutup

Ralph itu bukan magic. Ini cuma loop sederhana yang leverage kemampuan AI untuk pick tasks dan execute.

Yang bikin powerful:

  • PRD yang jelas — AI tau apa yang harus dikerjakan
  • Progress tracking — AI tau apa yang sudah selesai
  • Incremental commits — Mudah review dan rollback
  • Iteration limit — Prevent runaway costs

Start dengan human-in-the-loop dulu. Build intuition. Baru go full AFK.

Happy looping! šŸ”„

Artikel Terkait

Siap mulai vibe coding?

Pelajari cara membuat aplikasi tanpa perlu pengalaman coding sebelumnya.

Beli Ebook Sekarang