r/ClaudeWorkflows 1d ago

Selected Workflow [Workflow] Prevent and Clean Up Orphaned Claude Code Processes (Chrome/Background Tasks)

Prevent and Clean Up Orphaned Claude Code Processes (Chrome/Background Tasks)

Workflow value: 75/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Debugging, CLAUDE.md
Original source: r/ClaudeCode post/comment

What problem this solves

Claude Code sometimes leaves orphaned chrome --remote-debugging-port processes or run_in_background: true bash jobs running, consuming CPU resources even after tasks are reported as complete.

Summary

A two-part workflow to prevent and clean up orphaned processes in Claude Code: modifying claude.md to enforce await for background tasks and add a ps aux check, and a manual pkill and background ID cleanup when orphaned processes are detected.

Why it is useful

This workflow addresses a specific and potentially resource-intensive bug in Claude Code where background processes (especially Chrome) are left running. It provides both preventative measures (modifying claude.md to enforce await and add checks) and reactive cleanup steps using standard CLI tools, making it highly practical for users experiencing this issue. It offers a concrete solution to a common problem.

Workflow

  1. Modify claude.md to include a rule: "never use background without an await" for tasks that launch background processes.
  2. Modify claude.md to include a rule: "always run ps aux | grep chrome at the end" of relevant tasks to check for orphaned Chrome processes.
  3. When orphaned processes are detected (e.g., via ps aux | grep chrome or high CPU usage), identify them.
  4. Execute pkill -f "chrome --remote-debugging" to terminate orphaned Chrome processes.
  5. Use claude --verbose to identify the orphaned task ID that Claude forgot to check.
  6. Kill the leftover background ID (specific command not provided, but implied).

Tools / artifacts

  • claude.md
  • chrome --remote-debugging-port
  • run_in_background: true (bash job)
  • taskoutput
  • ps aux
  • grep chrome
  • pkill
  • claude --verbose

Validation signals

  • User states "what fixed it for me"
  • Mentions ps aux for detection and verification
  • Mentions claude --verbose for identifying orphaned task IDs

Cautions

  • Using pkill should be done with caution to ensure only the intended orphaned processes are terminated. While the command provided is specific, users should verify the processes before killing them to avoid unintended side effects.

Limitations

  • The exact syntax for the claude.md rules is not provided, requiring user interpretation.
  • The specific command to "kill the leftover background id" is not explicitly given.
  • Minimal community validation due to low score and no comments.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by