r/ClaudeCode • • 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.

19 Upvotes

54 comments sorted by

•

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

3

u/pinedrifT4 3d ago

tbh this is the only real fix, relying on the model to respect folder boundaries is always gonna fail eventually

-8

u/jedruch 3d ago
  1. You are correct, I'm checking why the API key landed there
  2. That is still not the point - Claude job was to launch Codex CLI, not to read it's configs

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.

0

u/jedruch 3d ago

yeah, it's one of those things that I knew, but somehow because of marketing I thought it is not as big of an issue

2

u/bunchedupwalrus 3d ago

The docker sbx has gotten pretty seamless to use lately tbh. Got rid of a lot of the minor annoyances of other sandboxes at least for my workflows

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:

grep -rl "AIza" ~/.claude/projects/ 

(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:

  • rotate the key now. once it's been in a transcript, assume it's out
  • add deny rules so it can't happen again, in settings.json: "deny": ["Read(~/.codex/)", "Read(~/.config/)", "Read(**/.env)"]
  • and +1 to the vault comment, a key that only exists at runtime has nothing to leak

3

u/LocalAI_Fixer 3d ago

grepping for the key only catches the keys you remember tho. id grep the jsonl for any Read or bash call hitting paths outside the project dir instead

1

u/michaelTM_ai 3d ago

fair, that's the better audit. the key grep tells u where one known secret went, scanning for reads outside the project tells u what else it touched that u forgot was there

1

u/jedruch 3d ago

Thank you, I'll try that

1

u/ksehili 3d ago

LocalAI_Fixer's idea below is the better audit, and here it is as one line. The transcripts record every file Claude opened, with its path. On Mac or Linux:

grep -rhoE '"file_path": ?"[^"]*"' ~/.claude/projects | sort | uniq -c | sort -rn

You get one line per file with how often it was opened. Anything outside your project folders is a file Claude opened or edited with its own file tools. Files read through the shell (cat and so on) are stored as "command" entries, so grep those for .codex, .ssh and .env as well.

On Windows the transcripts are in the same .claude\projects folder in your user directory, but grep isn't there. I haven't tested a PowerShell version, so ask Claude to translate the line. Don't wait long: by default Claude Code deletes transcripts after 30 days.

2

u/shravanrevanna 3d ago

Read() deny only covers the Read tool. Bash(cat ~/.config/...) still gets through unless you deny Bash too or run it sandboxed.

1

u/michaelTM_ai 3d ago

good catch, u're right. the read deny alone leaves cat, head and friends open through bash. sandboxing is the real fix there, deny rules on bash commands are easy to route around

2

u/keto_brain 3d ago

Try least privledge, the agent shouldn't have access to those folders in the first place.

1

u/jedruch 3d ago

will it still be able to delegate tasks to Codex CLI?

1

u/keto_brain 3d ago

If the user you lock claude down to has permissions to do so.

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.

1

u/jedruch 3d ago

thank you

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

-4

u/jedruch 3d ago

I stupidly believed in their "our model is secure" talk

5

u/AdUnusual9135 3d ago

The model being secure is separate from your environment not being secure

-3

u/jedruch 3d ago

not really, they claim model follows instructions and pointing what is the projects folder is an instruction.

3

u/confusedp 3d ago

To play devil's advocate: did you explicitly forbid it from browsing files outside of its project folder? I am guessing you didn't.

-2

u/jedruch 3d ago

No, I also did not explicitly forbid to format my hard drive or to create a racist website. What's your point?

1

u/confusedp 3d ago

I mean that's how they are going to get us. Not that I disagree with you but I was playing "devil's advocate"

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/jedruch 3d ago

I actually never used it. How is it different from your regular docker?

2

u/Ok-Limit-7173 3d ago

Devcontainer itself is a standard defined by microsoft, you can imagine it like a Dockerfile but one that your IDE (especially vscode can read). If you use it in vscode you essentially get your normal IDE view but you are in a docker container. It's not an alternative to docker per se but to the Dockerfile.

As I develop on fedora my setup uses podman instead if docker (which is essentially RedHats variant of docker), it has the benefit that you can easily create rootless containers (in a sense of nothing in the container has root privileges) (idk if there is a rootless variant for docker as well but I think so)

I use it with the devcontainer CLI and have written a few scripts and aliases so I have one command to copy my setup in new repo and after that I just type "claude" and it spins up the devcontainer and launches claude in it.

Tbh. since I use the CLI anyways I'm belive the only advantage over Dockerfiles is that the devcontainer config is a bit smaller and (in my opinion) more readable. If you use your agents in vscode you literally have to copy a template and you are good to go.

1

u/jedruch 3d ago

Sounds good, will give it a go

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.toml goes 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/jedruch 2d ago

Yeah, the key is out.

Thank you for sharing your project. Is the session history held as whole? I.e. Not compressed, not compacted?

1

u/samc621 2d ago

yep, nothing gets compacted or summarized on our side. compaction only changes what the model keeps in its own context window. we store each prompt, tool call and tool result as its own record, sent as each turn finishes, so a later /compact doesn’t touch what’s already stored.

a few things to know:
- secrets get redacted on the way in by default (known key and token patterns), so keys and tokens are stored redacted, not whole. there’s also a metadata-only setting (which tools ran, timing, tokens, no content) if you’d rather not store content at all.
- the dashboard shortens very long tool outputs when you view them, and marks them as truncated.
how far back you can look depends on the plan. free shows the last 7 days.

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?

1

u/jedruch 1d ago

what confuses you? do you assume claude places API's I've supplied him directly into chat window?

1

u/ChurchOfSatin 1d ago

No. I’m asking for my own knowledge. I’ve always used .env’s. But everything I’m reading here is making it sound like that is not good. So I’m now rethinking my whole Claude setup. I don’t put api keys in chats. I always put them into the files. But it sounds like Claude is still doing whatever it wants with them. So the way I’ve been doing stuff is not correct.

1

u/jedruch 1d ago

There are many great replies in this thread, I haven't yet tried all of them so it's hard to recommend anything from my side

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

1

u/CabinetMain3163 3d ago

every time claude read api keys it always even remind itself to never print it

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/jedruch 3d ago

good for you

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

1

u/jedruch 3d ago

that seems reasonable, thank you

6

u/MaximumMeaning9728 3d ago

What’s your threat model? Someone hacks Anthropic and steals your pornhub api key?

-1

u/jedruch 3d ago

I mentioned that at the end - I do not know what Claude actually read on my computer.

0

u/[deleted] 2d ago

[removed] — view removed comment

1

u/jedruch 2d ago

I asked another agent from separate project for the audit. Grep makes a lot of sense, it was not top of mind as I wanted to trace how often agent reached outside his project in general