Skip to content

Add memory-alert plugin for Claude Code process memory monitoring#38728

Open
tiwari91 wants to merge 2 commits intoanthropics:mainfrom
tiwari91:add-memory-alert-plugin
Open

Add memory-alert plugin for Claude Code process memory monitoring#38728
tiwari91 wants to merge 2 commits intoanthropics:mainfrom
tiwari91:add-memory-alert-plugin

Conversation

@tiwari91
Copy link
Copy Markdown

@tiwari91 tiwari91 commented Mar 25, 2026

Summary

  • Adds a new memory-alert plugin that monitors Claude Code's own process memory and alerts in the terminal when it exceeds a configurable threshold
  • Sums RSS (resident set size) of all running claude processes via ps
  • Works on both macOS and Linux
  • Uses a PostToolUse hook — lightweight check runs after each tool call
  • Default threshold is 5GB, configurable via MEMORY_ALERT_THRESHOLD_GB environment variable
  • Non-blocking: alerts are informational only, never interrupt workflow

Plugin structure

plugins/memory-alert/
├── .claude-plugin/
│   └── plugin.json
├── hooks/
│   ├── hooks.json
│   └── scripts/
│       └── memory-alert.sh
└── README.md

Example output

[MEMORY ALERT] Claude Code memory usage: 5.2GB (threshold: 5GB) — consider closing idle sessions

Test plan

  • Tested on macOS (Darwin) — correctly sums Claude process RSS and alerts above threshold
  • Verified alert is silent when memory is below threshold
  • Verified MEMORY_ALERT_THRESHOLD_GB env var overrides the default
  • Test on Linux

Adds a PostToolUse hook plugin that monitors system memory usage
(macOS + Linux) and alerts in the terminal when it exceeds a
configurable threshold. Default threshold is 5GB, customizable
via MEMORY_ALERT_THRESHOLD_GB environment variable.
Switch from tracking system-wide memory (vm_stat/meminfo) to summing
RSS of Claude CLI processes via ps. This gives users accurate alerts
about Claude's own memory footprint rather than total system usage.
@tiwari91 tiwari91 changed the title Add memory-alert plugin for system memory monitoring Add memory-alert plugin for Claude Code process memory monitoring Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant