Your AI saw your database password
Updated
AI coding agents such as Claude Code and Codex keep a record of every session on your machine: what you pasted, the files they read, and what came back from the commands they ran. If an agent read your .env or ran psql with your connection string, your database password went to the AI provider. So did any rows that came back.
Check your own history
ai-leak-scan is a free, open-source command that reads those session files and counts what reached the AI: database passwords, API keys, personal data from query results, and database writes the AI ran.
npx ai-leak-scan
It runs on your machine, makes no network requests, and never prints a secret or a personal value: passwords show as •••• and personal data only as counts. If you run it inside an AI agent, the agent sees that masked summary.
1. Clean up now
None of this needs SayQL.
- Change every database password it lists, starting with the ones marked as on a remote host. Run
npx ai-leak-scan --detailsto see which hosts and projects. Keep that output private. - Revoke the API keys and tokens it lists, and make new ones.
- Personal data can't be taken back. What came back from a query was sent to the AI provider. Check their data retention terms, and tell whoever is responsible for that data if your rules require it.
- Look at the writes it lists. Make sure each change the AI made was one you wanted.
2. Stop the next leak
The leak happens because the agent gets a password and runs a database client itself. Whatever you use, give the agent a read-only login and keep connection strings out of files it can read. Or put a tool between the agent and the database. With SayQL:
- Connect your database in SayQL. You type the password in SayQL and it's kept in your system keychain. It isn't in your project, and the AI never gets it. See Databases.
- Point your agent at SayQL. Claude Code, Cursor, Codex and other AI apps use SayQL's MCP server instead of
psql. See AI apps (MCP). - Choose what the AI may see of results: nothing, counts and summaries (the default), masked rows, or all rows. Mark columns such as
customers.tax_idas never send to AI and any query that could read them is refused. See Keep personal data out of AI prompts. - Changes come to you. SayQL's MCP server runs queries read-only. When the agent wants to change data, it opens the SQL in SayQL for you to review and run.
3. Check it worked
Run the scan again in a week with npx ai-leak-scan --since and the date you switched. New sessions should show no database passwords and no personal data.
Questions
Does ai-leak-scan send my data anywhere?
No. It reads the session files on your machine and makes no network requests. It keeps only short hashes of values in memory to count distinct ones, and prints masked labels and counts. Its source is a few hundred lines of plain JavaScript with no dependencies.
Which AI agents does it check?
Claude Code (~/.claude/projects) and the Codex CLI (~/.codex/sessions). Cursor and Gemini CLI are planned.
Can it miss things?
Yes. It looks for known patterns: database URLs and password variables, common key formats, and personal data in the output of database commands and database tools. A clean result means none of those patterns were found, not that nothing leaked.
Is a password on localhost a problem?
Less so. A local Docker or test database usually holds no real data. Change passwords on remote hosts first.
More: Safe production queries, Claude Code and PostgreSQL, and Privacy and data.
Something missing or unclear? Ask in Discussions.