Install command
Provided
Monitors memory usage and alerts when thresholds are exceeded.
Open the source and read safety notes before installing.
Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.
Decision playbook
Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.
0
78
—
No baseline selected
No major trust-signal divergence detected in the current selection.
Confirm ownership and provenance before trusting install instructions.
Source link availableRequired
Open the canonical repository and verify ownership.
Source provenance statusRequired
Marked as source-backed.
Metadata reviewed
Registry metadata indicates a reviewed listing.
Validate risk disclosures before installation or API wiring.
Safety notes presentRequired
Review the listed safety guidance before running commands.
Privacy notes presentRequired
Review data handling notes before connecting accounts or secrets.
Trust level risk gateRequired
Trust level does not block evaluation.
Check package metadata and artifact integrity signals.
Install payload available
Install or copy payload is available for review.
Package verification flag
No package verification flag provided.
Checksum metadata
No checksum provided for downloaded artifact.
Use compare context to validate trade-offs before adoption.
Compare tray has multiple entries
Add at least one more entry to compare trust differences.
Baseline comparison available
No baseline peer selected yet.
Diverging trust signals identified
No major trust-signal divergence found.
Setup at a glance
Copy-ready — paste the snippet to get started.
Install command
Provided
Config snippet
Provided
Copy snippet
Provided
Prerequisites
None
Platforms
1 listed
Difficulty
0/100
Adoption plan
Current risk score 16/100. Use staged verification before broader rollout.
Validate source and review signals before any execution.
Confirm source provenanceRequired
Source URL/provenance metadata is present.
Confirm metadata review state
Listing has review metadata.
Verify install payload
Install/config payload exists and can be inspected.
Confirm safety, privacy, and package integrity signals.
Review safety notesRequired
Safety notes are present.
Review privacy notesRequired
Privacy notes are present.
Verify package integrity metadata
No package verification/checksum metadata.
Adopt in controlled steps based on the selected plan.
Run in isolated sandbox firstRequired
Use a constrained sandbox and observe behavior across multiple tasks.
Roll out graduallyRequired
Roll out to a small cohort before wider usage.
Set monitoring and fallback
Define rollback path and monitor errors after adoption.
Evidence readiness
Required evidence gates are covered (5/6 signals complete).
Source repository/provenance is listed.
Required in this preset
Review metadata is present.
Required in this preset
Safety notes are present.
Required in this preset
Privacy notes are present.
Optional in this preset
Package integrity metadata is missing.
Optional in this preset
Install payload is available.
Required in this preset
Required evidence gates are covered for this preset.
Decision timeline
5/6 steps complete with no blocking gaps for this preset.
triage
Source/provenance metadata is available.
triage
Review metadata is available.
verify
Safety notes are available.
verify
Privacy notes are available.
verify
Package integrity metadata is missing.
rollout
Install payload is available.
No required blockers for this timeline preset.
Safety & privacy surface
1 safety and 1 privacy notes across 2 risk areas. Review closely: credentials & tokens, permissions & scopes.
#!/usr/bin/env bash
# Memory Usage Monitor Hook
# Monitors system and process memory usage during development activities
echo "💾 Memory Usage Monitor" >&2
# Initialize monitoring variables
TOTAL_MEMORY_KB=0
USED_MEMORY_KB=0
MEMORY_PERCENT=0
SWAP_PERCENT=0
HIGH_MEMORY_THRESHOLD=75
CRITICAL_MEMORY_THRESHOLD=90
HIGH_SWAP_THRESHOLD=25
WARNINGS=0
ERRORS=0
# Function to report memory status
report_memory() {
local level="$1"
local message="$2"
case "$level" in
"ERROR")
echo "❌ CRITICAL: $message" >&2
ERRORS=$((ERRORS + 1))
;;
"WARNING")
echo "⚠️ WARNING: $message" >&2
WARNINGS=$((WARNINGS + 1))
;;
"INFO")
echo "ℹ️ INFO: $message" >&2
;;
"PASS")
echo "✅ OK: $message" >&2
;;
esac
}
# Function to format bytes to human readable
format_bytes() {
local bytes=$1
local units=("B" "KB" "MB" "GB" "TB")
local unit=0
while (( bytes > 1024 && unit < 4 )); do
bytes=$((bytes / 1024))
unit=$((unit + 1))
done
echo "${bytes}${units[$unit]}"
}
# 1. System Memory Analysis
echo "📊 Analyzing system memory usage..." >&2
# Detect operating system for platform-specific commands
OS_TYPE=$(uname -s)
case "$OS_TYPE" in
"Linux")
# Linux memory information
if [ -f /proc/meminfo ]; then
TOTAL_MEMORY_KB=$(grep '^MemTotal:' /proc/meminfo | awk '{print $2}')
AVAILABLE_MEMORY_KB=$(grep '^MemAvailable:' /proc/meminfo | awk '{print $2}' || echo "0")
if [ "$AVAILABLE_MEMORY_KB" -eq 0 ]; then
# Fallback calculation for older systems
FREE_MEMORY_KB=$(grep '^MemFree:' /proc/meminfo | awk '{print $2}')
BUFFERS_KB=$(grep '^Buffers:' /proc/meminfo | awk '{print $2}')
CACHED_KB=$(grep '^Cached:' /proc/meminfo | awk '{print $2}')
AVAILABLE_MEMORY_KB=$((FREE_MEMORY_KB + BUFFERS_KB + CACHED_KB))
fi
USED_MEMORY_KB=$((TOTAL_MEMORY_KB - AVAILABLE_MEMORY_KB))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 🖥️ Total Memory: $(format_bytes $((TOTAL_MEMORY_KB * 1024)))" >&2
echo " 📈 Used Memory: $(format_bytes $((USED_MEMORY_KB * 1024))) ($MEMORY_PERCENT%)" >&2
# Check swap usage
if [ -f /proc/swaps ]; then
SWAP_TOTAL_KB=$(awk 'NR>1 {sum+=$3} END {print sum+0}' /proc/swaps)
SWAP_USED_KB=$(awk 'NR>1 {sum+=$4} END {print sum+0}' /proc/swaps)
if [ "$SWAP_TOTAL_KB" -gt 0 ]; then
SWAP_PERCENT=$((SWAP_USED_KB * 100 / SWAP_TOTAL_KB))
echo " 💿 Swap Usage: $(format_bytes $((SWAP_USED_KB * 1024))) / $(format_bytes $((SWAP_TOTAL_KB * 1024))) ($SWAP_PERCENT%)" >&2
else
echo " 💿 Swap: Not configured" >&2
fi
fi
else
report_memory "WARNING" "Unable to read /proc/meminfo - memory monitoring limited"
fi
;;
"Darwin")
# macOS memory information
if command -v vm_stat &> /dev/null; then
# Get page size
PAGE_SIZE=$(vm_stat | grep 'page size of' | awk '{print $8}' || echo "4096")
# Get memory statistics
VM_STAT_OUTPUT=$(vm_stat)
PAGES_FREE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages free:' | awk '{print $3}' | tr -d '.')
PAGES_ACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages active:' | awk '{print $3}' | tr -d '.')
PAGES_INACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages inactive:' | awk '{print $3}' | tr -d '.')
PAGES_SPECULATIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages speculative:' | awk '{print $3}' | tr -d '.' || echo "0")
PAGES_WIRED=$(echo "$VM_STAT_OUTPUT" | grep 'Pages wired down:' | awk '{print $4}' | tr -d '.')
# Calculate memory usage
TOTAL_PAGES=$((PAGES_FREE + PAGES_ACTIVE + PAGES_INACTIVE + PAGES_SPECULATIVE + PAGES_WIRED))
USED_PAGES=$((PAGES_ACTIVE + PAGES_INACTIVE + PAGES_SPECULATIVE + PAGES_WIRED))
TOTAL_MEMORY_KB=$((TOTAL_PAGES * PAGE_SIZE / 1024))
USED_MEMORY_KB=$((USED_PAGES * PAGE_SIZE / 1024))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 🖥️ Total Memory: $(format_bytes $((TOTAL_MEMORY_KB * 1024)))" >&2
echo " 📈 Used Memory: $(format_bytes $((USED_MEMORY_KB * 1024))) ($MEMORY_PERCENT%)" >&2
# Check swap usage on macOS
if command -v sysctl &> /dev/null; then
SWAP_USAGE=$(sysctl vm.swapusage 2>/dev/null | grep -oE 'used = [0-9.]+[KMGT]?' | awk '{print $3}' || echo "0")
SWAP_TOTAL=$(sysctl vm.swapusage 2>/dev/null | grep -oE 'total = [0-9.]+[KMGT]?' | awk '{print $3}' || echo "0")
echo " 💿 Swap Usage: $SWAP_USAGE / $SWAP_TOTAL" >&2
fi
else
report_memory "WARNING" "vm_stat command not available - memory monitoring limited"
fi
;;
*)
report_memory "WARNING" "Unsupported operating system ($OS_TYPE) - limited memory monitoring"
;;
esac
# 2. Process-Specific Memory Analysis
echo "🔍 Analyzing development process memory usage..." >&2
# Define process patterns for different development environments
DEV_PROCESSES=("node" "python" "java" "ruby" "php" "go" "rust" "dotnet" "code" "claude")
TOTAL_DEV_MEMORY_KB=0
PROCESS_COUNT=0
for process in "${DEV_PROCESSES[@]}"; do
if command -v pgrep &> /dev/null; then
# Use pgrep for more accurate process detection
PIDS=$(pgrep -f "$process" 2>/dev/null || true)
if [ -n "$PIDS" ]; then
PROCESS_MEMORY=0
PROC_COUNT=0
# Calculate memory for all matching processes
for pid in $PIDS; do
if [ -f "/proc/$pid/status" ]; then
# Linux: Read from /proc/pid/status
PID_MEMORY=$(grep '^VmRSS:' "/proc/$pid/status" 2>/dev/null | awk '{print $2}' || echo "0")
elif command -v ps &> /dev/null; then
# macOS/Other: Use ps command
PID_MEMORY=$(ps -o rss= -p "$pid" 2>/dev/null | awk '{print $1}' || echo "0")
else
PID_MEMORY=0
fi
PROCESS_MEMORY=$((PROCESS_MEMORY + PID_MEMORY))
PROC_COUNT=$((PROC_COUNT + 1))
done
if [ "$PROCESS_MEMORY" -gt 0 ]; then
echo " 🔧 $process processes: $PROC_COUNT running, $(format_bytes $((PROCESS_MEMORY * 1024))) memory" >&2
TOTAL_DEV_MEMORY_KB=$((TOTAL_DEV_MEMORY_KB + PROCESS_MEMORY))
PROCESS_COUNT=$((PROCESS_COUNT + PROC_COUNT))
fi
fi
fi
done
if [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ]; then
DEV_MEMORY_PERCENT=$((TOTAL_DEV_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 📊 Total dev processes: $PROCESS_COUNT processes, $(format_bytes $((TOTAL_DEV_MEMORY_KB * 1024))) ($DEV_MEMORY_PERCENT% of system)" >&2
else
echo " 📋 No development processes detected" >&2
fi
# 3. Container Memory Monitoring (if applicable)
echo "🐳 Checking container memory usage..." >&2
if command -v docker &> /dev/null && docker info >/dev/null 2>&1; then
# Check Docker container memory usage
RUNNING_CONTAINERS=$(docker ps --format "table {{.Names}}" --no-trunc 2>/dev/null | tail -n +2 | wc -l || echo "0")
if [ "$RUNNING_CONTAINERS" -gt 0 ]; then
echo " 🐳 Docker containers: $RUNNING_CONTAINERS running" >&2
# Get container memory stats (basic)
CONTAINER_STATS=$(docker stats --no-stream --format "table {{.Container}}\t{{.MemUsage}}" 2>/dev/null | tail -n +2 | head -5 || true)
if [ -n "$CONTAINER_STATS" ]; then
echo " 📊 Top container memory usage:" >&2
echo "$CONTAINER_STATS" | while read line; do
echo " $line" >&2
done
fi
else
echo " 🐳 No running Docker containers" >&2
fi
else
echo " 🐳 Docker not available or not running" >&2
fi
# 4. Memory Threshold Analysis
echo "⚠️ Analyzing memory thresholds..." >&2
# Check system memory thresholds
if [ "$MEMORY_PERCENT" -ge "$CRITICAL_MEMORY_THRESHOLD" ]; then
report_memory "ERROR" "Critical system memory usage: $MEMORY_PERCENT% (threshold: $CRITICAL_MEMORY_THRESHOLD%)"
elif [ "$MEMORY_PERCENT" -ge "$HIGH_MEMORY_THRESHOLD" ]; then
report_memory "WARNING" "High system memory usage: $MEMORY_PERCENT% (threshold: $HIGH_MEMORY_THRESHOLD%)"
else
report_memory "PASS" "System memory usage within normal range: $MEMORY_PERCENT%"
fi
# Check swap usage
if [ "$SWAP_PERCENT" -ge "$HIGH_SWAP_THRESHOLD" ]; then
report_memory "WARNING" "High swap usage detected: $SWAP_PERCENT% (threshold: $HIGH_SWAP_THRESHOLD%)"
else
if [ "$SWAP_PERCENT" -gt 0 ]; then
report_memory "INFO" "Swap usage normal: $SWAP_PERCENT%"
fi
fi
# Check for potential memory leaks (high dev process usage)
if [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ] && [ "$DEV_MEMORY_PERCENT" -ge 50 ]; then
report_memory "WARNING" "Development processes using significant memory: $DEV_MEMORY_PERCENT% of system"
elif [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ]; then
report_memory "INFO" "Development process memory usage normal: $DEV_MEMORY_PERCENT% of system"
fi
# 5. Memory Recommendations
echo "💡 Memory optimization recommendations..." >&2
if [ "$MEMORY_PERCENT" -ge "$HIGH_MEMORY_THRESHOLD" ]; then
echo " • Consider closing unused applications and browser tabs" >&2
echo " • Restart development servers to free up memory" >&2
echo " • Check for memory leaks in your applications" >&2
fi
if [ "$SWAP_PERCENT" -ge "$HIGH_SWAP_THRESHOLD" ]; then
echo " • High swap usage may slow down development" >&2
echo " • Consider adding more RAM or closing applications" >&2
fi
if [ "$PROCESS_COUNT" -gt 10 ]; then
echo " • Many development processes running ($PROCESS_COUNT)" >&2
echo " • Consider stopping unused development servers" >&2
fi
# 6. Generate Memory Summary
echo "" >&2
echo "📋 Memory Usage Summary:" >&2
echo "========================" >&2
echo " 💾 System Memory: $MEMORY_PERCENT% used ($(format_bytes $((USED_MEMORY_KB * 1024))) / $(format_bytes $((TOTAL_MEMORY_KB * 1024))))" >&2
[ "$SWAP_PERCENT" -gt 0 ] && echo " 💿 Swap Usage: $SWAP_PERCENT%" >&2
echo " 🔧 Dev Processes: $PROCESS_COUNT running ($(format_bytes $((TOTAL_DEV_MEMORY_KB * 1024))))" >&2
echo " ⚠️ Warnings: $WARNINGS" >&2
echo " ❌ Critical Issues: $ERRORS" >&2
if [ "$ERRORS" -eq 0 ] && [ "$WARNINGS" -eq 0 ]; then
echo " 🎉 Status: OPTIMAL - Memory usage is healthy" >&2
elif [ "$ERRORS" -eq 0 ]; then
echo " ✅ Status: GOOD - Memory usage acceptable with minor warnings" >&2
else
echo " ❌ Status: CRITICAL - Memory usage requires immediate attention" >&2
fi
echo "" >&2
echo "💡 Memory Best Practices:" >&2
echo " • Monitor memory usage regularly during development" >&2
echo " • Use memory profiling tools to identify leaks" >&2
echo " • Restart development servers periodically" >&2
echo " • Consider using lighter development tools when memory is limited" >&2
echo " • Close unused applications and browser tabs" >&2
# Memory monitoring complete
exit 0{
"hooks": {
"notification": {
"script": "./.claude/hooks/memory-usage-monitor.sh",
"timeout": 5000
}
}
}.claude/settings.local.json~/.claude/settings.json.claude/settings.json{
"hooks": {
"notification": {
"script": "./.claude/hooks/memory-usage-monitor.sh",
"timeout": 5000
}
}
}
#!/usr/bin/env bash
# Memory Usage Monitor Hook
# Monitors system and process memory usage during development activities
echo "💾 Memory Usage Monitor" >&2
# Initialize monitoring variables
TOTAL_MEMORY_KB=0
USED_MEMORY_KB=0
MEMORY_PERCENT=0
SWAP_PERCENT=0
HIGH_MEMORY_THRESHOLD=75
CRITICAL_MEMORY_THRESHOLD=90
HIGH_SWAP_THRESHOLD=25
WARNINGS=0
ERRORS=0
# Function to report memory status
report_memory() {
local level="$1"
local message="$2"
case "$level" in
"ERROR")
echo "❌ CRITICAL: $message" >&2
ERRORS=$((ERRORS + 1))
;;
"WARNING")
echo "⚠️ WARNING: $message" >&2
WARNINGS=$((WARNINGS + 1))
;;
"INFO")
echo "ℹ️ INFO: $message" >&2
;;
"PASS")
echo "✅ OK: $message" >&2
;;
esac
}
# Function to format bytes to human readable
format_bytes() {
local bytes=$1
local units=("B" "KB" "MB" "GB" "TB")
local unit=0
while (( bytes > 1024 && unit < 4 )); do
bytes=$((bytes / 1024))
unit=$((unit + 1))
done
echo "${bytes}${units[$unit]}"
}
# 1. System Memory Analysis
echo "📊 Analyzing system memory usage..." >&2
# Detect operating system for platform-specific commands
OS_TYPE=$(uname -s)
case "$OS_TYPE" in
"Linux")
# Linux memory information
if [ -f /proc/meminfo ]; then
TOTAL_MEMORY_KB=$(grep '^MemTotal:' /proc/meminfo | awk '{print $2}')
AVAILABLE_MEMORY_KB=$(grep '^MemAvailable:' /proc/meminfo | awk '{print $2}' || echo "0")
if [ "$AVAILABLE_MEMORY_KB" -eq 0 ]; then
# Fallback calculation for older systems
FREE_MEMORY_KB=$(grep '^MemFree:' /proc/meminfo | awk '{print $2}')
BUFFERS_KB=$(grep '^Buffers:' /proc/meminfo | awk '{print $2}')
CACHED_KB=$(grep '^Cached:' /proc/meminfo | awk '{print $2}')
AVAILABLE_MEMORY_KB=$((FREE_MEMORY_KB + BUFFERS_KB + CACHED_KB))
fi
USED_MEMORY_KB=$((TOTAL_MEMORY_KB - AVAILABLE_MEMORY_KB))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 🖥️ Total Memory: $(format_bytes $((TOTAL_MEMORY_KB * 1024)))" >&2
echo " 📈 Used Memory: $(format_bytes $((USED_MEMORY_KB * 1024))) ($MEMORY_PERCENT%)" >&2
# Check swap usage
if [ -f /proc/swaps ]; then
SWAP_TOTAL_KB=$(awk 'NR>1 {sum+=$3} END {print sum+0}' /proc/swaps)
SWAP_USED_KB=$(awk 'NR>1 {sum+=$4} END {print sum+0}' /proc/swaps)
if [ "$SWAP_TOTAL_KB" -gt 0 ]; then
SWAP_PERCENT=$((SWAP_USED_KB * 100 / SWAP_TOTAL_KB))
echo " 💿 Swap Usage: $(format_bytes $((SWAP_USED_KB * 1024))) / $(format_bytes $((SWAP_TOTAL_KB * 1024))) ($SWAP_PERCENT%)" >&2
else
echo " 💿 Swap: Not configured" >&2
fi
fi
else
report_memory "WARNING" "Unable to read /proc/meminfo - memory monitoring limited"
fi
;;
"Darwin")
# macOS memory information
if command -v vm_stat &> /dev/null; then
# Get page size
PAGE_SIZE=$(vm_stat | grep 'page size of' | awk '{print $8}' || echo "4096")
# Get memory statistics
VM_STAT_OUTPUT=$(vm_stat)
PAGES_FREE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages free:' | awk '{print $3}' | tr -d '.')
PAGES_ACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages active:' | awk '{print $3}' | tr -d '.')
PAGES_INACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages inactive:' | awk '{print $3}' | tr -d '.')
PAGES_SPECULATIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages speculative:' | awk '{print $3}' | tr -d '.' || echo "0")
PAGES_WIRED=$(echo "$VM_STAT_OUTPUT" | grep 'Pages wired down:' | awk '{print $4}' | tr -d '.')
# Calculate memory usage
TOTAL_PAGES=$((PAGES_FREE + PAGES_ACTIVE + PAGES_INACTIVE + PAGES_SPECULATIVE + PAGES_WIRED))
USED_PAGES=$((PAGES_ACTIVE + PAGES_INACTIVE + PAGES_SPECULATIVE + PAGES_WIRED))
TOTAL_MEMORY_KB=$((TOTAL_PAGES * PAGE_SIZE / 1024))
USED_MEMORY_KB=$((USED_PAGES * PAGE_SIZE / 1024))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 🖥️ Total Memory: $(format_bytes $((TOTAL_MEMORY_KB * 1024)))" >&2
echo " 📈 Used Memory: $(format_bytes $((USED_MEMORY_KB * 1024))) ($MEMORY_PERCENT%)" >&2
# Check swap usage on macOS
if command -v sysctl &> /dev/null; then
SWAP_USAGE=$(sysctl vm.swapusage 2>/dev/null | grep -oE 'used = [0-9.]+[KMGT]?' | awk '{print $3}' || echo "0")
SWAP_TOTAL=$(sysctl vm.swapusage 2>/dev/null | grep -oE 'total = [0-9.]+[KMGT]?' | awk '{print $3}' || echo "0")
echo " 💿 Swap Usage: $SWAP_USAGE / $SWAP_TOTAL" >&2
fi
else
report_memory "WARNING" "vm_stat command not available - memory monitoring limited"
fi
;;
*)
report_memory "WARNING" "Unsupported operating system ($OS_TYPE) - limited memory monitoring"
;;
esac
# 2. Process-Specific Memory Analysis
echo "🔍 Analyzing development process memory usage..." >&2
# Define process patterns for different development environments
DEV_PROCESSES=("node" "python" "java" "ruby" "php" "go" "rust" "dotnet" "code" "claude")
TOTAL_DEV_MEMORY_KB=0
PROCESS_COUNT=0
for process in "${DEV_PROCESSES[@]}"; do
if command -v pgrep &> /dev/null; then
# Use pgrep for more accurate process detection
PIDS=$(pgrep -f "$process" 2>/dev/null || true)
if [ -n "$PIDS" ]; then
PROCESS_MEMORY=0
PROC_COUNT=0
# Calculate memory for all matching processes
for pid in $PIDS; do
if [ -f "/proc/$pid/status" ]; then
# Linux: Read from /proc/pid/status
PID_MEMORY=$(grep '^VmRSS:' "/proc/$pid/status" 2>/dev/null | awk '{print $2}' || echo "0")
elif command -v ps &> /dev/null; then
# macOS/Other: Use ps command
PID_MEMORY=$(ps -o rss= -p "$pid" 2>/dev/null | awk '{print $1}' || echo "0")
else
PID_MEMORY=0
fi
PROCESS_MEMORY=$((PROCESS_MEMORY + PID_MEMORY))
PROC_COUNT=$((PROC_COUNT + 1))
done
if [ "$PROCESS_MEMORY" -gt 0 ]; then
echo " 🔧 $process processes: $PROC_COUNT running, $(format_bytes $((PROCESS_MEMORY * 1024))) memory" >&2
TOTAL_DEV_MEMORY_KB=$((TOTAL_DEV_MEMORY_KB + PROCESS_MEMORY))
PROCESS_COUNT=$((PROCESS_COUNT + PROC_COUNT))
fi
fi
fi
done
if [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ]; then
DEV_MEMORY_PERCENT=$((TOTAL_DEV_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo " 📊 Total dev processes: $PROCESS_COUNT processes, $(format_bytes $((TOTAL_DEV_MEMORY_KB * 1024))) ($DEV_MEMORY_PERCENT% of system)" >&2
else
echo " 📋 No development processes detected" >&2
fi
# 3. Container Memory Monitoring (if applicable)
echo "🐳 Checking container memory usage..." >&2
if command -v docker &> /dev/null && docker info >/dev/null 2>&1; then
# Check Docker container memory usage
RUNNING_CONTAINERS=$(docker ps --format "table {{.Names}}" --no-trunc 2>/dev/null | tail -n +2 | wc -l || echo "0")
if [ "$RUNNING_CONTAINERS" -gt 0 ]; then
echo " 🐳 Docker containers: $RUNNING_CONTAINERS running" >&2
# Get container memory stats (basic)
CONTAINER_STATS=$(docker stats --no-stream --format "table {{.Container}}\t{{.MemUsage}}" 2>/dev/null | tail -n +2 | head -5 || true)
if [ -n "$CONTAINER_STATS" ]; then
echo " 📊 Top container memory usage:" >&2
echo "$CONTAINER_STATS" | while read line; do
echo " $line" >&2
done
fi
else
echo " 🐳 No running Docker containers" >&2
fi
else
echo " 🐳 Docker not available or not running" >&2
fi
# 4. Memory Threshold Analysis
echo "⚠️ Analyzing memory thresholds..." >&2
# Check system memory thresholds
if [ "$MEMORY_PERCENT" -ge "$CRITICAL_MEMORY_THRESHOLD" ]; then
report_memory "ERROR" "Critical system memory usage: $MEMORY_PERCENT% (threshold: $CRITICAL_MEMORY_THRESHOLD%)"
elif [ "$MEMORY_PERCENT" -ge "$HIGH_MEMORY_THRESHOLD" ]; then
report_memory "WARNING" "High system memory usage: $MEMORY_PERCENT% (threshold: $HIGH_MEMORY_THRESHOLD%)"
else
report_memory "PASS" "System memory usage within normal range: $MEMORY_PERCENT%"
fi
# Check swap usage
if [ "$SWAP_PERCENT" -ge "$HIGH_SWAP_THRESHOLD" ]; then
report_memory "WARNING" "High swap usage detected: $SWAP_PERCENT% (threshold: $HIGH_SWAP_THRESHOLD%)"
else
if [ "$SWAP_PERCENT" -gt 0 ]; then
report_memory "INFO" "Swap usage normal: $SWAP_PERCENT%"
fi
fi
# Check for potential memory leaks (high dev process usage)
if [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ] && [ "$DEV_MEMORY_PERCENT" -ge 50 ]; then
report_memory "WARNING" "Development processes using significant memory: $DEV_MEMORY_PERCENT% of system"
elif [ "$TOTAL_DEV_MEMORY_KB" -gt 0 ]; then
report_memory "INFO" "Development process memory usage normal: $DEV_MEMORY_PERCENT% of system"
fi
# 5. Memory Recommendations
echo "💡 Memory optimization recommendations..." >&2
if [ "$MEMORY_PERCENT" -ge "$HIGH_MEMORY_THRESHOLD" ]; then
echo " • Consider closing unused applications and browser tabs" >&2
echo " • Restart development servers to free up memory" >&2
echo " • Check for memory leaks in your applications" >&2
fi
if [ "$SWAP_PERCENT" -ge "$HIGH_SWAP_THRESHOLD" ]; then
echo " • High swap usage may slow down development" >&2
echo " • Consider adding more RAM or closing applications" >&2
fi
if [ "$PROCESS_COUNT" -gt 10 ]; then
echo " • Many development processes running ($PROCESS_COUNT)" >&2
echo " • Consider stopping unused development servers" >&2
fi
# 6. Generate Memory Summary
echo "" >&2
echo "📋 Memory Usage Summary:" >&2
echo "========================" >&2
echo " 💾 System Memory: $MEMORY_PERCENT% used ($(format_bytes $((USED_MEMORY_KB * 1024))) / $(format_bytes $((TOTAL_MEMORY_KB * 1024))))" >&2
[ "$SWAP_PERCENT" -gt 0 ] && echo " 💿 Swap Usage: $SWAP_PERCENT%" >&2
echo " 🔧 Dev Processes: $PROCESS_COUNT running ($(format_bytes $((TOTAL_DEV_MEMORY_KB * 1024))))" >&2
echo " ⚠️ Warnings: $WARNINGS" >&2
echo " ❌ Critical Issues: $ERRORS" >&2
if [ "$ERRORS" -eq 0 ] && [ "$WARNINGS" -eq 0 ]; then
echo " 🎉 Status: OPTIMAL - Memory usage is healthy" >&2
elif [ "$ERRORS" -eq 0 ]; then
echo " ✅ Status: GOOD - Memory usage acceptable with minor warnings" >&2
else
echo " ❌ Status: CRITICAL - Memory usage requires immediate attention" >&2
fi
echo "" >&2
echo "💡 Memory Best Practices:" >&2
echo " • Monitor memory usage regularly during development" >&2
echo " • Use memory profiling tools to identify leaks" >&2
echo " • Restart development servers periodically" >&2
echo " • Consider using lighter development tools when memory is limited" >&2
echo " • Close unused applications and browser tabs" >&2
# Memory monitoring complete
exit 0
Complete hook script that performs memory usage monitoring
#!/usr/bin/env bash
echo "💾 Memory Usage Monitor" >&2
OS_TYPE=$(uname -s)
if [ "$OS_TYPE" = "Linux" ] && [ -f /proc/meminfo ]; then
TOTAL_MEMORY_KB=$(grep '^MemTotal:' /proc/meminfo | awk '{print $2}')
AVAILABLE_MEMORY_KB=$(grep '^MemAvailable:' /proc/meminfo | awk '{print $2}' || echo "0")
USED_MEMORY_KB=$((TOTAL_MEMORY_KB - AVAILABLE_MEMORY_KB))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo "📊 Memory Usage: $MEMORY_PERCENT%" >&2
if [ "$MEMORY_PERCENT" -ge 90 ]; then
echo "❌ CRITICAL: Memory usage exceeds 90%" >&2
elif [ "$MEMORY_PERCENT" -ge 75 ]; then
echo "⚠️ WARNING: High memory usage" >&2
fi
fi
exit 0
Enhanced hook script for tracking development process memory usage
#!/usr/bin/env bash
OS_TYPE=$(uname -s)
DEV_PROCESSES=("node" "python" "java" "ruby")
TOTAL_DEV_MEMORY_KB=0
for process in "${DEV_PROCESSES[@]}"; do
if command -v pgrep &> /dev/null; then
PIDS=$(pgrep -u $USER -f "$process" 2>/dev/null || true)
for pid in $PIDS; do
if [ "$OS_TYPE" = "Linux" ] && [ -f "/proc/$pid/status" ]; then
PID_MEMORY=$(grep '^VmRSS:' "/proc/$pid/status" 2>/dev/null | awk '{print $2}' || echo "0")
elif command -v ps &> /dev/null; then
PID_MEMORY=$(ps -o rss= -p "$pid" 2>/dev/null | awk '{print $1}' || echo "0")
fi
TOTAL_DEV_MEMORY_KB=$((TOTAL_DEV_MEMORY_KB + PID_MEMORY))
done
fi
done
echo "🔧 Development processes: $(($TOTAL_DEV_MEMORY_KB / 1024))MB" >&2
exit 0
Enhanced hook script for Docker container memory monitoring
#!/usr/bin/env bash
if command -v docker &> /dev/null && docker info >/dev/null 2>&1; then
RUNNING_CONTAINERS=$(docker ps --format "table {{.Names}}" --no-trunc 2>/dev/null | tail -n +2 | wc -l || echo "0")
if [ "$RUNNING_CONTAINERS" -gt 0 ]; then
echo "🐳 Docker containers: $RUNNING_CONTAINERS running" >&2
CONTAINER_STATS=$(timeout 5 docker stats --no-stream --format "table {{.Container}}\t{{.MemUsage}}" 2>/dev/null | tail -n +2 | head -5 || true)
if [ -n "$CONTAINER_STATS" ]; then
echo "📊 Top container memory usage:" >&2
echo "$CONTAINER_STATS" | while read line; do
echo " $line" >&2
done
fi
fi
fi
exit 0
Enhanced hook script for macOS memory monitoring with Apple Silicon support
#!/usr/bin/env bash
OS_TYPE=$(uname -s)
if [ "$OS_TYPE" = "Darwin" ] && command -v vm_stat &> /dev/null; then
PAGE_SIZE=4096
if [ "$(uname -m)" = "arm64" ]; then
PAGE_SIZE=16384
fi
VM_STAT_OUTPUT=$(vm_stat)
PAGES_FREE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages free:' | awk '{print $3}' | tr -d '.')
PAGES_ACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages active:' | awk '{print $3}' | tr -d '.')
PAGES_INACTIVE=$(echo "$VM_STAT_OUTPUT" | grep 'Pages inactive:' | awk '{print $3}' | tr -d '.')
PAGES_WIRED=$(echo "$VM_STAT_OUTPUT" | grep 'Pages wired down:' | awk '{print $4}' | tr -d '.')
TOTAL_PAGES=$((PAGES_FREE + PAGES_ACTIVE + PAGES_INACTIVE + PAGES_WIRED))
USED_PAGES=$((PAGES_ACTIVE + PAGES_INACTIVE + PAGES_WIRED))
TOTAL_MEMORY_KB=$((TOTAL_PAGES * PAGE_SIZE / 1024))
USED_MEMORY_KB=$((USED_PAGES * PAGE_SIZE / 1024))
MEMORY_PERCENT=$((USED_MEMORY_KB * 100 / TOTAL_MEMORY_KB))
echo "📊 macOS Memory Usage: $MEMORY_PERCENT%" >&2
fi
exit 0
MemAvailable fallback calculation adds cached memory twice. For older Linux: 'USED_MEMORY_KB=$((TOTAL_MEMORY_KB - FREE_MEMORY_KB))' excluding buffers/cache. Or upgrade kernel to 3.14+ with MemAvailable support. Verify memory calculation logic. Test with various Linux versions.
PAGE_SIZE extraction fails when format changes. Hardcode: 'PAGE_SIZE=4096' (Intel) or 'PAGE_SIZE=16384' (Apple Silicon M1/M2). Or use: 'sysctl hw.pagesize | awk '{print $2}''. Verify page size detection. Test with various macOS versions.
pgrep matches all users. Restrict: 'pgrep -u $USER -f "$process"' showing only current user's processes. Or filter: 'ps -u $USER -o pid,comm,rss' for ownership validation. Verify user filtering. Test with various user configurations.
docker stats --no-stream blocks on slow containers. Add timeout: 'timeout 5 docker stats --no-stream' or skip: 'docker stats --no-stream --format json 2>/dev/null | head -n 1' limiting output. Verify timeout handling. Test with various container states.
Process enumeration slow with 100+ dev processes. Increase timeout: '"timeout": 10000' in hookConfig. Or limit: 'pgrep -f "$process" | head -20' checking only top processes. Verify timeout configuration. Test with various system sizes.
Hook checks for swap existence before calculating percentages. Verify swap detection: 'if [ -f /proc/swaps ]' (Linux) or 'sysctl vm.swapusage' (macOS). Handle no-swap scenarios gracefully. Test with various swap configurations.
VmRSS includes all threads. For accurate per-process memory, sum thread memory or use process group memory. Verify thread handling. Test with various process types. Consider using process group aggregation.
System memory stats may be stale after sleep. Refresh memory information or add sleep detection. Verify memory refresh logic. Test with sleep/wake cycles. Consider adding memory refresh before monitoring.
Memory Usage Monitor - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
| Field | Monitors memory usage and alerts when thresholds are exceeded. Open dossier | Alerts when files exceed size thresholds that could impact performance. This PostToolUse hook provides comprehensive file size monitoring when files are created or modified, automatically detecting files that exceed recommended size thresholds for different file types and providing optimization suggestions. Open dossier | Monitors and alerts on performance-impacting changes in real-time. Open dossier | A Claude Code hook that flags files exceeding complexity thresholds after you edit them — estimating cyclomatic complexity, line and function counts, and nesting depth (via ESLint's complexity rule and Radon). Open dossier |
|---|---|---|---|---|
| Next steps | ||||
| Trust | ||||
| Review status | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed | ReviewedMaintainer reviewed |
| Package trust | Package not verified | Package not verified | Package not verified | Package not verified |
| Source provenance | Source-backed | Source-backed | Source-backed | Source-backed |
| Submitter | — | — | — | — |
| Install risk | Review first | Review first | Review first | Review first |
| Notes | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ |
| Brand | — | — | — | — |
| Category | hooks | hooks | hooks | hooks |
| Source | source-backed | source-backed | source-backed | source-backed |
| Author | JSONbored | JSONbored | JSONbored | JSONbored |
| Added | 2025-09-19 | 2025-09-19 | 2025-09-19 | 2025-09-19 |
| Platforms | Claude Code | Claude Code | Claude Code | Claude Code |
| Source repo | — | — | — | — |
| Safety notes | ✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling. | ✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling. | ✓Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling. | ✓Runs after edits to JS/TS/Python files and prints advisory warnings only; the line/function/brace counts are heuristics, not a substitute for ESLint or Radon run on the full project. |
| Privacy notes | ✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output. | ✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output. | ✓Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output. | ✓Reads the contents of files you edit to compute complexity locally; it prints warnings to hook output and does not transmit code, but those messages can reveal file structure. |
| Prerequisites | — none listed | — none listed | — none listed | — none listed |
| Install | | | | |
| Config | | | | |
| Citations | ||||
| Claim | Unclaimed | Unclaimed | Unclaimed | Unclaimed |
Source-backed guides for putting this to work.
Fix Claude Code CPU, memory, and search issues with /compact, /heapdump, and ripgrep steps from official docs.
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.