performance-monitor — Claude Code hook: what it does, how to install
This hook logs CPU, process memory, and timestamps around Claude Code tool calls. Use the CSV log to inspect resource readings by tool.
npx claude-code-templates@latest --hook performance/performance-monitorWhat performance-monitor does
Before and after each tool call, the hook appends a row to ~/.claude/performance.csv. Each row contains a timestamp, CPU reading, process RSS, tool name, and a start or end marker. The file is a log, not a generated performance report.
Once the file passes 1000 lines, the hook replaces it with its most recent 500 lines. It writes to ~/.claude/performance.csv, so that location must be writable and its parent directory must exist. The hook is added through .claude/settings.json.
What it helps with
- log CPU readings around tool calls
- record process RSS for each operation
- match start and end entries by tool name
- trim the log to its latest 500 lines after it exceeds 1000
Example prompts for the agent
- Review
~/.claude/performance.csvand compare CPU readings across tools. - Find operations with high RSS in
~/.claude/performance.csv. - Compare resource readings between the
startandendentries.
How to install performance-monitor
1claude-code-templates
npx claude-code-templates@latest --hook performance/performance-monitor2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about performance-monitor
How do I install performance-monitor in Claude Code?
Run npx claude-code-templates@latest --hook performance/performance-monitor, then add the hook to .claude/settings.json.
What does performance-monitor do?
It logs a timestamp, CPU reading, process RSS, and tool name before and after each tool call in ~/.claude/performance.csv.
How does performance-monitor limit the log size?
When the file grows beyond 1000 lines, the hook replaces it with the latest 500 lines.
Source text
performance-monitor.json · MIT
{
"description": "Monitor system performance during Claude Code operations. Tracks CPU, memory usage, and execution time for performance optimization.",
"hooks": {
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo \"$(date +%s.%N),$(ps -o %cpu= -p $$),$(ps -o rss= -p $$),$CLAUDE_TOOL_NAME,start\" >> ~/.claude/performance.csv"
}
]
}
],
"PostToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo \"$(date +%s.%N),$(ps -o %cpu= -p $$),$(ps -o rss= -p $$),$CLAUDE_TOOL_NAME,end\" >> ~/.claude/performance.csv; if [[ $(wc -l < ~/.claude/performance.csv) -gt 1000 ]]; then tail -n 500 ~/.claude/performance.csv > ~/.claude/performance.csv.tmp && mv ~/.claude/performance.csv.tmp ~/.claude/performance.csv; fi"
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates