Blog

Agent transcripts are the new .env. Make what leaks from them worthless

For years, the file you didn't commit was .env. Everyone learned the rules: keep it out of git, out of Docker images, out of screenshots and out of Slack.

In November, two companies disclosed leaked credentials, and neither leak went through a .env file. Both went through transcripts.

Cursor's update on its October incident traces the chain step by step.[1] An attacker got an access key that Cursor had issued to Fireworks, a vendor it used for training and inference. With it, the attacker copied a bucket of coding-agent traces, mostly from 2025, that Cursor shared with Fireworks for model training. "A small number of those traces contained credentials that had not been redacted." Those credentials reached some of the SaaS tools Cursor uses, which held another credential, which the attacker used to put a malicious copy of the Claude Code extension on the cache behind Cursor's extension marketplace. Up to 5,000 people could have installed it in the roughly 11 hours it was up.

The same Fireworks incident reached Notion, whose advisory says it revoked Notion API keys it found in affected users' AI chat messages, and reported the third-party keys it found there to the vendors that issued them.[2]

Credit to both companies: these are detailed write-ups, and the rest of us can learn from them because they published the chain rather than a summary. Nothing here is unique to Cursor or Notion. Any tool that keeps what an agent saw, and passes it on, has the same shape. An agent's folder is now as sensitive as a .env file, and it needs the same care. That's half the fix. Care alone won't be enough, so this post is mostly about the other half.

How credentials get into transcripts

A coding agent's transcript is everything it saw and did: your messages, the files it read, every command it ran and that command's output. Agents read and run things all day, so credentials land in the transcript without anyone pasting them in:

  • The agent runs cat .env or printenv to debug a config problem, and the values are now tool output.
  • A failing request prints its own headers. An error body echoes the token it rejected. A connection string with a password shows up in a stack trace.
  • You type the password into the command yourself, as in PGPASSWORD=hunter2 psql, because it's quicker, and the agent runs it.

That last one gets a second copy. When you answer a Claude Code permission prompt with "Yes, and don't ask again", Claude Code saves the approved command as a rule in .claude/settings.local.json at the root of the repository,[3] password included. Claude Code adds the file to your global git excludes,[4] which keep it out of your commits and nothing else: a file you created by hand isn't covered, and docker build, a zip or a synced folder copies the file along, since none of them reads git's excludes. People have reported the plaintext credentials in this file since at least August 2025.[5]

None of this is a bug in one model or one tool. Agents keep records so that they can resume, remember and do the same thing with less friction next time. The record is the product working as designed.

Where transcripts go

On your laptop, the records pile up:

Then they travel, and each copy is a new place to leak from:

  • Into backups and sync. Home-directory backups, dotfile repositories and tools that sync sessions between machines copy them whole.
  • Into git and packages. Agent folders sit inside project folders, which get committed, zipped, copied into Docker images and published as packages.
  • Into training data. Cursor's exposed traces came from sessions outside Privacy Mode, which it was permitted to use for model training, kept in a bucket it shared with a vendor.[1]
  • Through inference. Every turn sends the conversation so far, tool output included, to the model's provider, and through any gateway or reseller in between.

The copy on your laptop is a target too. In August 2025, malicious versions of Nx on npm carried a prompt telling the developer's own AI coding tools to search the disk for .env and other configuration files.[9] A month later, the Shai-Hulud worm scanned developers' machines for GitHub tokens and cloud keys.[10] An attacker with a shell on a developer's machine doesn't need to know where the keys are kept. The transcripts already collected them.

Why redaction can't be the defense

The obvious fix is to scrub transcripts before they're stored or shared. Do it, but don't rely on it.

Secret scanners match formats: a provider's prefix and a long random string, such as ghp_ or AKIA. A password after PGPASSWORD=, mysql -p or sshpass -p is a word like any other in a command line, and often has no format to match.

Agents also transform what they see. They base64-encode a value to put it in a Kubernetes secret, split a connection string into its host, user and password, and quote part of an error back to you. Each of those is a copy of the secret that no pattern for the original matches. Redaction has to be right about every secret, in every record, for as long as the record is kept. An attacker needs it to be wrong once.

