I recently finally got Claude Hooks working and they’re the missing piece to get fully autonomous agents that can work for hours continuously.

Hooks are still super buggy

Hooks have been around for about 6 months but they are really hard to get working for some reason. Even running claude with --debug doesn’t give you a great idea of why they aren’t working.

Up until now, to get my agents to work around the clock, I would tell them to work continuously until the GitLab Pipeline is green and I would wrap their command to check the pipeline with one that was blocking until the pipeline is finished. This is necessary since Agents love to return and say that the pipeline needs more time which breaks the flow. The Stop hook lets me run those commands for the agent, and keeps them working.

My current setup is an escalation of 3 different Stop’s. The first is checking that the pipeline is green, the second is checking the MR description for unfinished TODO’s, and the final lets the Agent break the loop by going into plan mode. I use the Merge Request as a source of truth since its more traceable than a plan written by Claude, and it keeps me from accidentally pushing a todo.md to main. Telling Claude to go into plan mode is a shortcut for now, but you likely will always need some way for your Agent to break out of its loop if its actually stuck or the task is impossible. In the future I want to have an oracle or maybe a CEO Agent that can review where things are at and make some of these decisions for me. I think with subagents in the mix I’m a manager, but with hooks I can get to the director level.

You might need to change the permissions on your hooks to keep Agents from cheating.

Future Ideas

Hooks are pretty exhaustive, you can hook into anything I could think of needing. Here is the complete list and some ways I want to use them in the future:

  • PreToolUse
    • I think this could be a good second layer to make sure Claude isn’t operating out of the bounds that are set for it.
  • PermissionRequest
    • This could generate an audit log if running in a secure environment, but probably too risky over other tools
  • PostToolUse
    • You could format or lint but that might muddy up your Agents context or cause confusion
  • Notification
    • Theres a matcher for 60s of idle time which would be really cool to hook into something like Telegram to give me notifs
  • UserPromptSubmit
  • Stop
  • SubagentStop
    • This could be powerful for pairing cheap/fast Agents with smarter ones. Have the smarter agent be the judge on if the cheap one actually completed the task or if it should keep going.
  • PreCompact
    • Keeping a concise bug exhaustive work log over long sessions is really hard and I think having a separate agent do a compaction against a MR description or something could be powerful. A big outstanding question at my job is how we understand Agents implementations so this could help with that.
  • SessionStart

  • SessionEnd