claude-code - 💡(How to fix) Fix Agent awareness of long-running background Bash processes (RAM pressure) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#53005Fetched 2026-04-25 06:14:58
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Fix Action

Fix / Workaround

I use web new experience beta Claude Code (agent mode) to drive a domain-specific CLI tool — a ~14,000-line Java/ASM fat-jar called ClaudePatcher that statically analyzes 355-jar Minecraft Forge modpacks (~65k classes). Each invocation is a separate JVM process consuming 1.5–2 GB RAM.

Workaround I'm building locally

RAW_BUFFERClick to expand / collapse

What happened

I use web new experience beta Claude Code (agent mode) to drive a domain-specific CLI tool — a ~14,000-line Java/ASM fat-jar called ClaudePatcher that statically analyzes 355-jar Minecraft Forge modpacks (~65k classes). Each invocation is a separate JVM process consuming 1.5–2 GB RAM.

During a session, the agent sometimes launches the same heavy command multiple times for timing tests / verification, without realizing previous background processes are still running. Seen today: 3 concurrent java processes × 1.5 GB each on a box without that headroom → memory thrashing → a command that finishes in ~15 s alone took 14 minutes before being killed.

The root problem: the agent has BashOutput and KillShell for shells it explicitly tracks, but no mechanism to see "what heavy processes are live right now" or to be warned before launching a new one.

Requests

  1. Surface pre-launch signals to the agent: running-process summary and available RAM, especially before Bash calls expected to be long / memory-heavy (or tagged run_in_background: true).
  2. Auto soft-kill or explicit warning for duplicate invocations: "a previous java -jar X ... is still running, continue? / will this thrash?"
  3. Expose a tool like "list my active background shell IDs" to the agent (currently it must self-track).

Workaround I'm building locally

A PreToolUse hook matching Bash that shells out to ps/free and returns {"decision":"block","reason":...} when the command matches a heavy-pattern AND a previous instance is already alive. Happy to share the script if useful as a community example.

Env

Claude Code web/IDE session (no terminal), ~April 2026 session date. Observed on a modpack with 355 mods

extent analysis

TL;DR

Implement a pre-launch check to detect running heavy processes and available RAM before launching new commands, potentially using a PreToolUse hook with ps and free commands.

Guidance

  • Consider using the PreToolUse hook to run a script that checks for running processes and available RAM before launching a new command, as described in the workaround.
  • Use ps and free commands to gather information about running processes and available RAM, and return a decision to block or proceed with the command.
  • Implement a mechanism to detect and warn about duplicate invocations of heavy commands, such as checking for running instances of java -jar commands.
  • Expose a tool or API to list active background shell IDs to the agent, to improve tracking and management of running processes.

Example

# Example PreToolUse hook script
if [ "$(ps -ef | grep java | grep -c ClaudePatcher)" -gt 0 ]; then
  echo '{"decision":"block","reason":"Previous instance of ClaudePatcher is still running"}'
else
  echo '{"decision":"proceed"}'
fi

Notes

The provided workaround using a PreToolUse hook with ps and free commands seems promising, but may require additional error handling and edge case consideration.

Recommendation

Apply workaround: Implement the PreToolUse hook with ps and free commands to detect running heavy processes and available RAM, as it provides a concrete solution to the problem of duplicate invocations and memory thrashing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Agent awareness of long-running background Bash processes (RAM pressure) [1 comments, 2 participants]