The same goes for the guards at the edges. A Claude Code rule such as Read(./.env) stops its file tools from reading .env, and covers cat and head too, but its docs say the rule doesn't reach a subprocess that reads the file indirectly, such as a Python script.[11] Set it, but don't count it as a boundary.

So treat transcripts as you treat .env files. Then assume they'll leak anyway, and make sure that what's in them is worth nothing by then.

Make what leaks worthless

A credential in a transcript is dangerous for as long as it works, and for whatever it can do. Both are choices.

The agent never holds a long-lived key. Your personal access token, your ~/.aws/credentials and your SSH keys stay out of the agent's environment. On a laptop, that means running the agent where those files aren't: a container, a VM or a user of its own. The agent gets credentials minted for its task, which expire on their own:

  • GitHub: an installation access token from a GitHub App expires after an hour,[12] and can be narrowed to chosen repositories and permissions as it's created. An agent that fixes one service gets contents: write on that service's repository, not everything your account reaches.
  • AWS: AssumeRole takes a session policy, and the session gets only what both the role and the policy allow. A session lasts from 15 minutes up to the role's maximum.[13] An agent that reads one log group gets logs:FilterLogEvents on that log group, for 15 minutes.
  • Google Cloud: tokens from service account impersonation are short-lived too, but they carry all of the service account's roles. Narrowing a single token works for Cloud Storage alone,[14] so give the agent a service account of its own, with only the roles its task needs.

The key that mints them lives somewhere else. The GitHub App's private key, or the credentials that assume the AWS role, are held by something the agent can ask but not read: a credential helper outside its environment, a broker on a socket or a process on another machine. Git's credential helpers and the AWS CLI's credential_process are how a tool asks for a credential when it needs one, but the boundary is where the helper runs: a helper that reads a private key from a file the agent can also read protects nothing. The agent can still print what it was given, as anything that runs a command can. What it was given is worth an hour of one repository.

Secrets are referenced, never typed. Write psql "$DATABASE_URL", not the URL, so that the command, and any rule saved from it, records a variable's name. The value still reaches the transcript if a command prints it, which is why the key behind it should be narrow too. For services that only issue long-lived keys, as many SaaS APIs do, give the agent a key of its own, scoped as narrowly as the service allows, so that rotating it breaks nothing of yours.

The record lives where the agent can't rewrite it. When something does leak, you need to know what the agent saw, what it ran and which credentials it held, from a record it couldn't edit. Short-lived credentials help here too. An organization's GitHub audit log can record which token made each call,[15] and a token minted for one task points to that task, if you keep a record of what you minted it for. Your personal token points to you, all year.

This answers a fair objection to hiding keys from agents: if the agent can do everything the key allows, hiding the key changes little. It changes a lot once the agent can't do everything the key allows. A token for one repository, for one hour, found in a transcript six months later, is worth nothing.

What to do this week

