We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Canceling

One of the easiest ways to make @sama a lot of money waste tokens with coding agents is to let a bad loop continue for too long.

If you're watching your agent work (and let's be frank, most of the time you actually shouldn't be), you'll see the tools it's calling, the changes it's making, and the reasoning it's producing in real time. If something looks off, press Esc twice to cancel the loop.

Just correct the bad behavior with a new prompt and try again. Canceling preserves the conversation context and doesn't undo changes already made.

After I fire off a prompt I usually tab away to work on something else (that's one of the main productivity boosts of using an agent). That said, sometimes I hang around for about 10 seconds, especially if it's a particularly large task, just to make sure things got off to a good start.

Adding a Cancel Condition

Another big-brain strat is to bake a "cancel condition" directly into your prompt. This is super useful if the start of the task is "research" and the next step is "implement". If the research comes back with less than optimal results, you want the agent to stop and ask you what to do next, rather than blindly implement a bad plan. For example:

If you can't find an API endpoint that matches the functionality we need, pause and ask me what to do next.