Read the diagram: every prompt in this module has the same structure — a checkable objective, one change per round, run the check, and stop when it passes (or hits the cap). Learn the structure once and change only the core.
🧪 The first loop: failing test
Here’s the cleanest loop to start with: fix failing tests. "Done" is opinion-proof — either the tests pass or they don’t. The prompt below is complete: open a small project with a broken test and paste it in.
Objective: let Claude Code run on its own, in a loop, until the entire test suite passes—making one fix at a time and stopping at the attempt limit.
# Cole no Claude Code dentro de um projeto com testes falhando
Objetivo: faça todo teste em /tests passar ao rodar `npm test`.
Loop:
(1) rode `npm test` e leia as falhas;
(2) abra o arquivo mais responsável pela 1ª falha e faça UMA correção;
(3) rode `npm test` de novo pra verificar;
(4) se ainda falhar, repita do passo 1.
Depois de cada correção que melhora, escreva 1 linha em PROGRESS.md e commite.
Pare quando todos passarem ou após 10 tentativas.
Não edite nada fora de /src e /tests, e não apague testes pra fazê-los passar.
How to verify: watch the terminal — you should see the cycle run tests → edit 1 file → run them again repeating, with the number of failures going down. At the end, run npm test yourself and check for green; open PROGRESS.md and the git log to see the trail from each cycle.
🧩 Why this is the best first loop
It has everything a solid loop needs built in: a machine-checkable goal (npm test), one change per pass, real verification at every step, saved state, and an attempt limit. Master this form, and the other five prompts in this module are variations of it.
✍️ Non-coder version: rewrite text
Loops aren’t just for programmers. The same approach works for text. We changed only the work and how to check it: the goal becomes "rewrite this paragraph," and "done" becomes two objective rules you can count.
Objective: shorten a paragraph until it passes two measurable rules, iterating on its own until it meets them (or stops after 5 attempts).
# Cole no Claude Code (ou em qualquer chat com ferramentas de contagem)
Objetivo: reescreva o parágrafo abaixo.
Pronto quando: o texto está abaixo de 50 palavras E menciona a palavra "preço".
Loop:
(1) reescreva uma versão;
(2) conte as palavras e procure "preço";
(3) se quebrar alguma regra, reescreva de novo mirando o que faltou;
(4) repita.
Pare quando as duas regras passarem, ou após 5 tentativas.
Parágrafo:
<parágrafo que você cola aqui>
How to verify: ask for the final word count (it must be < 50) and look for “price” in the result. Notice: the check verifies the rules, not whether the text was pleasant to read—that is exactly a Functional check. If you want elegance too, you would add a second evaluator (topic 6).
🎚️ /goal e /loop in Claude Code
Instead of writing the loop by hand every time, you can declare the goal and let Claude Code build the cycle. /goal says where to end up; /loop keeps it running until then. Together, they become a self-directed loop that knows when to stop.
Objective: generate and refine thumbnail concepts until one reaches the target score on a rubric you define yourself.
# Cole no Claude Code
/goal Gerar 10 conceitos de thumbnail para um vídeo sobre <seu tema>.
Pontue cada conceito de 0 a 10 em três critérios:
- clareza (dá pra entender o tema em 1 segundo)
- contraste (cores e formas saltam num feed)
- curiosidade (dá vontade de clicar)
A nota do conceito é a média dos três.
Pronto quando o melhor conceito atingir nota média >= <8>.
/loop A cada volta: pegue o conceito de maior nota, descreva 2 variações
dele mirando o critério mais fraco, pontue as variações pela mesma
rubrica e mantenha a melhor. Pare quando bater a nota-alvo ou após
8 voltas. Mostre a tabela de notas no fim.
How to verify: At the end, a table should show each concept and its three scores, and the winner with an average ≥ 8 (or a notice that it stopped at the limit without reaching it). Check for yourself that the rubric was applied consistently—if two similar thumbnails received very different scores, tighten the description of the criteria.
🔒 Human gate for risky tasks
When the loop can touch something that’s painful to undo—delete files, send email, make a payment—you don’t want it deciding on its own. Add a human gate: a line that requires the agent to stop and ask for your confirmation before any irreversible action.
Objective: run a loop as usual, but with a brake that prevents any destructive or external action without your explicit approval.
# Acrescente esta linha a QUALQUER prompt de loop deste módulo
Pause e me pergunte antes de deletar, enviar ou pagar qualquer coisa.
# (opcional, deixa o gate mais explícito)
Trate como irreversível: apagar/sobrescrever arquivos fora de /src,
fazer git push, enviar e-mail/mensagem, ou qualquer pagamento.
Nesses casos, descreva o que faria e espere meu "ok" antes de agir.
How to verify: run the loop on a task that naturally leads to a risky action (e.g., cleaning up a folder). The agent should stop and ask instead of executing—if it deletes something without consulting you, the gate didn’t catch it: make the list of irreversible actions more specific and test again in a toy directory.
💡 Use this on your first run, always
At the start, scope permissions to the minimum (edit /src and /tests, run tests) and put this gate on top. The loop works; the merge, push, and send are up to you. It’s cheap to add and saves you from irreversible damage while you’re still learning to trust the loop.
💾 Loop with PROGRESS.md + commits
Big tasks don’t fit in a single pass. The solution is to give the loop a place to store state: a progress file that it reads at the start and updates at the end of each pass, plus one commit per change. That way, if the session ends, the next one picks up where it left off.
Objective: run a long loop that advances one feature at a time, saving state after each pass so it can be interrupted and resumed without losing work.
# Cole no Claude Code num repositório git
Objetivo: implementar <a feature/lista de tarefas> até estar completa e testada.
No início de cada volta:
- leia PROGRESS.md para saber o que já foi feito e o que vem a seguir.
Durante a volta:
- escolha a PRÓXIMA tarefa não-feita e trabalhe SÓ nela (uma de cada vez);
- rode os testes para verificar a mudança (self-verify);
- se passou: atualize PROGRESS.md (marque a tarefa, anote 1 linha do que fez)
e faça um commit com uma mensagem curta e clara;
- deixe a árvore de trabalho limpa (sem arquivos soltos) para a próxima volta.
Pare quando PROGRESS.md não tiver mais tarefas, ou após 15 voltas.
How to verify: open PROGRESS.md and watch the history grow line by line; run git log --oneline and check one commit per change. The acid test: interrupt the loop midway, start a new session with the same prompt, and see whether it resumes at the right task instead of starting over from scratch.
🧩 Adapting the template to your task
All the prompts in this module use the same skeleton with different parts swapped out. For YOUR task, keep the loop structure and change only two things: the domain (what work) and the checker (how to measure "ready").
What to look at: the flow is always copy → paste → run → observe. What changes from task to task isn’t the mechanics, but the fields <between arrows>: the goal, what counts as done, and the limit.
The three types of checkers you'll switch between depending on the task:
⚙️ Functional
Objective rules: tests pass, < 50 words, build compiles. Yes/no answer.
🖼️ Visual
Take a screenshot and compare it with what you expect: layout, color, "did the button appear?".
🧑⚖️ Judgment
A second agent scores a rubric (tone, clarity) until it passes. For subjective quality.
Objective: have a blank template to fill in with your task — just change the marked fields <assim> and paste it.
# Template em branco — preencha os campos <entre setas> e cole no Claude Code
Objetivo: <o que produzir, numa frase>.
Pronto quando: <o critério checável de "pronto">.
Loop:
(1) faça UMA mudança em direção ao objetivo;
(2) rode o check: <como medir — testes / contar / screenshot / 2º agente>;
(3) se não passou, ajuste mirando o que faltou;
(4) repita.
Salve o progresso: <ex.: 1 linha em PROGRESS.md + commit a cada melhora>.
Pare quando passar, ou após <N> tentativas.
Não toque em <o que está fora de escopo>; pause e me pergunte antes de
qualquer ação irreversível.
How to verify: if you were able to fill in the four fields without hesitation — objective, completion criteria, which checker, and the cap — your task is ready to become a loop. If you got stuck on "Done when," the problem isn't the prompt: the task doesn't yet have a checkable "done" state (go back to module 3.1, step 2).
When adapting the template for a new task, what do you change?
🧾 Module Summary
Next:
3.3 — 8 ingredients of a solid loop