claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Hangs until timeout for non-terminating CLI commands

Open brennancheung opened this issue 7 months ago • 2 comments

There are a few scenarios where Claude Code will try to run non-terminating processes such as:

  • npm run dev
  • pnpm dlx convex dev

When it does run these, Claude will hang and then eventually time out but it wastes significant time while the agent is paused waiting for it and also it doesn't seem to actually see the output either.

The workaround is to tell Clause not to run these and then manually run them outside of Claude. But this really slows down work and causes unnecessary human interaction.

npm run dev will frequently require restarts and can't simply be run in a separate terminal tab that I forget about. I have to frequently restart it when Claude edits files because it gets in a corrupt state (missing files / renaming files that used to be there is one scenario I think).

The other use case I'd like to have be more automated / agentic is having Claude start up the dev server and then check the rendered page using something like BrowserMCP or equivalent.

Are there any good workarounds or plans to solve this problem?

brennancheung avatar Jun 17 '25 07:06 brennancheung

I was thinking through some possible solutions for this. 1 might be to allow child invoked processes to be piped into Claude and streamed. So basically they run in the background and Claude manages starting and stopping them.

Another cleaner way might be something completely outside of Claude and moved into an MCP server that Claude can use to start, stop, view logs, extract URL (especially important when running parallel worktrees on different ports).

brennancheung avatar Jun 17 '25 21:06 brennancheung

Best solution: Tell your agent to make all the npm/etc commands it uses self-terminating. So your npm run should terminate after everything is started. Your log commands should be head/tail-based. Doing this eliminated my 2 min waiting periods. Make sure CLAUDE.md contains instructions for those commands.

clharman avatar Jun 20 '25 19:06 clharman

I ended up creating an MCP server to solve this use case. For anyone else that wants to try it out it is available here:

https://github.com/brennancheung/mcp-rewatch/#readme

Image

Image

brennancheung avatar Jul 03 '25 18:07 brennancheung

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Oct 10 '25 10:10 github-actions[bot]

Hi - Claude Code is now able to run long-running tasks in the background and can check on the logs from that task.

catherinewu avatar Nov 30 '25 03:11 catherinewu

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Dec 07 '25 14:12 github-actions[bot]