Skip to main content
hook

command-logger — Claude Code hook: what it does, how to install

Records every Claude Code tool call with a timestamp and file path to a local text file for debugging and auditing.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --hook development-tools/command-logger
Open on GitHub

What command-logger does

This hook triggers on the PreToolUse event across all tool calls. Before Claude Code executes an action, it appends an entry containing the current date, $CLAUDE_TOOL_NAME, and $CLAUDE_TOOL_FILE_PATH to ~/.claude/command-log.txt.

The setup relies purely on a shell echo command without extra runtimes or external services. Logging fails if the shell cannot write to ~/.claude/command-log.txt.

What it helps with

  • log tool execution history locally
  • audit file modifications and inspect accessed paths
  • troubleshoot automated sessions during debugging

Example prompts for the agent

  • Run the test suite and check the command output
  • Update the source code according to the issue description

How to install command-logger

1claude-code-templates

npx claude-code-templates@latest --hook development-tools/command-logger

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 command-logger

How do I install command-logger in Claude Code?

Run npx claude-code-templates@latest --hook development-tools/command-logger in your terminal or insert the hook configuration into .claude/settings.json.

What does command-logger do?

It captures every tool invocation right before execution and appends the timestamp, tool name, and target path to ~/.claude/command-log.txt.

Where does command-logger save the log file?

Output goes directly to ~/.claude/command-log.txt on the local machine using basic shell redirection.

Source text

command-logger.json · MIT
{
  "description": "Log all Claude Code commands to a file for audit and debugging purposes. Simple logging that records tool usage with timestamps.",
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"[$(date)] Tool: $CLAUDE_TOOL_NAME | File: $CLAUDE_TOOL_FILE_PATH\" >> ~/.claude/command-log.txt"
          }
        ]
      }
    ]
  }
}

© davila7 · MIT · davila7/claude-code-templates

Similar hooks

All hooks for Agent setup: memory, context, orchestration →

From the same set804

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