AI Coding Agent Audit Trail: How to Build a Tamper-Evident Log

How to build an AI coding agent audit trail you can trust: append-only events, hash chaining, signed anchors, and what a tamper-evident log still cannot prove.

Kumar NihalNovember 24, 20267 min read
On this page

AI Coding Agent Audit Trail: How to Build a Tamper-Evident Log

By Kumar, founder of Causly and creator of PCSKit. Last updated: November 24, 2026.

Quick answer: An AI coding agent audit trail is a record of what an agent did, such as commands run, files changed and tests executed, that you can check later. To make it tamper-evident, write events to an append-only log, link each entry to the previous one with a hash, and keep a signed copy of the latest hash somewhere the agent cannot write.

Disclosure: I build PCSKit, an open-source tool that records agent evidence, and describe it in one section near the end. The rest of this post draws on OWASP, IETF and EU sources linked in Sources.

What a trustworthy audit trail needs#

  1. It is written by something other than the agent being audited.
  2. Entries are append-only and linked by hashes.
  3. A signed copy of the latest hash is stored outside the log.
  4. Each fact says where it came from.
  5. Secrets are kept out of what is recorded.
  6. It states what it cannot prove.

What is an AI coding agent audit trail?#

It answers one question: what did the agent actually do? An agent's end-of-session summary cannot answer it, because the summary is the agent's own account. It can leave out a failed command or claim tests passed when they never ran.

OWASP's guidance on agent execution evidence makes the same point in general terms: a supplier can sign a record that omits actions or describes a run that never happened, and a recorder fed only by the component keeps that component's account of events.

Why isn't a normal log file enough?#

A plain log can be edited. OWASP's Logging Cheat Sheet lists attackers preventing writes or damaging the log to cover their tracks, and recommends building in tamper detection so you know if a record was modified or deleted, and copying logs to read-only media as soon as possible.

What is a tamper-evident log?#

A log where tampering becomes detectable, not impossible. Certificate Transparency is the best-known example. RFC 9162 says its append-only logs do not themselves prevent misissuing certificates, but they let interested parties detect it.

Apply the same idea to an agent: you cannot stop someone with file access from editing a database, but you can make the edit show up.

How does a hash chain work?#

Each event stores the hash of the previous event. Change one entry and every later hash stops matching. Here is a minimal version:

js
import { createHash } from "node:crypto";

const GENESIS = "0".repeat(64);

const hashEvent = (prev, event) =>
  createHash("sha256").update(prev + JSON.stringify(event)).digest("hex");

function append(log, event) {
  const prev = log.length ? log[log.length - 1].hash : GENESIS;
  log.push({ event, prev, hash: hashEvent(prev, event) });
}

function verify(log) {
  let prev = GENESIS;
  for (const entry of log) {
    if (entry.prev !== prev) return false;
    if (entry.hash !== hashEvent(prev, entry.event)) return false;
    prev = entry.hash;
  }
  return true;
}

In production, serialize events canonically (for example, sorted keys), or the same event can hash differently. Editing, deleting from the middle, or reordering entries all make verify fail.

What can a hash chain not detect?#

Two things:

  • Truncation. Delete the newest entries and the remaining chain still verifies.
  • A full rewrite. Someone with write access can edit entries and recompute every hash. A Drupal audit-chain module documents this limit: plain SHA-256 catches careless edits and accidental corruption, but not someone with database access who recomputes the chain.

If a tool claims tamper-proof from a hash chain alone, ask about these two cases.

How do you close the gap with a signed anchor?#

Take a small summary of the log (head hash, last entry id, entry count, timestamp), sign it with a key stored outside the log's reach, and keep the signed file somewhere else. To verify, check the chain, then the signature, then that the anchored entry still exists with the same hash and count.

Two details matter:

  • Use public-key signatures. OWASP notes that anyone who can verify a message authentication code with a shared secret can also forge one, so it cannot attribute authorship between those holders.
  • Know what outside witnesses add. A transparency log can make changes after submission detectable, but it cannot reveal an event that was never submitted.

Who should write the log?#

Not the agent. OWASP advises identifying an observer that gets event data independently of the component's own reports, and keeping its records where the component cannot rewrite them. For a coding agent, that means recording from sources you can observe yourself: git state, file hashes, and test commands you ran and whose exit codes you saw.

Label each fact by source. "Observed by the recorder," "claimed by the agent" and "inferred from other facts" are different strengths of evidence and should not be mixed.

What should an agent audit log record?#

OWASP's Logging Cheat Sheet suggests recording when, where, who and what for each event. For a coding agent that usually means session start and end, commands and exit codes, files changed (by hash), repository state and test runs.

