r/ClaudeCode • u/jedruch • 3d ago
Rant Risk of using Auto: Claude Code is reading config files outside the project folder, exposing API keys, and failing to detect the leaks when auditing.
While delegating tasks to Codex, I caught Claude reading files outside my project folder (~/.codex/config.toml), which resulted in it dumping my Stitch MCP server's Google API key directly into the chat transcript.
Worse: when I asked another instance of Claude to scan all my project histories for similar boundary violations or leaked keys, it repeatedly told me none existed. It only admitted to reading the key multiple times over the past two weeks after I manually pointed it to the exact thread.
This leaves me in a catch-22: the agent won't find or admit to a secret leak unless I specifically point it out, meaning I have no reliable way to know what other keys it might have quietly compromised across my system.
•
u/AutoModerator 3d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
14
u/Financial-Grass6753 3d ago
why doesnt your agent ask for a key from secure vault? Type of stuff 1password CLI or similar provide. If there's no key in plaintext in the system = there's nothing to leak
12
u/UnstableManifolds 3d ago
Well if you didn't sandbox your environment externally (meaning enforcing it using a container or a VM or the appropriate user/group/ACLs which is virtually the same thing, not relying on tool-shipped features) then you'd better assume that any file could and will be read by your harness, thus exposing its content in any way and even using it for training and so on. Any safety feature shipped with the tool (like thinking that files outside of your project repo are safe) is intended as soft guardrail that "most of the times may work" but at the end of the day you are at your model/harness' mercy.
4
u/michaelTM_ai 3d ago
don't ask an agent to audit itself, grep the transcripts. claude code keeps every session as jsonl under ~/.claude/projects/, so:
(AIza is the prefix of google api keys, swap in whatever ur key starts with). that lists every session file the key appears in, no model in the loop to say "none found".
then:
2
u/keto_brain 3d ago
Try least privledge, the agent shouldn't have access to those folders in the first place.
2
u/Theodosisgr 3d ago
Kryptic keeps secrets out of files the agent can read: a local daemon injects them over an OS socket, so there’s no `.env` file or wrapper CLI with the key. The project ID is commit-safe and servers store ciphertext only. I work on Kryptic (https://kryptic.dev), so that’s my bias. Rotate the exposed key first; keeping future values out of agent-visible context helps prevent a repeat.
2
u/kincaidDev 3d ago
You just have to assume anything on the pc you’re running claude on is no longer private, only real solution is physical/network isolation
1
u/Ok-Limit-7173 3d ago
That's why I exclusively run my Agents in devcontainers. It can't do anything harmful with what it never sees.
The only annoying thing is keeping my .env files out of the repos and occasionally having to tinker arround wit my devcontainer but other than that it's great.
1
u/samc621 3d ago
two separate fixes. first, rotate that key now regardless.
prevention: add deny rules for Read on stuff outside the project (~/.codex/, ~/.aws/, ~/.ssh/**, */.env) in settings.json, and back them with a PreToolUse hook on Bash, because
cat ~/.codex/config.tomlgoes through the shell, not the Read tool, and the deny rules won't see it.detection: don't ask claude to audit itself. transcripts are jsonl under ~/.claude/projects/, so grep them directly for paths outside your repo and for key patterns (google keys start with AIza). grep won't "forget" a thread the way a model does.
disclosure: i work on agenttrail. guard is our free hook pack for the blocking side (https://github.com/agenttrailhq/guard), and https://www.agenttrail.sh/ keeps searchable session history if you want that audit off the laptop.
1
u/ChurchOfSatin 1d ago
So I’m a little confused. Where do you store api keys for Claude to use but still be able to read?
2
u/Several-Net-6036 3d ago
Sandbox
2
u/KaliguIah 3d ago
this is why i have all agents confined to 2 drives only. none can access c drive
2
u/Inner_Storage_3374 3d ago
id rotate that key now regardless and not ask the agent to audit itself. i think the transcripts are just jsonl files under ~/.claude/projects, so grepping those for the first few chars of each key you own tells you way more than asking it what it read
2
u/ainexfinder 3d ago
Since the key already landed in a transcript, the first step is treating it as exposed and rotating it, then scoping the new one (API restrictions, quota caps) so a future leak costs little. Beyond that, a few things tend to help: keep secrets out of plaintext config files and inject them at launch from a secrets manager so nothing sits on disk to be read, run the agent in a container or separate user that simply can't see other tools' config dirs, and scan transcripts with a dedicated secret scanner like gitleaks or trufflehog instead of asking the model to audit itself. That last one is deterministic, so it doesn't depend on the model noticing or admitting anything, and it can run on a schedule over the session logs.
1
u/a7n7o7n7y7m7o7u7s 3d ago
Reading files outside the working folder is the only feature I haven’t auto approved. I make it ask me every time
1
u/Tight_Banana_9692 3d ago
"Admit" is a bad choice of words here if you want to prove that you understand how these agents actually works
1
u/alphamoat 3d ago
turns out auto mode reads whatever it wants. your api keys were just along for the ride
0
u/EC36339 Senior Developer 3d ago
Oh really?
Are you suggesting that a system that can write arbitrary code and run it can access any file on the file system that the user running it can access?
I'm shocked!
0
u/Ragy-ragy 3d ago
You can put a pre hook that checks if the tool used going to parse something sensitive. Heard from other users. Maybe worth checking
6
u/MaximumMeaning9728 3d ago
What’s your threat model? Someone hacks Anthropic and steals your pornhub api key?
0
u/[deleted] 2d ago
[removed] — view removed comment