Audit Log Hook
/install audit-log-hook
Audit Log Hook - Tool Call Audit
Purpose
Record all tool calls via before_tool_call and after_tool_call hooks for:
- Security auditing
- Debugging issues
- Usage statistics
- Error tracking
Implementation
Register hooks in a plugin:
// Audit log file path
const AUDIT_LOG = path.join(process.env.OPENCLAW_STATE_DIR || '~/.openclaw', 'audit.log');
api.registerHook("before_tool_call", async ({ event, ctx }) => {
const entry = {
ts: new Date().toISOString(),
event: "before_tool_call",
tool: event.tool.name,
params: JSON.stringify(event.tool.params).slice(0, 500),
session: ctx.sessionKey,
user: ctx.session?.senderId || 'unknown'
};
console.log("[AUDIT]", JSON.stringify(entry));
return {};
});
api.registerHook("after_tool_call", async ({ event, ctx }) => {
const entry = {
ts: new Date().toISOString(),
event: "after_tool_call",
tool: event.tool.name,
result: String(event.result).slice(0, 200),
error: event.error?.message || null,
duration: event.durationMs,
session: ctx.sessionKey
};
console.log("[AUDIT]", JSON.stringify(entry));
return {};
});
Log Format
{"ts":"2026-04-01T23:00:00.000Z","event":"before_tool_call","tool":"exec","params":"{\"command\":\"ls -la\"}","session":"agent:main:feishu:direct:ou_xxx","user":"ou_xxx"}
{"ts":"2026-04-01T23:00:00.050Z","event":"after_tool_call","tool":"exec","result":"total 8\
drwxr-xr-x 12 dc staff 384 Apr 1 23:00","error":null,"duration":50,"session":"agent:main:feishu:direct:ou_xxx"}
Sensitive Data Handling
Auto-redact sensitive fields:
function redactSensitive(obj) {
const sensitive = ['apiKey', 'token', 'password', 'secret'];
for (const key of Object.keys(obj)) {
if (sensitive.some(s => key.toLowerCase().includes(s))) {
obj[key] = '[REDACTED]';
}
}
return obj;
}
Statistics Analysis
Periodically analyze audit.log:
# Count tool usage
grep "before_tool_call" audit.log | jq -r .tool | sort | uniq -c | sort -rn
# Count errors
grep "after_tool_call" audit.log | jq -r '.error' | grep -v null | wc -l
# Count sessions
grep "before_tool_call" audit.log | jq -r .session | sort -u | wc -l
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install audit-log-hook - After installation, invoke the skill by name or use
/audit-log-hook - Provide required inputs per the skill's parameter spec and get structured output
What is Audit Log Hook?
Logs all tool calls before and after execution with parameters, results, errors, and session info for auditing and debugging. It is an AI Agent Skill for Claude Code / OpenClaw, with 95 downloads so far.
How do I install Audit Log Hook?
Run "/install audit-log-hook" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Audit Log Hook free?
Yes, Audit Log Hook is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Audit Log Hook support?
Audit Log Hook is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Audit Log Hook?
It is built and maintained by hanxiao-bot (@hanxiao-bot); the current version is v1.0.0.