← 返回 Skills 市场
hanxiao-bot

Audit Log Hook

作者 hanxiao-bot · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
95
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install audit-log-hook
功能描述
Logs all tool calls before and after execution with parameters, results, errors, and session info for auditing and debugging.
使用说明 (SKILL.md)

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
安全使用建议
This skill appears intended to audit tool calls, but the example implementation is inconsistent and can leak secrets if used as-is. Before installing: (1) require a clear, consistent implementation that actually writes to a secured audit log (or explicitly documents relying on console logs); (2) implement robust redaction (recursive traversal, header keys like Authorization, nested fields, and pattern matching) and call it before logging; (3) avoid logging full param/result payloads — log hashes or truncated metadata where possible; (4) ensure logs are stored with access controls, rotation, and encryption; (5) review retention and privacy/compliance requirements for session and user identifiers. If you cannot verify these changes, treat the skill as unsafe for production/real-user data.
功能分析
Type: OpenClaw Skill Name: audit-log-hook Version: 1.0.0 The skill provides a standard implementation for auditing tool calls within the OpenClaw environment, as described in SKILL.md. It defines hooks to log tool parameters, execution results, and session metadata for security monitoring and debugging. The implementation includes a helper function for redacting sensitive information (API keys, tokens), and the behavior is entirely consistent with its stated purpose without any indicators of data exfiltration or unauthorized execution.
能力评估
Purpose & Capability
The skill's name and description match the provided hook code (before_tool_call / after_tool_call). However the SKILL.md declares an audit log file path (AUDIT_LOG) but the example hooks only console.log entries (they do not write to the audit.log). The code references process.env.OPENCLAW_STATE_DIR even though no environment variables are declared; this is plausible as an optional override but should be documented.
Instruction Scope
The instructions capture tool params, results, session keys, and user IDs which is consistent with auditing, but the provided redaction function is never invoked in the hook examples and is naive (only top-level key checks for tokens/passwords). Logging uses JSON.stringify and simple slicing of values which can still expose secrets in values or nested objects. The SKILL.md also shows shell grep/jq commands against audit.log even though the example hook does not write that file—this is an internal inconsistency. There is no guidance on log retention, access controls, or encryption.
Install Mechanism
Instruction-only skill with no install spec or code files; nothing is written to disk by an installer. This minimizes install-time risk but also means runtime behavior depends entirely on the agent’s execution of the provided hook code.
Credentials
No required environment variables or credentials are declared, which fits a local audit hook. The example references OPENCLAW_STATE_DIR (optional) and uses session/user identifiers; these are reasonable but should be declared if relied upon. No credentials are requested, which is proportionate.
Persistence & Privilege
The skill does not request always:true and is user-invocable with normal model invocation enabled. It does not request elevated system-wide privileges or modify other skills' configurations in the provided instructions.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install audit-log-hook
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /audit-log-hook 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release of Audit Log Hook for tool call auditing. - Records all tool calls using `before_tool_call` and `after_tool_call` hooks with detailed event context. - Automatically redacts sensitive parameters (such as apiKey, token, password, secret) in log entries. - Provides log format examples and analysis tips for usage stats, errors, and session counts. - Assists with security auditing, debugging, and monitoring tool usage.
元数据
Slug audit-log-hook
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Audit Log Hook 是什么?

Logs all tool calls before and after execution with parameters, results, errors, and session info for auditing and debugging. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 95 次。

如何安装 Audit Log Hook?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install audit-log-hook」即可一键安装,无需额外配置。

Audit Log Hook 是免费的吗?

是的,Audit Log Hook 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Audit Log Hook 支持哪些平台?

Audit Log Hook 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Audit Log Hook?

由 hanxiao-bot(@hanxiao-bot)开发并维护,当前版本 v1.0.0。

💬 留言讨论