Safeguard
Developer Tools•

What should you log from an AI coding agent, and what should you not?

Log sessions, tool decisions and MCP connections for audit. Keep prompts, tool output and raw API bodies off by default, since they hold sensitive content.

Safeguard Security Team
3 min read

Log who used the agent, which tools it called, what permission decisions were made and which MCP servers connected. Keep prompt text, tool output and raw API bodies off unless you have a clear reason, because they can hold secrets and customer data. Claude Code's documented telemetry follows this split, with sensitive fields as opt-ins.

Definitions

Metrics. Counts and totals, such as sessions, tokens and commits.

Events. Individual records, such as a tool decision or an API request.

OpenTelemetry (OTel). A standard way to export metrics, logs and traces to a backend you choose.

What to log, with the sensitivity

DataExample from the documented telemetryDefault stance
Session counts and active timeSessions started, active timeLog
Tool decisionsAccept or reject decisions for edit tools, tool decision eventsLog
MCP connectionsMCP server connection eventsLog
Token and cost usageTokens by type, costLog for spend control
Prompt textRedacted by default, only length recordedOff
Tool detailsBash commands, tool inputs, MCP names, opt-inDecide per risk
Tool outputOpt-in in tracesOff
Raw API bodiesFull request and response, including conversation historyOff, the most sensitive
Identity fieldsEmail and account IDs included when availableLog, with access controls

Steps

  1. Decide the questions you need to answer. Who ran an agent against this repository? Which servers connected? What did it run when something broke?
  2. Turn on metrics and event export to your own backend, so you control retention and access.
  3. Leave content logging off by default. The documentation says prompts are redacted by default and the settings for tool details, tool content and raw bodies are separate opt-ins.
  4. If you must capture commands, enable tool details for specific groups and restrict who can read the logs.
  5. Control who can enable export. The documentation says project-level settings cannot turn on the exporter variables. Only managed settings, the shell or user settings can, so deploy the configuration through managed settings.
  6. Treat identity fields as personal data. Apply your retention and access rules.
  7. Alert on patterns, such as a new MCP server connecting from many machines or a spike in rejected tool decisions.
  8. Test redaction. Run a session with a fake secret in the prompt and confirm it does not appear.

What logs cannot do

Logs record what happened. They do not prevent it, and an agent's own report of its actions should be checked against these records. Pair logging with permissions and approvals.

Quick check

Should we log full prompts for investigations?

Only if you accept holding sensitive content. Many teams log decisions and tool names and enable richer capture temporarily during an incident.

Who should read agent logs?

Security and platform owners, with access controls. Developers can see their own sessions if you wish.

Do other agents log the same fields?

No. Use this table as a checklist and check what your tool exports.

Where Safeguard fits

Safeguard offers asset discovery, agent identity and compliance evidence automation, which help turn agent activity records into audit evidence. You can start with a free scan at gold.safeguard.sh/scan.

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.