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

Published: (March 9, 2026 at 05:21 AM EDT)
3 min read
Source: Dev.to

Source: Dev.to

The Issue: Claude Code Gets Stuck When I’m AFK

In a previous post I described building an MCP server that lets Claude Code ask me questions via Slack. The prototype worked nicely, so I decided to give it a longer prompt that would keep it busy for a while and included the command to enable Slack interaction (/lassare‑slack).

I started the run, headed to the gym, and the agent asked a couple of questions during my walk. After that, it went silent. I waited, but nothing happened.

When I returned from my workout, Claude Code was waiting for me to approve a git reset—a reset I never requested. Permission prompts are displayed locally in the terminal, not in Slack, so I couldn’t approve or deny them from my phone.

Coding Agent getting stuck waiting for approval (HITL) – Lassare lets you approve it remotely while AFK

First Attempt: Using Hooks

What are hooks?

Claude Code supports hooks, which are scripts that run automatically when specific events occur (e.g., a permission request or an imminent stop).

Implementing the PermissionRequest hook

  1. Identify the relevant hook (PermissionRequest).
  2. Add the hook configuration to CLAUDE.md.
  3. Write a small script that automatically approves the request.
  4. Test the setup.

After a few iterations, the agent could approve the permission request without my manual input, and the run continued successfully.

The Next Problem: Stopping Mid‑Run

The following day I repeated the test. The agent again asked for approvals, but after a short pause—while I was still at the gym—it stopped unexpectedly.

At the gym, while AI coding agent keeps working

Adding a “Stop” Hook

To handle this, I created a Stop hook:

  1. Define the Stop hook in the configuration.
  2. Write a script that prompts the agent for further instructions before it terminates.
  3. Run extensive tests (this part was more involved and could merit its own blog post).

With the Stop hook in place, Claude Code now asks what to do next whenever it’s about to finish, allowing it to keep working while I’m away.

Approving AI coding agent to use tool via Slack, leveraging hooks

Results

  • Claude Code can now operate autonomously for extended periods, handling permission requests and graceful shutdowns without my immediate presence.
  • The same hook‑based approach works with other agents such as Cursor, Gemini CLI, and GitHub Copilot, using the same MCP server and Slack integration.

Resources

  • GitHub repository with the final hook and script configuration:
  • Try Lassare:
0 views
Back to Blog

Related posts

Read more »

The Enablers Who Helped Me Code Forward

This is a submission for the 2026 WeCoded Challengehttps://dev.to/challenges/wecoded-2026: Echoes of Experience Sometimes the difference between giving up and m...

Design Thinking : Define

Define Phase After understanding the user, the next step is to synthesize that knowledge into tools such as empathy maps and personas. Empathy Map An empathy m...