AI Tip #4 · The Long Version

Hooks and loops, or how a chat becomes an assistant that runs itself.

Running Claude in the terminal lets you change how the AI runs, not just what you ask it. Here is what that actually looks like in my setup, and the part where I crashed my computer a few times.

Ethan Brace · Brace Yourself Solutions 2026 · 07 · 16
01 — The Idea

You stop asking the AI things and start changing how it runs.

A chat window lets you talk to the model. A terminal lets you rewrite the rules of the game around it.

Most people meet AI through a chat box. You type, it answers, it waits. That is a conversation, and conversations are one turn at a time.

When you run Claude in the terminal instead, something changes. You get to reach in and decide what happens automatically before it acts, after it acts, and even whether it is allowed to stop. You are no longer just choosing the words. You are choosing the reflexes.

Two small levers do almost all of the work: hooks and loops.
Hooks
Little scripts that fire on their own at set moments. The AI's reflexes and guardrails. You do not ask for them. They just happen.
Loops
The session wakes itself back up and keeps going. A one-shot answer becomes a worker that grinds through a list for hours and only pings you when it is genuinely stuck.

Put them together and a simple chat turns into something that supervises itself, refuses to cut corners, and emails you when it needs a decision. The catch, and it is a real one, is that the moment it can spawn its own helpers and run unattended, it can also cheerfully spawn seventy of them at once and take the whole computer down. We will get there.

02 — Hooks

The reflexes: things that fire without being asked.

A hook is a command the terminal runs for you at a specific moment in the AI's turn. Think seatbelts and muscle memory, not instructions.

There are a handful of moments a hook can grab onto: when a session opens, right after you hit enter but before the AI reads your message, right before it uses a tool, right after, and the important one, when it is about to go idle and stop. My setup wires up dozens of these. Here are the ones worth meeting.

Hook · a rule with teeth
You literally cannot skip the tests
fires before an edit, and again when it tries to stop

One hook watches every attempt to edit a code file. If there is no test for that file yet, the edit is blocked before it happens. The AI is forced to write the test first. A second hook fires when the AI thinks it is finished: it runs the whole test suite and refuses to let the session stop if anything fails.

Why it matters: AI coding assistants have a famous bad habit of quietly deleting a safety check just to make a test pass, then announcing "done." These two hooks make that structurally hard. Tests have to exist before the code, and pass before the work can rest. It is the difference between an assistant that says it did the work and one that had to prove it.

Hook · manners
Stop emailing me the same question
fires before sending an email

Whenever the AI tries to send me an email, a hook checks one thing: did I already write to this person and not hear back yet? If so, it blocks the second message and tells the AI which threads are still open.

Once you let an assistant send email on its own, the nightmare is inbox flooding: five messages before you have replied to the first. This encodes a social rule, not a technical one. One open question per person, wait for the human. A genuine emergency marked urgent still sails straight through, so a real alert never gets trapped behind politeness.

Hook · memory
Load the right context before you answer
fires the instant you hit enter, before the AI reads you

Before the AI even sees my message, a hook looks at what I am asking and which project I am in, then quietly pulls in the relevant notes, past lessons, and house rules from my memory files and hands them over. A small local model picks which few notes are worth loading so it stays cheap.

This is what makes it feel like it knows me. I do not re-explain my infrastructure or my preferences or the thing we learned last Tuesday. A generic chat forgets. A hook-wired terminal briefs itself before it opens its mouth.

Hook · seatbelts
Do not wreck the computer
fires before running a command

A cluster of small hooks act as bumpers: block any command that would wipe a database, refuse to read password and secret files so they never end up in a transcript, honor a "this client's repo is read-only" agreement so autonomy never crosses a line someone agreed to, and cut off a helper that runs a command which never exits.

Guardrails are the price of autonomy. The more you let the AI act on its own, the more you want automatic reflexes for the handful of actions you can never take back.

A last honest note: guardrails that cry wolf get switched off. One of mine kept blocking legitimate work and once killed a fourteen-minute build, so I disabled it. You tune these like reflexes, not like laws.
03 — Loops

The part where it stops waiting for you.

