Safeguard
Security Guides•

What should you log from AI coding agent sessions, and for how long?

Log who ran the agent, which tools it called, which files changed and which approvals were given. Keep prompts for a shorter window than action records.

Safeguard Security Team
3 min read

Log the user, the agent and version, the repository, each tool call, each file changed, and each approval granted or denied. Keep action records longer than raw prompts, because prompts often contain sensitive text. Set retention by what an investigator or auditor will need, not by what is easy to store.

Two kinds of log

Action records say what happened: command run, file written, tool server called, approval given. They are small, structured, and rarely sensitive.

Content records say what was said: prompts, model replies, pasted logs. They are large, and they can contain secrets, personal data, and proprietary code. OWASP's sensitive information disclosure guidance names security credentials and source code among the data types at risk, which is a fair reason to treat content logs with care.

Treating them differently solves most of the retention argument.

Suggested fields and retention

RecordFieldsSuggested handling
Session startUser, agent, version, repo, timeKeep with action records
Tool callTool, arguments summary, result statusKeep with action records
File changePath, commit or diff hashKeep with action records
ApprovalPrompt shown, answer, who, whenKeep with action records
Prompts and repliesFull textShorter window, restricted access, redact known secret patterns

Pick the actual durations with your legal and compliance owners. Common drivers are your incident response needs, customer contract terms, and any framework you are assessed against. This post does not set a number because the right one depends on those inputs.

Steps to set it up

  1. Check what the tool emits. Some tools produce telemetry, some do not. Write down which fields exist before promising anything.
  2. Send action records to the same place as other security logs so responders do not need a second console.
  3. Restrict content logs. Fewer people, an access log of its own, and a defined delete date.
  4. Test a lookup. Pick a recent change and trace it from commit back to the session and approval. If you cannot, fix the gap before rollout.
  5. Write down who may read content logs and why. Developers will ask, and a clear answer builds trust.

What logging will not do

OWASP is plain on this point: logging, monitoring, and rate limiting will not prevent excessive agency, but they can limit the damage it causes. Logs shorten the time to understand an incident. They do not replace permissions and review. Pair this post with agent audit log fields for tool calls for a deeper field list.

A note on privacy

Logging a person's prompts is monitoring. Tell developers what you collect, who sees it, and how long it stays. Silent collection costs more in trust than it returns in safety.

Safeguard offers compliance and evidence automation and agent identity, which can help you tie actions to an identity and keep the evidence tidy.

Quick check

Do we need to keep full prompts?

Usually not for long. Keep action records, and keep prompts only as long as your investigation needs justify, under tighter access.

What if the tool has no logs at all?

Log what you can around it: git history, proxy logs, and CI records. Treat missing logs as a finding when you evaluate the tool.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.