Torna al Blog

Claude Code kept getting stuck while I was AFK — here's how I fixed it with hooks

In my previous post I talked about building an MCP server to let Claude Code ask me questions via Slack. Our prototype was working… so nice!

It was time to test it more “deeply”, so I passed Claude Code a long enough prompt to keep it busy for a while, and as part of the prompt, I asked it to run the command to enable interaction via Slack (/lassare-slack). Waited a bit, was working, time to go to the gym.

It asked me a couple of questions during the walk to the gym… then nothing more. I waited, and waited… and waited… nothing. What happened?!

Completed my workout, back at my laptop.

Claude Code was waiting for me to approve a “git reset” (a reset that I didn’t ask it to do BTW 🤦🏻‍♂️). Permission prompts are a local thing — they show up in the terminal, not in Slack. So there was no way for me to approve or deny from my phone.

Claude Code permission prompt waiting for approval

Now what?!?

HOOKS! Yes, let me try using hooks.

💡 What are hooks? Claude Code has a feature called hooks — scripts that run automatically when certain events happen, like when the agent needs permission or when it’s about to stop.

So I started with identifying the right hook (it was clearly “PermissionRequest”) then the hook configuration, creating a couple of scripts, adding a few more instructions into CLAUDE.md. A few back and forths but it worked. Very good.

Did a few more rounds of tests, I was really happy with the results. Next day, same drill… I gave Claude Code a few instructions and asked it to move to Slack. Waited a few minutes, was working, it asked me a couple of approvals and it kept working.

Back to the gym (no, I don’t go to the gym every day!), doing my workout, one more question answered… then stopped. Again?!? That was depressing.

Working out at the gym while Claude Code works

Finished my workout, back to my laptop… Claude Code finished what I asked it to do and was there, waiting for me to tell it what to do. Here we go again…

Same playbook… I need another hook! “Stop” hook. A couple more scripts, a lot of tests (this one wasn’t easy, it might deserve a dedicated blog post I think) and now Claude Code can ask what else it should do when it’s going to stop. Pretty cool, right?

Approving from the gym via Slack

I was really able to let Claude Code work while AFK, on multiple tasks.

Time to make it work with other AI Coding Agents, decided to focus on Cursor first and maybe Gemini CLI, but this is for the next post I guess.

You wanna have a look at our “final” (so far) configuration of hooks and scripts? Have a look at our GitHub public repo lassare-hq/agent-configs and then give lassare a try: lassare.com.