Omniscio

OmniscioGuidesLogging every tool call

A Claude Code hook that logs every tool call

When a session ends and you want to know what happened, the transcript records the conversation. A log records actions in the shape you choose: which tool, aimed at what, when, with which call id, and how long it took. That is the difference between re-reading a conversation and querying one.

Checked against Anthropic’s Claude Code hooks documentation on November 25, 2026. By the Omniscio team. Updated .

The problem

Three questions are hard to answer after the fact with only a conversation. Did Claude ever run that migration? Which files did the session touch, in what order? Why was the twenty-third turn slow?

All three are records, and Anthropic gives every tool event the fields that make them: the tool name, its input, a tool-use id, the working directory and the session, plus a duration on the way out. The log below keeps those and deliberately throws away everything else.

The script

Save it as ~/.claude/hooks/log-tool-call.sh and make it executable with chmod +x. It needs jq. One script serves all three events, because the event’s own name arrives in the JSON as hook_event_name, so the log labels itself.

#!/bin/bash
# ~/.claude/hooks/log-tool-call.sh
input=$(cat)
command -v jq >/dev/null || exit 0

umask 077
jq -c '{
  at: .hook_event_name,
  time: (now | todate),
  session: .session_id,
  id: .tool_use_id,
  tool: .tool_name,
  target: (.tool_input.file_path // .tool_input.notebook_path
           // .tool_input.command // .tool_input.url
           // .tool_input.pattern // .tool_input.description),
  ms: .duration_ms,
  error: .error
}' <<<"$input" >> "$HOME/.claude/tool-calls-$(date +%F).jsonl"

The projection is the point of the whole page. tool_input is never logged whole, because a Write call carries the entire file content and an Edit carries the replacement text: logging the input turns the file into a shadow copy of your source code. What is kept is the one field that says what the call was aimed at, and // is jq’s “try the next if this is null”, so one expression covers file tools, shell tools, searches, fetches and agents. A tool whose input has none of those fields logs null there; add its own field if you rely on it.

Registering it

Add the three events to ~/.claude/settings.json, merging them into any hooks object already there. No matcher means every tool. async keeps each write out of the turn’s critical path.

{
  "hooks": {
    "PreToolUse": [
      { "hooks": [ { "type": "command", "command": "\"$HOME/.claude/hooks/log-tool-call.sh\"", "async": true } ] }
    ],
    "PostToolUse": [
      { "hooks": [ { "type": "command", "command": "\"$HOME/.claude/hooks/log-tool-call.sh\"", "async": true } ] }
    ],
    "PostToolUseFailure": [
      { "hooks": [ { "type": "command", "command": "\"$HOME/.claude/hooks/log-tool-call.sh\"", "async": true } ] }
    ]
  }
}

An async hook cannot block, which a logger never needs, and its timeout is not enforced. The trade is that the write lands shortly after the event rather than during it, so a line can appear a moment late.

Logging into the project instead

For a log that travels with the work, change the script’s destination to "$CLAUDE_PROJECT_DIR/.claude/tool-calls.jsonl" and add that path to .gitignore. Claude Code exports CLAUDE_PROJECT_DIR to the hook’s process, so it resolves in both shell and exec form. In a PowerShell hook the variable is spelled $env:CLAUDE_PROJECT_DIR; the bare $CLAUDE_PROJECT_DIR form resolves to nothing there.

What each line does

PartJob
three event keysPreToolUse before the call, PostToolUse after one that succeeded, PostToolUseFailure after one that started and failed.
no matcherAn omitted matcher matches every tool, which is the point of an audit log.
command -v jq || exit 0A logger fails silent rather than loud: without jq the hook does nothing, and the session carries on.
umask 077Makes the log readable only by you, so a shared machine does not get your command history.
jq -cCompact JSON: one object, one line, which is what makes a JSONL file readable by every line-oriented tool.
at: .hook_event_nameLabels the line with the event that wrote it, so one file holds all three kinds.
id: .tool_use_idThe call id. It is what lets you pair the pre line with the post or fail line for the same call.
target: …The one field that says what the call was aimed at, with a fallback chain for file, shell, search, fetch and agent tools.
ms: .duration_msHow long the tool took, excluding permission prompts and PreToolUse hooks. Absent on the pre line.
>> …jsonlAppends. A > here would leave exactly one line in the file, forever.

Reading it back

A JSONL file is queryable with the same jq that wrote it. Start by finding the session you care about:

jq -r '.session' ~/.claude/tool-calls-$(date +%F).jsonl | sort -u

Then ask the questions the log exists for:

# shell commands this session attempted
jq -r 'select(.at=="PreToolUse" and .session=="abc123" and .tool=="Bash") | .target' \
  ~/.claude/tool-calls-$(date +%F).jsonl

