Skip to content

hookWorkflow

Log Bash Commands

A Claude Code hook that appends every shell command the agent runs to .claude/command-log.txt with a timestamp, for review afterward.

npx workspacetemplates add log-bash-commands --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file16 lines · 612 BFile
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"let d='';process.stdin.on('data',c=>d+=c).on('end',()=>{let j={};try{j=JSON.parse(d)}catch(e){process.exit(0)}const i=j.tool_input||{};const c=(j.tool_input||{}).command;if(!c)process.exit(0);const fs=require('fs');fs.mkdirSync('.claude',{recursive:true});fs.appendFileSync('.claude/command-log.txt',new Date().toISOString()+' '+JSON.stringify(c)+String.fromCharCode(10))})\"",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

What it does

When an agent works for a while it is hard to remember what it ran. This PreToolUse hook writes each Bash command to a plain text log next to your project settings.

Each line holds an ISO timestamp and the command as a JSON string, so multi-line commands stay on one line. Nothing leaves your machine.

Example

you › Run the tests and fix any failures.

agent › .claude/command-log.txt gains lines such as: 2026-11-15T09:12:44.120Z "npm test". Add the file to .gitignore if you do not want to commit it.

Questions

Where is the log?
In .claude/command-log.txt under the folder Claude Code was started in.
Does it block anything?
No. It always lets the command run and only writes the line.
  • Inject Current Date

    HookWorkflow

    Free
  • Log Session End

    HookWorkflow

    Free
  • Notification Bell

    HookWorkflow

    Free