Skip to content
groundedby
Waitlist

Security

How to redact secrets and personal data from agent logs

AI agent session files capture API keys, tokens, emails and customer data. How to find them in Claude Code and Codex logs, and how to mask them before sharing.

Updated October 29, 2026 // Markdown

Agents read your .env files, print command output and paste API responses into their context. All of it lands in the session file. Before you share a session with anyone - a colleague, a bug report, a buyer - assume it contains secrets.

What ends up in session files

  • Keys and tokens read from .env files, config files or command output.
  • Connection strings with passwords inside them.
  • Emails, names and phone numbers from databases, logs and customer records.
  • Internal hostnames, IPs and paths that reveal how your systems are built.
  • Your own home directory, which usually contains your username.

Find them

Search your session files for common secret formats. A starting set:

cd ~/.claude/projects
# Provider keys with known prefixes
grep -rEl 'sk-(ant|proj|live)-[A-Za-z0-9_-]{20,}|ghp_[A-Za-z0-9]{36}|xox[bp]-[A-Za-z0-9-]{20,}|AKIA[0-9A-Z]{16}' . | head
# Private keys and connection strings
grep -rEl 'BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY|postgres(ql)?://[^ ]+:[^ ]+@' . | head
# Email addresses
grep -rEoh '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' . | sort | uniq -c | sort -rn | head

Dedicated scanners do this better. gitleaks and trufflehog both scan plain directories, not only git repositories:

gitleaks dir ~/.claude/projects --report-path leaks.json
trufflehog filesystem ~/.claude/projects

Mask them

For a session you will share:

  1. Copy it. Never edit the original in place; agents may still read it.
  2. Replace each secret with a typed placeholder, so the session still makes sense: sk-ant-... becomes [ANTHROPIC_KEY], an email becomes [EMAIL_1], a customer name becomes [CUSTOMER_1].
  3. Keep placeholders consistent across the session, so [EMAIL_1] is the same person every time.
  4. Replace your home path (/Users/yourname/) with ~/.
  5. Read the result. Automated tools miss names, addresses and anything business-sensitive in plain prose.

Rotate what leaked

If a live key sat in a session that was synced, shared or uploaded anywhere, rotate it at the provider. Masking the file does not un-share it.

Prevent it

  • Keep secrets out of the agent's reach: deny reads of .env files in your agent's permission settings where it supports them.
  • Use a secrets manager and short-lived tokens, so a leaked value expires.
  • Review before sharing, every time.

groundedby's marketplace will run this redaction on your machine and show you the masked session before anything is offered. Privacy model.

Questions

Is deleting a key from the log enough if it leaked?+

No. If a live key appears in a session you shared or synced anywhere, rotate it. Redaction protects what you share next; rotation fixes what already leaked.

Can I just search for the word "key"?+

It helps, but keys rarely sit next to the word key. Search for the known formats of the services you use, for long random strings, and for email addresses.

Waitlist

Your sessions, your call.

We are building an opt-in marketplace where developers license redacted sessions they pick, one by one. Join to hear first.

Your email and the side you picked. Nothing else. Privacy