OpenClaw instances can consume excessive memory due to large conversation contexts, unbounded caches, memory leaks in skills, or simply having too many features enabled simultaneously. High memory usage leads to slow response times, system swap thrashing, and eventual OOM (out of memory) kills. This guide helps you identify memory hogs and optimize resource usage.
Why This Is Hard to Do Yourself
These are the common pitfalls that trip people up.
Memory usage creeping up over time
Slow leaks in skill code or unbounded conversation history buffers
Massive context windows
Keeping full conversation history in memory for long sessions
Unbounded caches and buffers
Embedding caches, skill result caches growing without eviction policies
Too many loaded skills
Each skill and its dependencies consuming heap space even when idle
Step-by-Step Guide
Measure current memory usage
Establish a baseline to understand how much memory OpenClaw is actually using.
# Find OpenClaw process memory:
top -b -n 1 | grep openclaw
# Or use htop for real-time monitoring:
htop -p $(pgrep -f openclaw)
# Get detailed memory breakdown:
cat /proc/$(pgrep -f openclaw)/status | grep -E "VmSize|VmRSS|VmSwap"
# VmRSS = actual physical RAM usedIdentify specific memory hogs
Use profiling tools to see which parts of OpenClaw consume the most memory.
# Enable memory profiling in OpenClaw config:
export OPENCLAW_PROFILE_MEMORY=true
# Check skill memory usage in logs:
grep "memory_usage" ~/.openclaw/logs/openclaw.log
# For Node.js-based OpenClaw:
node --inspect --expose-gc ./openclaw.js
# Then use Chrome DevTools memory profilerConfigure strict memory limits
Set hard limits to prevent runaway memory consumption and force garbage collection.
# For systemd services:
sudo systemctl edit openclaw
# Add:
[Service]
MemoryMax=2G
MemoryHigh=1.8G
# For Docker:
docker run -m 2g --memory-swap 2g openclaw/openclaw
# For Node.js processes:
node --max-old-space-size=2048 ./openclaw.jsReduce conversation context window
Limit how much conversation history OpenClaw keeps in memory.
# Edit OpenClaw config (config.json or .env):
MAX_CONTEXT_LENGTH=4000 # Reduce from default 16000
CONVERSATION_HISTORY_LIMIT=50 # Keep only last 50 turns
ENABLE_CONTEXT_COMPACTION=true
# Enable automatic summarization:
CONTEXT_SUMMARIZATION_THRESHOLD=8000
SUMMARIZATION_MODEL=claude-3-haiku # Faster, cheaperPrune loaded skills and caches
Disable unused skills and configure cache eviction policies.
# List currently loaded skills:
curl http://localhost:3000/api/skills | jq .
# Disable unused skills in config:
DISABLED_SKILLS=skill-image-gen,skill-video-analysis
# Configure cache limits:
SKILL_CACHE_MAX_SIZE=100 # Max cached skill results
EMBEDDING_CACHE_TTL=3600 # Evict after 1 hour
CLEAR_CACHES_ON_RESTART=trueSet up memory monitoring and alerts
Track memory trends over time and get notified before OOM kills.
# Simple memory monitoring script:
cat > monitor-memory.sh << 'EOF'
#!/bin/bash
while true; do
MEM=$(ps -o rss= -p $(pgrep -f openclaw))
echo "$(date): ${MEM}KB"
if [ "$MEM" -gt 2000000 ]; then
echo "WARNING: Memory exceeds 2GB!" | mail -s "OpenClaw Memory Alert" admin@example.com
fi
sleep 300
done
EOF
chmod +x monitor-memory.sh
# Or use systemd with monitoring:
systemctl status openclaw | grep MemoryMemory Issues Slowing You Down?
Our performance experts profile your OpenClaw instance, identify memory leaks, and implement custom optimization strategies. Get a tuned configuration and monitoring setup tailored to your workload.
Get matched with a specialist who can help.
Sign Up for Expert Help โ