Leave out or mask access tokens, passwords, encryption keys, connection strings and similar secrets. Use a structured format such as JSON, and sanitize input to prevent log injection through carriage-return and line-feed characters.

What can an audit trail not prove?#

  • That nothing else happened. OWASP warns that an empty report from a recorder that may have dropped events is no basis for calling a run clean.
  • That an agent told the truth. Claims can be labeled and compared with evidence, not proven.
  • Anything outside what the observer could see. A recorder at one boundary cannot establish actions that never crossed it.

Decide what happens when recording fails, too. OWASP notes that halting on every logging failure turns an outage into an availability problem, so choose by the action's risk and make any loss of evidence visible.

Do you need an audit trail for EU AI Act compliance?#

Possibly, but not automatically. Article 12 requires high-risk AI systems to technically allow automatic recording of events over their lifetime. Whether a coding agent counts as part of a high-risk system depends on how it is used, and the article does not prescribe hash chains. This is not legal advice; check the current application dates and your own classification with official sources.

How does PCSKit build a tamper-evident audit trail?#

PCSKit is a local-first CLI and MCP server (Apache-2.0) that hands work from one AI coding agent to the next. Its README and docs/DECISIONS.md describe the audit side:

  • Events are append-only (enforced with SQLite triggers) and chained with SHA-256 over the previous hash plus content. pcs verify detects edited, deleted-in-the-middle or reordered events.
  • Every fact is tagged verified (PCS observed it), reported (an agent or person claimed it) or inferred. AI completion claims are never verified.
  • pcs test runs the command itself and records the exit code, so "tests passed" is observed, not claimed.
  • pcs anchor writes a small signed JSON (head hash, last event id, count, timestamp) using a local ed25519 key stored outside the project. pcs verify --anchor <file> then catches truncation and a recomputed rewrite. The anchor should be kept outside the project, such as another disk or a commit.
  • pcs export writes the log as JSON or Markdown. A JSON export can be checked without PCSKit, and pcs export --check <file> re-verifies one.
  • Secrets are redacted before storage, and files flagged sensitive are listed by name and never read.

Its documented limits: someone who can rewrite both the log and the anchor on your machine can forge history, redaction is pattern-based, and reported claims are labeled, not proven. Source: github.com/KNIHAL/pcskit and pcskit.causly.in/docs.

FAQ#

What is the difference between tamper-evident and tamper-proof?#

Tamper-proof means tampering cannot happen. Tamper-evident means it can happen but will be detected. Hash chains and signed anchors give you the second, not the first.

Can a hash chain stop an agent from deleting its own logs?#

No. It makes deletion visible at the next verification. To make it hard in the first place, keep the log and the signing key where the agent has no write access.

Is a SHA-256 hash chain enough?#

For catching accidental corruption and careless edits, yes. Against someone who can rewrite the whole log, you also need a signed anchor stored elsewhere.

Do I need a blockchain for this?#

For a single-machine, local log, no. A hash chain plus a signed anchor covers the detection goal. Wider public witnessing, as in Certificate Transparency, uses Merkle-tree logs with independent monitors.

Where should I store the anchor?#

Outside the project and outside the agent's write access: another disk, a git commit, or a ticket.

Sources#

Share
Kumar Nihal

Written by

Kumar Nihal

AI-first software engineer and founder of Causly. I build software, SaaS and AI systems, and write about it here. More about me

Get new posts by email

High-signal notes on AI, automation and building systems. No spam.

Keep reading

Insight

Why I Built PCSKit: Solving Context Loss in AI Coding Sessions

AI coding agents are productive, but their work can lose continuity when a context window fills up, a session gets interrupted, or developers switch between tools. I built PCSKit to solve this problem with local-first project continuity, evidence-based handoffs, and verifiable development history—so the next AI agent can continue from the actual project state instead of relying on an unreliable summary.

Nov 24, 2026
Insight

AI Coding Agent Handoffs: Why HANDOFF.md Needs Verifiable Evidence

Learn how to preserve context across AI coding agent sessions with reliable handoffs. Explore the limitations of traditional HANDOFF.md files, why task summaries aren't enough, and how Git state, test results, file changes, and verifiable evidence help agents resume development work with greater confidence.

Nov 24, 2026
Insight

MCP Tool Annotations Explained: Practical Examples, Defaults, and Security Best Practices

Understand MCP Tool Annotations and how they influence AI agent interactions with tools. Learn the four core annotations — readOnlyHint, destructiveHint, idempotentHint, and openWorldHint — with practical JSON examples, default behaviors, security considerations, common mistakes, and testing strategies for building reliable Model Context Protocol servers.

Nov 24, 2026