Skip to main content
hook

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.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --hook performance/performance-monitor
Open on GitHub

What 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.csv and compare CPU readings across tools.
  • Find operations with high RSS in ~/.claude/performance.csv.
  • Compare resource readings between the start and end entries.

How to install performance-monitor

1claude-code-templates

npx claude-code-templates@latest --hook performance/performance-monitor

2Manually: put the files in place

.claude/settings.json

The 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

Similar hooks

Hooks catalog →

From the same set740

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor