All guides

How do I respond to a security incident involving an AI coding agent?

Updated

Short answer

Treat it like any incident, with one difference: the agent's actions are your evidence, and that evidence can disappear fast. Preserve the session transcript first. Then revoke every credential the agent could reach, halt agents through managed settings, and rebuild the timeline from what actually ran. Check for persistence (rules files, hooks, keys) before you call it contained, then work out whether a reporting clock has started.

Why agent incidents are different#

An agent acts with the developer's credentials. Anything the developer can reach, the agent can reach too, usually without a second approval.

It also produces the record of what it did. Capture that record early, or you'll end up trusting the agent's own summary of its own session.

NIST's current incident response guide, SP 800-61 Rev. 3 (April 2025), treats incident response as part of your wider cybersecurity risk management under CSF 2.0. That fits agents well. How bad the first hour gets depends on what you set up beforehand: credential scope, logging and a way to halt agents.

First hour: preserve, then contain#

Order matters, because some containment steps destroy evidence.

  • Preserve the transcript. Claude Code stores session transcripts locally in plaintext under ~/.claude/projects/ and keeps them for 30 days by default. Copy them off the laptop before anyone reimages it. Other agents keep their logs in other places, so find them now.
  • Snapshot the machine state. Grab shell history, the repo working tree, the git reflog and agent config files. Don't clean anything up first.
  • Revoke credentials. Rotate every token, key and cloud credential the agent could read, including ones you don't think leaked. If your credentials are short-lived and narrowly scoped, this is a small job. If they're long-lived, you'll be hunting for a while.
  • Halt agents. Use managed settings and credential revocation. An email asking people to stop isn't enough. In Claude Code, administrators can also set allowManagedHooksOnly in managed settings to control which hooks run.
  • Pull provider and platform logs. GitHub's personal security log only covers the last 90 days, so grab it early. Do the same for cloud audit logs and package registry histories.

Scope it: what did the agent actually do#

Rebuild a timeline of commands, file edits, network calls and pushes. Then compare it with what the agent said it did.

Look hard at four things:

  • Outbound. Did secrets or code go anywhere? Check curl, git push, package publish and MCP calls.
  • Persistence. Look for new or edited rules files, hooks, MCP configs, shell startup files, cron entries and SSH keys. If planted instructions steered the agent, a rules file can re-infect the next session. See how coding agents persist past the session.
  • Destruction. Look for deleted backups, cleared logs or rewritten history. Each of these also damages your timeline.
  • Irreversible actions. Published packages, deploys and external emails can't be recalled, so put them first in your impact assessment.

Ask what started it. Prompt injection from a repo file, ticket or dependency looks different in the transcript from a poisoned extension or an agent that did the wrong thing at full speed. Each one needs a different fix.

What the built-in controls give you after the fact#

The built-in controls help, but each one has limits.

ControlHelps withLeaves a gap
Permission rulesStops listed commands and pathsMatches command text, so the same action written another way can slip past
Managed settingsHalts or restricts agents across the fleetControls configuration, not what a given command does
HooksA real check before each tool callExit code 2 blocks. For most hooks, any other failure lets the action go ahead
SandboxLimits reach and damageDoesn't tell you what happened inside the boundary
Approval promptsA human in the loopAnthropic reports users accept 93% of them anyway, so a click is weak evidence of review

By default, none of these gives you a per-action record from outside the agent. That's the thing you'll wish you had.

Decide whether a clock started#

Reporting duties depend on what the agent did, not on the fact that an agent did it. Exposed customer data, a material cyber event and an EU AI Act trigger each come with different obligations. Bring legal in early and use our guide to AI agent incident reporting requirements.

Checklist you can run today#

  • Know where each agent's transcripts and logs live, and how long they're kept.
  • Keep credentials on laptops short-lived and scoped, and keep production credentials off laptops entirely.
  • Make sure one person can push a managed-settings change that halts agents, and test it.
  • Make agent config and rules files read-only, and watch them for changes.
  • Name an owner for agent incidents in your runbook.
  • Run a tabletop exercise with three scenarios: a stolen token, a poisoned rules file and a force-push.

Where Harden fits#

Harden Agentic Integrity Foundation (AIF) runs on the developer laptop, outside the agent, at the agent's pre-execution hook. Before any command, file edit or push runs, AIF checks it against the session's intent. It decides locally in about 28 ms, and nothing leaves the machine. If the check can't run, the action doesn't run.

During an incident, that gives you two things. AIF can stop a bad action before it runs. It also records every decision, so you can rebuild the timeline from Harden's Records instead of the agent's own account, and export those Records to a SIEM.

AIF starts watch-only, so you can see what agents do before you enforce anything. It adds a layer on top of scoped credentials and egress policy and doesn't replace them.

FAQ

Related questions

What should I do first when a coding agent does something dangerous?

Preserve the evidence, then contain. Copy the session transcript and shell history off the machine. Then revoke the credentials the agent could reach and halt agents through managed settings. If you reimage the laptop first, you destroy your timeline.

How long do coding agent transcripts last?

It depends on the tool. By default, Claude Code keeps local transcripts under ~/.claude/projects/ for 30 days, and you can change that with cleanupPeriodDays. Check retention for every agent you use, and copy transcripts before the investigation starts.

Do I have to report an incident caused by an AI agent?

Duties depend on the outcome, not the tool. If customer data was exposed or the event is material, the normal breach and disclosure rules apply. Involve legal early and check the reporting requirements guide.

How do I know the agent didn't leave something behind?

Check rules files, hooks, MCP configs, shell startup files, cron entries and SSH keys for changes made during the session. Any of them can carry instructions or access into future sessions. Afterwards, make agent config read-only and watch it for edits.

Can I rely on the agent's own summary of what it did?

No. Treat the summary as a claim you need to verify. Compare it with the transcript, shell history and provider logs, and give more weight to records created by a control outside the agent.

Sources

  1. NIST SP 800-61 Rev. 3: Incident Response Recommendations and Considerations for Cybersecurity Risk Management
  2. Data usage | Claude Code Docs
  3. Hooks | Claude Code Docs
  4. Reviewing your security log | GitHub Docs
  5. Claude Code auto mode | Anthropic

Start free at harden.run

Full Enterprise access, free for 60 days: unlimited developers, custom policies, centralized visibility, no commitment.