Courses / Build an Autonomous Claude Code AgentProLesson 8 of 94:30

The Stop Hook Sends Work Back

The agent wrote a test and said done without running it. The stop hook ran the test, got red and handed the work back; the agent fixed the code, not the test, and only stopped on green. Then a draft pull request and a reviewer subagent.

Transcript

Okay, let's go into like how you can you can stop your execution. So oftentimes this is one thing which will be asked when your code execution will be stopped, is when you are actually sending an exit code to if you are just exiting, then most probably it will loop again to Claude or loop again to the agent because agentic loop oftentimes have its own retries, it will send what is the error to the agentic loop and it will once again try. Okay, am I able to solve it? We will see that example. let me let me show that we are in the same session, and I'm actually invoking a Claude and prompting a payment key. So just a dummy key here, but it immediately classifies and say, okay, this this never reaches the model actually. This is in the hook itself, it says okay, you are you are inputting something which is which is a key, and you should avoid that and I ask only for a test of a bug and it tell to stop when the test is written. Okay, let's do it again. So add a test to test CLI dot test dots Ts and tell what let's go. So what exactly happened in this is it wrote the test and said done without running anything. The stop hook ran the test and handled it back with red. The test has been created, and the stop hook has run the test which has been written and back. Okay, the test is failing. So let's go back. And now it fixes the code, not the test, only on green was it allowed to stop. So basically it's an agentic loop. What exactly happens is like in our skill, we defined you write the test and you never you know edit the test, rather you go in loop. So in in a production environment, it is not the case. oftentimes you write hold out test separately, and then you you know you test against the code changes so that you can able to identify what are all the things which is actually done, what are all the things which is not done against your agentic run. For this example, it is basically the loop was able to do the test and then it test again against the code without changing anything, and then for that test, the code is red because the code is not written, the test has been written and it was red, and after that it gives back to the agentic loop, and agent loop gets that, and based on that it writes the code and it executed it. Now, if you check the difference, it was able to write the test, and for that test, it was able to write the code as well, and it passes to green. so the agentic loop is complete until the green comes. Okay. Now the draft pull request is opened, it closes the issue. The description is the skills last message. What was wrong? What was the fix, and test was proven done. And then we have our sub agent for review that is the coding code reviewer, which we invoked, and the code reviewer actually reviews the code and and does the code review. It is an isolated sub agent which has its own context, and then we check the code changes as you see the three files which has changed, and it was able to do that.

This lesson comes with Pro, $149 a year: Get Pro. This lesson is cut from the free Lightning session Build an Autonomous Claude Code Agent. The Live Labs build the same system with you, free, on Thursdays: see the Live Labs.