Hand Back a Pull Request

In the last lesson, you built a command that runs issue #4 with nobody watching and tried it once while you watched. That trial ended with a report in your terminal and changes in your working folder, and you were there to read both. Tonight, nobody will be there to read anything. Something still has to decide whether the agent’s work is kept, and that decision can’t be the agent’s own.

In this lesson, you’ll write the script that runs issue #4 unattended and decide what it hands back: a branch, your own test run, and a pull request that you review before anything reaches main. Start with the script most people write first.

Trust the Exit Status

A script around your command needs a rule for when to keep the run’s work. The first rule that comes to mind is the convention every shell script already follows: a program that exits with status 0 succeeded.

First, copy the command you saved in the last lesson into a file called issue-4-command.sh in your home folder, outside the repository. With the command in its own file, every script in this lesson can start the run with sh ~/issue-4-command.sh, whichever agent you use. A natural first script then looks like this:

Language: Shell Filename: nightly-issue-4.sh
#!/bin/sh
sh ~/issue-4-command.sh
if [ $? -eq 0 ]; then
  git commit -am "Add instruments category" && git push
fi

$? holds the exit status of the command before it, so this script commits and pushes to main whenever the run exits with 0. Schedule it for 2 a.m., and it looks finished. Before you read on, decide what could be on GitHub’s main by morning after a run that exited with 0.

An exit status of 0 says the run itself completed: the agent started, worked, printed its report, and stopped without crashing. It says nothing about whether the task is done. Behind that zero, any of these can be waiting:

  • A blocked test command: Claude Code refused the agent’s call to run the tests, or Codex’s sandbox blocked it. Either way, the run carried on. The agent edited files without seeing a test result, and the script pushed untested edits.
  • A partial task, reported honestly: The final report says, “I added the category but couldn’t get the test to pass.” Nobody reads it, and the script pushes anyway.
  • A change outside the limits: If your agent’s sandbox limits where it writes but not which files it changes, “Change only” is an instruction that nothing enforces, so a run can touch a file the task never mentioned.

And every one of them lands on main with no person in between.

The exit status answers “Did the agent’s process end normally?” The question you care about is “Is this change right?” and only checks outside the agent can answer that.

Look Behind Your Own Run’s Zero

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.