How do I audit which commands an AI coding agent ran on a developer's laptop?
Updated
Short answer
Turn on your agent's built-in telemetry, but don't stop there. By default, Claude Code's OpenTelemetry export leaves out command text and skips tool_result events for rejected calls, and its local transcripts are deleted after 30 days. Auditors want to know what was attempted, what was decided and why. So record every action decision at the agent's pre-execution hook, tie each record to its session and ship it off the laptop to central storage or your SIEM.
The first audit question is usually simple: "What did the agent run on that laptop last Tuesday?"
Most teams can't answer it. The data is scattered and partial, and it sits on a disk that deletes it.
What native telemetry gives you#
Take Claude Code as the example. It can export OpenTelemetry events, including tool events and a tool_result event when a tool call completes (Claude Code monitoring docs).
Here's what you don't get by default:
- Command text. Tool parameters and input arguments, including Bash commands, are off unless you set
OTEL_LOG_TOOL_DETAILS. Without it, you know a tool was called but not what it ran. - Prompt text. It's redacted unless you set
OTEL_LOG_USER_PROMPTS=1. - Rejected-call results. The
tool_resultevent isn't emitted when a tool call was rejected, so that event alone won't show you what was stopped. - A reason. Even when you can see an outcome, the export doesn't tell you what the session was trying to do.
Turn on both variables for every developer, not just the ones who opt in.
Local files and shell history#
Claude Code keeps transcripts and history under ~/.claude. It deletes those files once they're older than cleanupPeriodDays, which defaults to 30 days and can be set as low as 1. They aren't encrypted at rest, so OS file permissions are the only protection (Claude Code docs).
That makes the local record short-lived and readable by anything running as that user. Use it for debugging. Don't present it to an auditor as evidence.
Don't assume shell history covers you either. Have an agent run a harmless command containing a unique string, then search ~/.bash_history or ~/.zsh_history. If the string isn't there, cross that source off your list.
What an auditor actually asks#
Auditors want records they can sample, not a firehose. For each action they'll ask for:
- Who: the named developer and the device.
- Which agent: Claude Code, Codex, Cursor or another, with its version.
- Where: the repo and working directory.
- The action: the exact command, file edit or push, as the agent proposed it.
- The verdict: allowed, blocked, asked or rewritten.
- The reason: which rule or judgment decided, and what the session was trying to do.
- When, and in which session.
After-the-fact telemetry covers some of this. The hard parts are the proposed action, the verdict and the reason, because you need them at the moment of decision.
Hooks are where you capture them. A Claude Code hook receives session_id, transcript_path and cwd, and tool events add tool_name and tool_input (Claude Code hooks reference). A hook that logs before execution records what the agent attempted, not only what finished.
Make the record trustworthy#
A log only counts as evidence if it's complete and the agent can't edit it. Check three things:
- Failures don't leave silent gaps. In Claude Code, a hook that crashes, doesn't start or prints invalid JSON is a non-blocking error, and the action goes ahead. The docs say to use exit code 2 if the hook enforces policy. Test what happens when your hook breaks.
- The agent can't change it. If the agent can edit its own settings or log files, the harness grades its own homework. Keep the hook and the log writer in configuration that developers and agents can't change.
- Records leave the laptop fast. Ship them to central storage or a SIEM more often than the local cleanup window, or the sweep wins.
For the org-wide view, see monitoring coding agent activity across engineering. For how hooks work, see what Claude Code hooks enforce.
Map it to change management#
Your existing controls already fit. An agent's actions are changes made with a developer's credentials, so treat them that way:
- Authorization: a policy says which actions are allowed, and the record shows each action was checked against it.
- Separation of duties: the agent proposes, and something outside the agent decides.
- Traceability: every production-bound push links back to a session and a decision.
- Exceptions: when someone overrides a rule to allow an action, the record shows who approved it.
Approval prompts won't give you this. In Anthropic's study of 1,053 testers, people caught 13.6% of dangerous commands and approved 93% of prompts anyway. A click isn't a control record.
Where Harden fits#
Harden Agentic Integrity Foundation (AIF) runs on the developer laptop, outside the agent, at the agent's pre-execution hook. It checks every command, file edit and push against the session's intent before it runs. Verdicts take about 28 ms and are made locally, so nothing leaves the machine.
Harden records every decision (allow, block, ask, redact or log only) with the reason the agent was given, and you can export the records to a SIEM such as Splunk or Coralogix. One policy covers every agent. It starts in watch-only mode, so you have records before you enforce anything. Agents average 145 actions per session, so this has to happen automatically. See the AIF trust page.
It's one layer of defense, not a full perimeter. It doesn't replace scoped credentials or egress policy, and it can't contain a process that's already malicious.
FAQ
Related questions
Does Claude Code log the commands it runs?
Its OpenTelemetry export includes tool events, but command text and tool arguments are off unless you set OTEL_LOG_TOOL_DETAILS. It also keeps local transcripts, which are deleted after 30 days by default.
Can I rely on shell history to audit an agent?
Don't assume you can. Have an agent run a harmless command with a unique string, then search the history file. If the string isn't there, that source won't help you.
How long should agent audit records be kept?
Use the retention period you already apply to change-management or security records. What matters most is getting records off the laptop well before local cleanup deletes them.
Does source code have to leave the laptop to keep audit records?
No. Harden checks each action on the machine and makes the decision locally. What you export to your SIEM is a decision record, so agree with your reviewers which fields it should contain.
What should I turn on first?
Enable OpenTelemetry with tool details for every developer. Then run a watch-only check at the pre-execution hook for a few weeks, so you can see attempts and decisions before you enforce anything.