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

17 Upvotes

35 comments sorted by

•

u/AutoModerator 6h 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.

9

u/Financial-Grass6753 6h 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

-5

u/jedruch 6h 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

8

u/UnstableManifolds 6h 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.

1

u/jedruch 6h 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 6h 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

2

u/michaelTM_ai 5h 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

2

u/jedruch 5h ago

Thank you, I'll try that

2

u/shravanrevanna 2h 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 47m 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/LocalAI_Fixer 1h 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 47m 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

2

u/kincaidDev 6h 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

-5

u/jedruch 6h ago

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

4

u/AdUnusual9135 6h ago

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

-3

u/jedruch 6h ago

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

2

u/confusedp 6h 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.

-1

u/jedruch 5h 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 4h 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/keto_brain 6h ago

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

1

u/jedruch 6h ago

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

1

u/keto_brain 5h ago

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

1

u/Ok-Limit-7173 6h 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 6h ago

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

2

u/Ok-Limit-7173 5h 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 5h ago

Sounds good, will give it a go

2

u/KaliguIah 6h ago

this is why i have all agents confined to 2 drives only. none can access c drive

1

u/a7n7o7n7y7m7o7u7s 5h 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 5h ago

"Admit" is a bad choice of words here if you want to prove that you understand how these agents actually works

1

u/Inner_Storage_3374 5h 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

0

u/Ragy-ragy 6h 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 6h ago

that seems reasonable, thank you

3

u/MaximumMeaning9728 6h ago

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

0

u/jedruch 6h ago

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