# completed calls per tool, and where the tool time went
jq -s 'map(select(.at=="PostToolUse" and .session=="abc123"))
       | group_by(.tool)
       | map({tool: .[0].tool, calls: length, total_ms: (map(.ms // 0) | add)})
       | sort_by(-.total_ms)' ~/.claude/tool-calls-$(date +%F).jsonl

# one call, end to end
jq -c 'select(.id=="toolu_01ABC123")' ~/.claude/tool-calls-$(date +%F).jsonl

One thing the first query cannot answer on its own: a PreToolUse line means a call was attempted, and it fires even for a call that was later denied at the permission prompt. To know the call actually ran, look for a matching PostToolUse line with the same id.

What not to log

A hook runs with your full user permissions and writes a file with your umask, so the log inherits both risks at once.

  • Never log tool_input whole. A Write call carries the entire file content and an Edit carries the replacement text, so the log becomes a shadow copy of your source, secrets included.
  • Treat the Bash command as sensitive. A command line can hold a token, a password or a connection string. If that matters for your projects, redact it in the projection with gsub before it is written, for example target: (.tool_input.command | gsub("(?i)((?:token|password|secret|key)=)[^ ]+"; "\\1[redacted]")).
  • Keep it readable only by you. umask 077 in the script does that; chmod 600 the file once if it was written before you added the line.
  • Keep it out of the repository unless you mean it. ~/.claude is the safe default; a project file needs a .gitignore line and a moment’s thought about who else gets the log.
  • Bound the size. One file per day is the cheapest bound. Add a weekly find ~/.claude -name 'tool-calls-*.jsonl' -mtime +30 -delete if the directory should not grow without limit.

How to test that it fires

  1. Run the script by hand with sample JSON. This is the fastest way to see what a record will contain, and it needs no session:
    echo '{"session_id":"abc123","hook_event_name":"PreToolUse","tool_name":"Bash","tool_input":{"command":"ls -la"},"cwd":"/tmp","tool_use_id":"toolu_1"}' \
      | ~/.claude/hooks/log-tool-call.sh
    tail -n 1 ~/.claude/tool-calls-$(date +%F).jsonl
  2. Ask Claude to run one command and one edit, then read the file. tail -n 5 ~/.claude/tool-calls-$(date +%F).jsonl shows a pre line and a post line for each. Because the hook is async, give it a second and look again before deciding it failed.
  3. Try a failure. A command that starts and exits non-zero should add a fail line with its error. A call denied at the permission prompt writes neither a post nor a fail line, only the pre, which is documented behaviour rather than a bug.
  4. Check the registration with /hooks, and use claude --debug-file /tmp/claude.log if a line is missing: a JSON parse failure shows up there and nowhere in the conversation.

No Claude Code session was configured to run these hooks for the page, so the commands above are the ones to run rather than a record of a run.

The common failures

1. The file is enormous

tool_input or tool_response logged whole is the cause nearly every time. Project the fields you will actually query; if you need the full record for a week, log it to a separate file with a rotation you control.

2. Nothing is written

Three usual causes: ~/.claude or the script does not exist where you pointed the hook, jq is missing so the script exits 0, or jq fails because stdin is not valid JSON or the projection indexes something that is not an object. A field the event simply lacks becomes null and still writes a line, so an empty target is not this failure. Run the exact command from the settings file by hand and read what jq says.

3. The hook prints to stdout by accident

Anthropic reads stdout as the hook’s JSON output only when it is exactly one JSON object with nothing else around it; anything that does not start with { is plain text, and at exit 0 the run is a success, with the debug log noting Hook output does not start with {. Keep the redirect and let the hook print nothing, and there is nothing to misread.

4. Slower turns

A non-async command hook makes the turn wait for it, so a logger that shells out to a slow network call adds that latency to every tool call. "async": true is the documented answer.

5. Windows quoting

Under PowerShell the $(date +%F) form and the >> redirect behave differently from Bash, and $CLAUDE_PROJECT_DIR must be written $env:CLAUDE_PROJECT_DIR. Keep the hook in Bash through Git Bash, or set "shell": "powershell" and write the equivalent in PowerShell with an explicit encoding on the write.

Where Omniscio fits

This logger is a personal settings file, so put it in ~/.claude/settings.json and every session on the machine uses it. Omniscio’s Hooks panel composes the hooks it ships, and any you define, into every session it spawns, with a global switch and per-project overrides, kept in its own database rather than written into your global Claude configuration. The Claude Code hooks guide covers that panel, and the hooks builder assembles the block from the event, matcher and handler you pick.

How this page was written

The three events, the fields each one carries, the no-matcher rule, the async behaviour and the stdout-parsing rules were read from Anthropic’s Claude Code hooks reference on November 25, 2026. The privacy guidance is Anthropic’s own security section, read the same day.

No Claude Code session was configured to run these hooks for the page. The commands are the ones to run against your own machine, and the ledger records that nothing was observed live.

Sources

  • Anthropic’s Hooks reference, for the tool events and their input, the matcher rules, async, the stdout and JSON parsing rules, the handler types and the security section, read November 25, 2026.
  • Anthropic’s Automate actions with hooks, for the manual pipe test and the shell-profile output note, read November 25, 2026.

Common questions

How do I log every tool call Claude Code makes?

Register a PreToolUse hook and a PostToolUse hook with no matcher, so each runs for every tool. Each one reads the event JSON from stdin, projects the fields you care about with jq and appends one line to a file. Add PostToolUseFailure for calls that started and failed.

Why is my log so large?

Because tool_input can carry whole files: a Write call includes the full content and an Edit call includes the replacement text. Project the fields you need, such as the file path or the command, instead of logging tool_input whole.

Does a logging hook slow the session down?

It can, because the turn waits for a command hook that is not async. Set async to true on the logging handler to run it in the background without blocking.

Can I log to a database instead?

Yes. The handler runs whatever command you give it, so the same JSON can go to a script that writes to SQLite, a queue or an HTTP endpoint. Anthropic also documents an http hook type that posts the event to a URL and an mcp_tool type that calls a tool on an MCP server.

Does the log see commands that fail?

The calls that started and failed, yes: PostToolUseFailure covers those and carries the error text. It does not fire for a call rejected before execution — an unknown tool, input that fails validation, or a permission denial — so those appear only as a pre line, and a schema rejection appears nowhere in the log at all.

See what every session did

Omniscio runs your Claude Code sessions side by side and keeps their transcripts and status in one place, and it can compose the hooks it ships, and any you define, into every session it spawns.

The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.