Keeping Secrets and Production Data Out of Coding Agent Prompts
Updated November 8, 2026 · first published August 21, 2026 · by the AQ team
When an AI coding agent runs, everything it puts into its context window (your instructions, the contents of every file it reads, and the output of every command it executes) is sent to the model provider as part of the prompt. If the agent reads a .env file or greps a log that contains a customer's email address, that material leaves your machine. The reliable defense is layered: keep secrets off the disk the agent works on, add the agent's own deny rules and sandboxes as a second line, keep production data out of the loop, and scan for what slips through. Pattern-based blocking alone is not enough: an agent has more than one way to read a file. Secrets also collect in the files agents write about their own work: a password typed into a command can become a standing approval rule, a transcript line, or a memory note, and from there a commit. The section on approval files, transcripts and memory shows that chain with reproducible tests and ends with a response checklist.
In AQ, organization and personal secrets reach agents, terminals and previews as environment variables, an agent that needs a missing secret asks for it with a secure card in the thread, and every saved value is replaced with [secret: NAME] in transcripts, run output, commit messages and pull request titles. AQ does not change what a CLI writes to its own settings files, so the checklist below applies on AQ machines and laptops alike.
What actually leaves the machine
Coding agents like Claude Code and Codex CLI execute locally, but the reasoning happens at a hosted API. Anthropic's documentation is explicit that Claude Code sends all user prompts and model outputs over TLS, as of August 2026. In practice the prompt is much bigger than what you type: it accumulates the file contents the agent reads, directory listings, test output, and shell results: that is how the model sees your codebase at all.
Three consequences:
- Reads are sends. Any file the agent opens becomes model input. A database URL in a config file, real values in a committed .env.example, or personal data in a fixture all travel with the session.
- Command output counts too. An agent that runs printenv, cats a credentials file while debugging, or tails a production log has put that output into the prompt without ever using a read tool.
- Telemetry is usually separate. Anthropic states that Claude Code's operational metrics never include code, prompts, or file paths, as of August 2026. The sensitive channel is the conversation itself, not the analytics.
Where the copies go: retention, training, and transcripts
The realistic risk is rarely a provider misusing your key. It is the number of places a copy of the conversation can end up, each with its own lifetime.
For Claude Code, as of August 2026: consumer accounts (Free, Pro, and Max) choose whether sessions can be used to train future models, with retention of five years when that setting is on and 30 days when it is off. Commercial accounts (Team, Enterprise, and API) are not trained on by default and carry a 30-day standard retention, with zero-data-retention available to qualified enterprise accounts. Transcripts shared through the /feedback, /bug, or /share commands are retained for five years regardless. Locally, Claude Code keeps session transcripts in plaintext under ~/.claude/projects/ for 30 days by default, so a secret that entered a session also sits on disk afterward.
OpenAI's published policies draw a similar line, as of August 2026: consumer ChatGPT and Codex content may be used for training unless you opt out, while business products and the API are not trained on by default. The pattern to internalize is that account type, not tool choice, usually decides your data terms. Run work agents under work accounts.
Layer 1: keep secrets off the agent's disk
The strongest control is the boring one: a secret the agent's environment never holds cannot end up in a prompt. Concretely:
- Fetch secrets at runtime instead of storing them in the repo. A secret manager (AWS Secrets Manager, Vault, Doppler, 1Password CLI) injects credentials into the process that needs them, so no .env file with production values sits in the working tree.
- Scope what remains. Where the agent's environment does need credentials (a GitHub token to push, a test database URL), make them short-lived and least-privilege: a token scoped to one repo, a database user that can read only non-production data.
- Separate dev values from real values. A .env full of localhost URLs and dummy keys is harmless in a prompt. Keep it that way by policy: production values live in the deployment platform's secret store, never in files a development checkout can reach.
Layer 2: deny rules, hooks, and sandboxes in the agent
The agents ship real controls, worth using while understanding what they gate. Claude Code supports deny rules in settings.json that block its file tools from reading matched paths:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
]
}
}
Claude Code also supports hooks that run before a tool call and can block or rewrite it, which teams use to redact known secret patterns before file contents reach the context. Codex CLI approaches the same problem from the sandbox side: as of August 2026, OpenAI documents a default sandbox where writes are limited to the workspace and network access is off unless explicitly enabled, plus approval policies that control when the agent must stop and ask.
The honest caveat: these are pattern and path gates, and an agent has many paths to a file's contents. A deny rule on a read tool does not by itself stop a shell command from printing the same file, and a redaction hook only sees the tool calls it intercepts. Treat agent-level rules as a valuable second layer that catches accidents, not as the boundary that makes secrets on disk safe. The boundary is layer 1.
Layer 3: keep production data out of the loop
Secrets are half the problem. The other half is production data: the customer records, tokens, and personal information that show up when an agent debugs against real systems. An agent that queries a production database to reproduce a bug pastes rows into its context; one that reads production logs reads whatever your users typed.
- Give agents sandbox datasets. A seeded or synthetic database that mirrors the production schema lets the agent write and test real queries with nothing sensitive in the rows.
- Keep production credentials out of development environments entirely. If the agent's environment cannot connect to production, the failure mode disappears rather than needing to be caught.
- Scrub what you paste. The human is an egress path too: a stack trace or log excerpt pasted into a prompt should be redacted as you would before posting to a public issue tracker.
Layer 4: catch what slips through
Assume something eventually gets past the first three layers, and instrument for it:
- Pre-commit scanning. Agent-written commits deserve the same gate as human ones. Tools like gitleaks and TruffleHog run as pre-commit hooks and block a commit containing a key before it becomes history, with push protection and CI scanning as the backstop.
- Review the session, not just the diff. The transcript records what the agent actually read and ran. Making transcripts easy to inspect is how you notice a session touched a file it should not have, the same practice that makes verifying agent work tractable.
- Rotate on exposure. If a real credential entered a session, rotate it. Retention windows mean a copy exists somewhere for a while; a rotated key makes the copy worthless.
Approval files, transcripts and memory: where agents record your secrets
Every place an agent records a command or a session is a potential credential store. When you approve a command permanently, Claude Code saves the command text as an allow rule. When a session runs, the transcript keeps every command and its output. When an agent takes notes for later, its memory files and handoff notes keep whatever it chose to write down. A secret typed into a command reaches all three, and each one is a file that can be committed, copied into a package or image, or read by anything else on the machine.
Threat model and boundary
- Asset: credentials that appear as literal text in a command: a database password after PGPASSWORD=, an SSH password after sshpass -p, a token in a curl header, a password inside a connection URL.
- Where the copies live: the project folder (.claude/settings.local.json, the shared .claude/settings.json, CLAUDE.md and CLAUDE.local.md, exported transcripts such as .specstory, handoff notes) and the agent's home folder (~/.claude/projects/ holds session transcripts and Claude Code's auto memory, in plaintext, kept 30 days by default as of November 2026).
- Who can read them: anyone who can read the repository and its history, including forks and clones; anyone who receives a package, Docker image or archive built from the folder; and any process running as your user, which includes malicious dependencies.
- Assumptions: a file in the project folder is one git add -A away from a commit unless an ignore rule that applies on that machine says otherwise, and a committed file stays in history after it is deleted.
- Outside this section: what the model provider retains, covered in the retention section above.
How a typed password becomes a commit
- The secret lives somewhere the agent can see: a config file, a .env, or the prompt you pasted.
- You ask the agent to check why staging login fails. The command it proposes carries the password inline, because the command cannot work without it.
- The approval prompt offers "Yes, and don't ask again" for a prefix of that command. If the command starts with an environment assignment, the password is part of the prefix.
- Claude Code writes the prefix as an allow rule to .claude/settings.local.json at the root of the repository, and the full command and its output go into the session transcript.
- The settings file reaches git whenever no ignore rule covers it on that machine. Once committed, it lives in every clone and fork, and in history after the file is deleted.
Claude Code's settings documentation describes the protection, as of November 2026: Claude Code adds the file to your global git excludes the first time it writes it, so it stays out of your commits, and "if you create it by hand, add it to .gitignore yourself." The global exclude lives in one person's git configuration on one machine, and nothing travels with the repository.
What public GitHub shows
Apiiro's research, published November 5, 2026 from read-only GitHub code and commit search run November 1 to 3, counted 104,185 public copies of .claude/settings.local.json, of which 1,122 hold a real secret by Apiiro's classification: a key in a known provider format, or a password or token on the same line as a public host, after rules that remove placeholders, local hosts and public-by-design keys, plus a reviewer pass. Counting the file's history, the shared settings.json teams commit on purpose, committed agent transcripts, memory files and handoff notes, Apiiro reports 2,539 distinct real secrets in 1,994 repositories. Earlier versions of the file alone hold 734 secrets that appear in no current copy, usually because the file was deleted. Apiiro ran gitleaks and TruffleHog over all the files: of the 1,122 with a real secret, gitleaks flagged 564, TruffleHog 643, and 215 were flagged by neither, mostly passwords inside ordinary commands.
Two limits matter when you quote these numbers. Apiiro states that no credential was used or tested and no host was contacted, so "real secret" means a value that matches a provider format or points at a public host; validity was never checked. And Apiiro's history search covered 43,120 repositories, so the history count is a floor. On the Hacker News discussion of the research, Anthropic's head of Claude Code, Boris Cherny, said the team is looking into prevention, including "making sure auto mode catches this, building in basic secret scanning," and that in his view the exposed copies were created manually and checked in, since Claude Code gitignores the file when it creates it.
What we reproduced
We ran the flow ourselves on November 8, 2026 with made-up credentials only and a local stub script that makes no network connection. Setup: Claude Code 2.1.319 on Linux in manual (default) permission mode, git 2.43.0, and a separate empty global git configuration for each scenario, so each one started like a fresh machine.
| Scenario | What Claude Code wrote | Ignore rule created | Result |
|---|---|---|---|
| Inside a git repository | .claude/settings.local.json with Bash(PGPASSWORD=aqcanary-pw-7Hq2Lx9Zr4 ./bin/dbcheck *) | **/.claude/settings.local.json in the user's global git ignore file ($XDG_CONFIG_HOME/git/ignore); nothing in the repository | Ignored for that user. The same checkout read under a different global git configuration listed .claude/ as untracked. |
| Folder that becomes a repository later | The same rule shape, password included, in .claude/settings.local.json | None | After git init and git add -A, the file was staged for commit. |
| Settings file created by hand | (A hand-written rule with mysql -p and a password) | None | Staged by git add -A, as the documentation warns. |
| File already tracked by git | The next approval was appended to the tracked file | None | git status showed the file modified; the session gave no warning. |
| Bearer token in a curl command | Bash(curl *): the prompt offered the broad prefix, with no token in the rule | Not needed | The rule held no secret, and the token was still in the transcript. |
Each made-up value appeared seven times in the session transcript under ~/.claude/projects/. For history, we committed a settings file holding an sshpass password, then untracked it, deleted it and added it to .gitignore. git grep found nothing at HEAD, git show HEAD~1:.claude/settings.local.json printed the password, and a fresh clone carried both commits.
What the scanners catch
We ran gitleaks 8.30.1 (gitleaks dir, default rules) and TruffleHog 3.99.8 (trufflehog filesystem with --no-verification, so nothing was sent to any provider) over 16 fixtures, each a settings.local.json holding one allow rule with a made-up value. We repeated the run six times with freshly generated values. In-command passwords were tested in two styles: a human-style password (Lakeside-Otter-2026) and a random 22-character string.
| Fixture | gitleaks 8.30.1 | TruffleHog 3.99.8 |
|---|---|---|
| AWS access key pair in an environment assignment | 5 of 6 runs | 6 of 6 |
| GitHub personal access token (ghp_) | 6 of 6 | 6 of 6 |
| Slack bot token | 6 of 6 | 6 of 6 |
| OpenAI project key | 6 of 6 (generic rule) | 6 of 6 |
| Anthropic API key | 6 of 6 | 6 of 6 |
| Stripe live secret key in curl -u sk_live_...: | 0 of 6 | 6 of 6 |
| PGPASSWORD=... psql, human-style password | 0 of 6 | 0 of 6 |
| PGPASSWORD=... psql, random password | 6 of 6 (generic rule) | 0 of 6 |
| sshpass -p ..., both styles | 0 of 6 | 0 of 6 |
| mysql -p..., both styles | 0 of 6 | 0 of 6 |
| curl -H "Authorization: Bearer ...", both styles | 0 of 6 | 0 of 6 |
| postgresql://user:password@host URL, both styles | 0 of 6 | 6 of 6 (Postgres detector) |
Seven of the ten in-command fixtures were missed by both tools in every run, which matches the gap Apiiro describes. The Stripe miss is specific to the trailing colon in Stripe's documented curl form: gitleaks flagged the same key once the colon was removed. Both tools' git modes also missed the deleted sshpass password in the history test above. These results come from 16 synthetic fixtures and show which command shapes the default rules cover; use them as a coverage check for your own scanner configuration.
Response checklist
- Find current copies. List every approval file on the machine, including folders that are not repositories, and check which ones git tracks:
Also search your GitHub organization for .claude/settings.local.json and .claude/settings.json, and open the allow list of every copy you find.# Approval files anywhere under your home folder find ~ -path '*/node_modules' -prune -o -path '*/.claude/settings*.json' -print 2>/dev/null # In each repository: agent files git is tracking git ls-files -- ':(glob)**/.claude/settings*.json' ':(glob)**/CLAUDE*.md' - Find historical copies. A deleted file is still in history, and in every fork and clone made before the deletion:
git log --all --format='%h %ad %s' --date=short -- \ ':(glob)**/.claude/settings*.json' ':(glob)**/CLAUDE*.md' \ ':(glob)**/MEMORY.md' ':(glob)**/.specstory/**' - Rotate every exposed credential, first. Rotation is what makes the existing copies worthless. Deleting the file, rewriting history or making the repository private leaves every clone, fork, cache and transcript holding a working credential. Start with credentials that sit next to a public host.
- Remove secret-bearing rules. Delete every allow entry that contains a literal password, token or key, in local and shared settings files, and approve again with a reference instead: PGPASSWORD="$PGPASSWORD" psql -h ... records a variable name. Delete the transcript files that hold the value, or lower cleanupPeriodDays so they age out sooner.
- Add repo-local ignore protection. The global exclude does not cover a folder that becomes a repository later, a settings file created by hand, another person's machine or a CI runner, or a file that is already tracked. Put the rule in the repository itself, and untrack anything already committed:
Add the same lines to your organization's .gitignore templates.printf '%s\n' '.claude/settings.local.json' 'CLAUDE.local.md' >> .gitignore git rm --cached --ignore-unmatch .claude/settings.local.json CLAUDE.local.md - Scan commands as well as key formats. Run a scanner in pre-commit and CI, over history as well as the working tree, with rules for PGPASSWORD=, sshpass -p, mysql -p, bearer headers and URL passwords. Treat agent folders (.claude/, .cursor/, .gemini/, .specstory/) and memory files like .env files, on laptops as well as in repositories.
A command-aware scanner rule
This gitleaks configuration keeps the default rules and adds five for the command shapes in the table. On our fixtures it matched all ten in-command cases in all six runs and found the deleted sshpass password in history, with no match on placeholder forms such as PGPASSWORD=$DB_PASSWORD, sshpass -p "$SSH_PW", Bearer $TOKEN, psql "$DATABASE_URL" and mysql -p with a prompt. Expect it to flag development passwords too; in agent artifacts, that is the behavior you want.
# gitleaks-agent-commands.toml
[extend]
useDefault = true
[[rules]]
id = "cmd-pgpassword"
description = "Password in a PGPASSWORD assignment"
regex = '''PGPASSWORD=(?:'[^'$][^']*'|"[^"$][^"]*"|[^\s'"$][^\s'"]*)'''
[[rules]]
id = "cmd-sshpass"
description = "Password passed to sshpass -p"
regex = '''sshpass\s+-p\s*(?:'[^'$][^']*'|"[^"$][^"]*"|[^\s'"$][^\s'"]*)'''
[[rules]]
id = "cmd-mysql-p"
description = "Password attached to mysql -p"
regex = '''\bmysql(?:dump)?\b[^\n]*?\s-p[^\s'"$][^\s'"]*'''
[[rules]]
id = "cmd-bearer-header"
description = "Literal bearer token in an Authorization header"
regex = '''(?i)authorization:\s*bearer\s+[^\s'"$\\][^\s'"\\]{7,}'''
[[rules]]
id = "cmd-url-password"
description = "Password inside a connection URL"
regex = '''[a-z][a-z0-9+.-]*://[^\s/:@]+:[^\s/@$][^\s/@]*@'''
gitleaks dir . -c gitleaks-agent-commands.toml # working tree
gitleaks git . -c gitleaks-agent-commands.toml # full history
gitleaks dir ~/.claude -c gitleaks-agent-commands.toml # transcripts, memory, user settings
Scanning ~/.claude (or the folder CLAUDE_CONFIG_DIR points to) also reports Claude Code's own login credentials; that hit is expected.
Fewer approvals, fewer records
The root cause is volume. In the Hacker News thread on Apiiro's research, one engineer, rbehrends, put it plainly: "After ten or more of these, you're going to get hit by permission fatigue." Boris Cherny's answer in the same thread was "Permission rules are old hat. Everyone should be using auto mode instead," where a classifier reviews actions in place of a person. When a reader pointed out that auto mode can still ask about a sensitive command and offer the same save option, he replied "good catch." Anthropic's open-source sandbox-runtime (the srt command, a research preview) limits what a command can write and which network hosts it can reach, using bubblewrap on Linux and Seatbelt on macOS; it bounds the damage a command can do, and a password typed into that command still lands in the rule and the transcript. Another commenter, agentdev001, suggested that the harness "bundle its own secret manager," so secret requests travel outside the conversation. Whatever tool you pick, the durable fix is the same: the command should name a secret, and the value should arrive through the environment.
| Egress path | What travels | Primary control |
|---|---|---|
| Files the agent reads | Full file contents into the prompt | No real secrets on disk; deny rules as backup |
| Commands the agent runs | stdout and stderr into the prompt | Scoped credentials, sandbox datasets |
| Provider retention | Session copies for days to years | Work accounts under commercial terms |
| Local transcripts | Plaintext session logs on disk | Cleanup settings, disk encryption, rotation |
| Standing approvals | The approved command text, secret included, in a settings file | Secrets referenced as variables, repo-local ignore rules, command-aware scanning |
| Agent memory and handoff notes | Whatever the agent wrote down, in project files | Review before commit, command-aware scanning |
| Agent commits | Secrets written into git history | Pre-commit scanning and push protection |
Where AQ fits
AQ is the multiplayer coding harness where teams build and run bots with every AI coding agent, like Claude Code and Codex: shared live terminals, review and merge, app previews, and standing jobs, in your own cloud. AQ handles two parts of this problem: how a secret reaches the agent, and where the agent's environment lives. A CLI still sends its prompts to its model provider and writes its own settings files as it always has, and you should not believe any harness that claims to change that.
Secrets in AQ are stored encrypted and handed to agents, terminals and previews as environment variables: organization secrets that admins manage and personal secrets that any member saves, optionally limited to one repository. When an agent needs a secret that is missing, it asks with a secure card in the thread (Save and continue, or Skip), and the value reaches the turn that asked without being typed into the conversation. If you paste something that looks like a key into the composer, AQ offers to save it as a secret instead of sending it. Every saved value is replaced with [secret: NAME] in transcripts, run output, commit messages and pull request titles. Against the chain above, that means the agent can write PGPASSWORD="$DB_PASSWORD" and the command, any approval rule and the transcript record a variable name. The secrets docs cover the details.
The limits are just as specific. AQ does not find or rotate credentials already sitting in Claude settings files, transcripts or git history, and it does not replace a secret scanner: run the checklist and the scanner rules above on every repository and machine. Agents run on your team's machine in your own cloud or on a dedicated AQ-managed machine, each work item in its own git worktree, and everyone signs into the CLIs with their own Claude or OpenAI account, so the data terms that apply are the ones your organization already chose with those vendors (your own keys and accounts stay yours). Sessions stream live to the browser, so what an agent read and ran is reviewable by the team. For the broader custody picture, the security and isolation docs and the guide to running agents safely on your own repos cover the details.
Frequently asked questions
Does Claude Code's "Yes, and don't ask again" save my password in a file?
It saves the approved command prefix as an allow rule in .claude/settings.local.json at the root of the repository. In our tests with Claude Code 2.1.319 in November 2026, a command that started with PGPASSWORD=... produced a rule containing the password. Claude Code adds that file to your global git excludes when it creates it inside a repository, so on that machine it stays out of commits by default. A folder that becomes a repository later, a file created by hand, another machine, or a file already tracked by git is not covered, so add the file to the repository's own .gitignore and reference secrets as environment variables in commands.
Do gitleaks and TruffleHog catch passwords inside agent commands?
Mostly not with default rules. Apiiro reports that of 1,122 public Claude Code settings files holding a real secret by its classification, 215 were flagged by neither tool, mostly passwords inside commands. In our November 2026 test with gitleaks 8.30.1 and TruffleHog 3.99.8, both caught provider-shaped keys reliably, while passwords after sshpass -p, mysql -p and in curl bearer headers went undetected by both. Adding command-aware rules, like the gitleaks configuration in this guide, closes that gap for the shapes you know about.
Does Claude Code send my .env file to the model provider?
If the agent reads it, yes: any file contents that enter the context window are sent as part of the prompt. As of August 2026, Claude Code supports deny rules (for example Read(./.env) in settings.json) that block its file tools from matched paths, and hooks that can redact content before it is read. Treat those as a safety net; the stronger fix is keeping real values out of the files a development checkout holds.
Is code sent by coding agents used to train models?
It depends on the account, not the tool, as of August 2026. Anthropic lets consumer accounts choose whether Claude Code sessions can be used for training, while commercial accounts are not trained on by default. OpenAI's published policy is similar: consumer content may be used for training unless you opt out, while business and API traffic is not trained on by default. The practical rule is to run work agents under work accounts.
Are deny rules and ignore files enough to protect secrets?
No. Deny rules gate specific tool calls against specific path patterns, but an agent can encounter the same content through other routes: a shell command that prints a file, command output that echoes an environment variable, or a log line that contains a token. Use deny rules as one layer, and put the real boundary earlier by never placing production secrets on the disk the agent works from.
Can I let a coding agent debug with production data?
Assume anything the agent queries or reads becomes model input under your provider's retention terms. The safer pattern is a sandbox dataset: a seeded or synthetic database with the production schema but harmless rows, so queries and fixes are real while the data is not. If a session genuinely requires production access, scope the credentials tightly, redact what you paste, and rotate anything sensitive that entered the transcript.
How do I find out what an agent actually read during a session?
The session transcript is the record: it shows every file read, every command run, and the output that came back. Claude Code stores transcripts locally under ~/.claude/projects/ (plaintext, 30 days by default as of August 2026), and a shared harness can make the same sessions reviewable by the whole team. Reviewing the session rather than only the diff is how you catch an agent touching files it should not have.