You can do most of this without changing tools:

  1. Rotate first. Treat anything that was ever in a transcript, a settings.local.json or an agent's memory file as exposed. Deleting the file doesn't reach git history, forks, backups or a vendor's bucket.
  2. Untrack the settings file. Run git rm --cached .claude/settings.local.json, and add the file to the repository's own .gitignore and .dockerignore, which travel with the repository where your global excludes don't.
  3. Keep less. Lower Claude Code's cleanupPeriodDays,[6] set CLAUDE_CODE_SKIP_PROMPT_HISTORY=1 for sessions that shouldn't be written to disk, and run claude purge to delete a project's transcripts now.[16] For scripted Codex runs, codex exec --ephemeral writes no session files.[17]
  4. Deny the obvious reads. Read(./.env) and Read(./secrets/**) deny rules in Claude Code[11] stop the casual leak, though not a determined one.
  5. Reference secrets, don't type them. Keep secrets in variables, and approve patterns, such as Bash(npm run *), rather than literal commands.
  6. Swap long-lived tokens for short-lived ones. Use a GitHub App on the agent's repositories in place of your personal token, and an AWS role with a session policy in place of your access keys.
  7. Scan agent folders. Add .claude/ and other agents' project folders to what your pre-commit hooks and CI scan, and scan ~/.claude and ~/.codex on your own machine, with a scanner that catches passwords inside commands, not only key formats.
  8. Check what you share. Read your agent tool's data settings, and know whether your sessions are used for training and who else holds them.

How we do it in kosem

kosem runs each agent in a microVM of its own, so we built these rules into where agents run rather than leaving them to each developer:

  • No long-lived keys in the environment. For GitHub, AWS and Google Cloud, the agent's tools ask a credential socket in its environment when they need a credential. kosem checks the agent's grant on each request, and mints a credential narrowed three times, by what the team allowed, what this agent was granted and what the command asked for: a GitHub token for chosen repositories that lasts an hour, or AWS credentials under a session policy. git, gh, gcloud and the AWS CLI use the socket with no setup, and no credential is written to the disk.
  • Static secrets for one command at a time. For services that only issue long-lived keys, a secret is passed to the one command that needs it, as a variable or as a file under /run/kosem/secrets, off the disk. Its value is redacted live from that command's output. Minted credentials are redacted the same way, in commands that were already running too.
  • The record out of the agent's reach. The transcript lives in kosem, not in the agent's environment, and kosem doesn't use it for training unless your organization opts in. Each credential issue goes into the audit log under the agent's own identity, with GitHub's hashed token or AWS's access key ID, so you can follow a credential from kosem's log into the provider's. AWS sessions also carry the agent's ID as their source identity, so CloudTrail names the agent itself.

Redaction is a backstop here too. A command given a secret can reveal it indirectly, and whoever directs an agent can have it show what it was granted. A GitHub token works for its hour. The same goes for a transcript kept in kosem: if one ever leaks, the minted credentials in it were redacted, and expired within the hour. What we can do is make what leaks narrow, short-lived wherever the service allows it, and tied to one agent.

Keep the transcripts, lose the keys

Agents keep records because records make them useful: they resume where they stopped, remember what worked and hand work to a teammate. We aren't going to stop writing transcripts, and we shouldn't. So stop putting things in them that outlive the task. A leaked transcript still exposes your code and your data, and that's worth preventing. But a transcript that holds a token for one repository, which expired last Tuesday, won't be the first step of the next supply-chain attack.

How kosem gives each agent an environment, an identity and access of its own, and keeps the record, is in the post that introduced it: Introducing kosem.

Notes

  1. Cursor, An update on our recent security incident, November 2026. ↩
  2. Notion, Fireworks AI incident, November 2026. ↩
  3. Claude Code's docs: Configure permissions. ↩
  4. Claude Code's docs: Settings, on settings.local.json. ↩
  5. Claude Code's issues: approved bash commands containing credentials are stored as is with plain text credentials in settings.local.json, August 2025. ↩
  6. Claude Code's docs: cleanupPeriodDays. ↩
  7. Codex's source: codex-rs/rollout/src/lib.rs, under CODEX_HOME, which is ~/.codex by default. ↩
  8. Codex's docs: Configuration reference, read 20 November 2026. ↩
  9. Nx, Malicious versions of Nx and some supporting plugins were published, August 2025. ↩
  10. CISA, Widespread supply chain compromise impacting npm ecosystem, September 2025. ↩
  11. Claude Code's docs: Read and Edit permission rules. ↩
  12. GitHub's docs: Authenticating as a GitHub App installation. ↩
  13. AWS's docs: AssumeRole. ↩
  14. Google Cloud's docs: Restrict a credential's Cloud Storage permissions. ↩
  15. GitHub's docs: Identifying audit log events performed by an access token. ↩
  16. Claude Code's docs: Environment variables and CLI reference, claude purge. ↩
  17. Codex's docs: CLI reference, codex exec --ephemeral. ↩