How to Maintain Tamper-Proof Audit Trails for AI Agents
A standard log file can be edited, truncated, or deleted after the fact — if an AI agent or attacker modifies your logs, you lose the evidence trail. SafeClaw by Authensor produces hash-chained audit logs where every entry includes a cryptographic hash of the previous entry, making any tampering immediately detectable. If a single log entry is modified, inserted, or deleted, the hash chain breaks and verification fails. This gives you audit trails that regulators, auditors, and security teams can trust.
Quick Start
npx @authensor/safeclaw
Scaffolds a .safeclaw/ directory with hash-chained auditing enabled by default.
How Hash-Chaining Works
Each audit entry includes a prevHash field containing the SHA-256 hash of the previous entry. This creates an unbreakable chain:
Entry 1: { data: ..., hash: H1, prevHash: null }
Entry 2: { data: ..., hash: H2, prevHash: H1 }
Entry 3: { data: ..., hash: H3, prevHash: H2 }
Entry 4: { data: ..., hash: H4, prevHash: H3 }
If someone modifies Entry 2, its hash changes. Entry 3's prevHash no longer matches, and verification fails at that point. You know exactly where the chain was broken and which entries are suspect.
Step 1: Configure Hash-Chained Auditing
# .safeclaw/config.yaml
audit:
enabled: true
hashChain:
enabled: true
algorithm: "sha256"
includeFields:
- timestamp
- action
- effect
- agentId
- matchedRule
- requestDetails
destination: "logs/audit.jsonl"
rotation:
maxSize: "100MB"
maxAge: "90d"
compress: true
Step 2: Understand the Audit Entry Format
Each log entry is a self-contained JSON object with chain metadata:
{
"sequence": 1847,
"timestamp": "2026-02-13T14:23:01.847Z",
"action": "file.write",
"effect": "deny",
"agentId": "coding-assistant-01",
"matchedRule": "block-config-writes",
"requestDetails": {
"path": ".env.production"
},
"hash": "sha256:3f2a91bc4d...",
"prevHash": "sha256:7e1b83af2c..."
}
The hash field is computed over all data fields plus prevHash, creating the chain.
Step 3: Verify Chain Integrity
Run periodic verification to confirm your audit trail has not been tampered with:
npx @authensor/safeclaw audit verify logs/audit.jsonl
Audit Trail Verification
━━━━━━━━━━━━━━━━━━━━━━━━
File: logs/audit.jsonl
Entries: 24,847
Chain status: VALID ✓
First entry: 2026-01-15T09:00:01Z (sequence 1)
Last entry: 2026-02-13T14:23:01Z (sequence 24847)
No gaps detected.
No hash mismatches detected.
If tampering is detected:
Chain status: BROKEN ✗
Break detected at sequence 12,445
Expected prevHash: sha256:7e1b83af2c...
Actual prevHash: sha256:9a4c22de8f...
Entries 12,445 through 24,847 may have been tampered with.
Step 4: Configure Immutable Storage
For maximum tamper resistance, write audit logs to append-only storage:
audit:
destination:
primary: "logs/audit.jsonl"
secondary:
- type: "s3"
bucket: "company-audit-logs"
prefix: "safeclaw/"
objectLock: true # S3 Object Lock prevents deletion
- type: "syslog"
host: "syslog.internal.company.com"
port: 514
protocol: "tcp"
Writing to multiple destinations simultaneously means an attacker would need to compromise all storage systems to erase evidence.
Step 5: Set Up Automated Verification
Schedule regular chain verification as part of your operations:
# Cron job or CI schedule
Run verification daily
0 6 * npx @authensor/safeclaw audit verify logs/audit.jsonl --alert-on-failure
Configure the --alert-on-failure flag to send notifications if the chain is broken:
audit:
verification:
schedule: "daily"
alertWebhook: "${SECURITY_ALERT_WEBHOOK}"
retainVerificationProofs: true
Step 6: Export for Compliance
Generate audit reports for compliance reviews:
# Export all actions for a date range
npx @authensor/safeclaw audit export \
--from "2026-01-01" \
--to "2026-02-13" \
--format csv \
--output compliance-report-q1.csv
Export with chain verification proof
npx @authensor/safeclaw audit export \
--from "2026-01-01" \
--to "2026-02-13" \
--format pdf \
--include-verification-proof \
--output compliance-report-q1.pdf
The PDF export includes the hash chain verification proof, which auditors can independently verify.
Why SafeClaw
- 446 tests covering hash-chain integrity, verification, and edge cases
- Deny-by-default — every action attempt (allowed and denied) is logged in the chain
- Sub-millisecond evaluation — hash computation adds negligible overhead
- Hash-chained audit trail — the core feature: cryptographic tamper detection built into every log entry
- Works with Claude AND OpenAI — one tamper-proof audit trail for all your AI agents
Cross-References
- Tamper-Proof Audit Trail Explained
- Immutable Audit Log Pattern
- Audit Trail Specification Reference
- How to Log Every AI Agent Action for Compliance
Try SafeClaw
Action-level gating for AI agents. Set it up in your browser in 60 seconds.
$ npx @authensor/safeclaw