Normally the AI answers and then stops. A loop breaks that: the session schedules its own next wake-up and hands itself the next instruction, over and over.

The whole trick behind turning a chat into a worker is this: it no longer needs you present to take the next step. It can set an alarm, wake up, look at what needs doing, do it, and set another alarm. Here are the three flavors I actually run.

A. The email loop

A per-project loop wakes every thirty minutes and checks my inboxes for replies to threads the AI itself started. When a reply lands, it spins up a helper to act on it. So the assistant can email me a question, go dormant, and pick the conversation back up the moment I answer, even hours later. A pen pal that never forgets to check the mailbox.

B. The goal loop

Lock a session to one north-star goal and let it drive itself to done. It pins the goal to a file, builds a checklist, and wakes itself on a timer. The clever part: on every wake it asks a separate evaluator AI a blunt question, "am I still driving at the goal, or am I polishing something that does not matter?" The evaluator names the single most valuable next action and the loop does it. It is an assistant with a built-in manager tapping it on the shoulder each cycle.

C. The backlog loop

The go-AFK, keep-working mode. Point it at the to-do list and it picks the highest-value item, does it properly (tests first, an independent skeptic AI checks the work, a real end-to-end verification), ships it if it passes, and moves on. It only interrupts me when it hits something a human genuinely must decide: a password it cannot hold, a message it cannot un-send, a real judgment call. Everything reversible, it just does.

Its prime directive is my favorite line in the whole system: an honest FAIL beats a claimed pass. In one 24-hour run it caught six of its own "done" claims that were actually false.

Underneath, several of these run as always-on background sessions, one per project, kept warm so they react to an email reply or a scheduled tick instead of starting cold. That is what makes it feel like a standing assistant rather than a tool you launch. There is a version of it quietly resident, waiting, for each project.

04 — Careful Though

The honest part: I have crashed my computer a few times.

The failure mode is not the AI going rogue. It is the AI being too eager to work in parallel with nothing capping it. Give it the ability to spawn seventy workers and it will, gladly, at 2am, all at once.

Sessions at once
17
warm sessions, no memory limit, ate 64GB of RAM. Hard reboot.
Load average
500
one hook fired a full build on every push; ~100 pushes, ~100 builds.
Test workers
76
firing simultaneously, uncapped, from a single command.

Within a single 24-hour stretch the same root cause surfaced four separate ways: a build process that ballooned to 27GB, a monitoring loop that ran 7.5 hours with no time limit, the 100-build pile-up above, and a local model that quietly climbed from 12GB to 23GB overnight until it ran the machine out of memory.

The lesson I wrote down and now live by: nothing is capped by default. The absence of a limit is a bug, not a default.

The fix was boring and correct: put a hard ceiling on the whole family of processes so every session and helper inherits it, then hunt down the holes (anything a scheduled job launched escaped the fence and had to be wrapped on its own). Now every new long-running thing gets a memory cap, a time limit, and a CPU cap. Always.

That is the real trade. Hooks and loops let you hand the AI real autonomy and real horsepower. The moment you do, you become the one responsible for the seatbelts. Worth it. Just cap everything first.

05 — Cheat Sheet

The whole thing on one page.

If you skimmed everything else, this is the part to keep.
KindWhat it isFiresWhy it is worth it
HookTest-first enforcerbefore an edit, and at stopCan't touch untested code, can't finish on broken code.
HookBounded emailbefore a sendNo second message before you reply to the first. Manners.
HookContext injectbefore it reads youAuto-loads the right memory. It already knows your world.
HookSeatbeltsbefore a commandBlocks data-wipes, secret reads, runaway commands.
LoopEmail loopevery 30 minChecks the inbox, resumes the moment you reply.
LoopGoal loopself-pacedDrives one goal, a manager AI checks it stays on target.
LoopBacklog loopself-paced, AFKGrinds the to-do list, escalates only when truly stuck.
RuleCap everythingalwaysMemory, time, and CPU limits on every long-running thing.

None of this requires being a programmer to understand. It is the same move over and over: take a moment in how the AI runs, and decide what should happen automatically. Do that a few dozen times and the chat quietly becomes a colleague.