AID-76Required
Redact secrets from agent session logs
Agent session logs pass a redaction step before they leave the developer's machine or the runner. Keys, tokens and passwords never reach the log store in clear text.
How to do it
Logged commands carry what the agent typed, and agents paste keys into commands, such as curl -H "Authorization: Bearer …". Log only what the activity log needs. Keep prompts, tool output and raw API bodies off unless you are debugging. In Claude Code these are off by default. Run every export through a collector that masks known key shapes, such as the OpenTelemetry Collector's redaction processor. Mask by value patterns, such as sk_live_, ghp_ and AKIA, and by key names that contain token or secret. Then scan the stored logs with a secret scanner each day, and rotate any key it finds. The same idea for app logs is Keep personal data and secrets out of logs.
Examples
YAML example
processors:
redaction:
allow_all_keys: true
blocked_key_patterns: [".*token.*", ".*secret.*", ".*password.*"]
blocked_values:
- "sk_live_[A-Za-z0-9]+"
- "gh[pousr]_[A-Za-z0-9]{36,}"
- "AKIA[0-9A-Z]{16}"
Python example
import re
SECRET_SHAPES = re.compile(r"sk_live_[A-Za-z0-9]+|gh[pousr]_[A-Za-z0-9]{36,}|AKIA[0-9A-Z]{16}")
def mask_secrets(line: str) -> str:
return SECRET_SHAPES.sub("****", line)
JavaScript example
const SECRET_SHAPES = /sk_live_[A-Za-z0-9]+|gh[pousr]_[A-Za-z0-9]{36,}|AKIA[0-9A-Z]{16}/g;
const maskSecrets = line => line.replace(SECRET_SHAPES, '****');
How to check
Start a session that runs echo sk_live_TESTONLY000000000000. Within five minutes the log store shows the command with the key masked. A daily secret scan of the log store finds no key, or opens a ticket naming it.
Sources
Related rules
- AID-34 Log what every agent session does in AI-assisted development
- OPS-9 Keep personal data out of logs in Operations and observability
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-assisted-development/isolation-and-credentials/redact-agent-logs">Agent Wranglers AI-assisted development playbook</a>. In code you write, add a comment next to it with the same link.