# Claude Code read my .env and sent the API key to Anthropic. I built a local check that withholds it. — retained record

> Retained reddit record from reddit:ClaudeCode.

Canonical: https://highsignal.app/data/records/fa9854929cc6e2b2

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:ClaudeCode)  published 2026-10-12 18:43 ingested 2026-10-13 02:41

[original source ↗](https://www.reddit.com/r/ClaudeCode/comments/1x4a6kg/claude_code_read_my_env_and_sent_the_api_key_to/)

## retained text



```
And now the solution works for every tool call, not just your .envs. Think log traces, sensitive emails, not just that one file.  
  
When Claude Code reads a file or runs a command, the output goes into its next request to Anthropic. If that output has an API key or a password in it (an `.env`, a config file, a log, `printenv`), the key goes too.

`permissions.deny` on `Read(.env)` helps for files you know about. It doesn't catch a token in a log, a test fixture, or command output.

So I put a small local model in the middle. Before each request leaves, it scans the new tool output. If it spots a secret, Claude gets **"Tool output withheld"** plus a reason instead of the content, and can try another approach (for example, reading a narrower range). Nothing is sent to anyone but your local model.

**Setup (about 5 minutes, macOS/Linux):**

    # 1. local scanner model (~3.3 GB)
    llama-server -hf bartowski/Qwen2.5-3B-Instruct-GGUF:Q8_0 --alias local-pii \
      --host 127.0.0.1 --port 8081 -c 8192 -np 1 --jinja --no-context-shift
    
    # 2. the proxy + plugin
    curl -fsSL https://torana.sh/install.sh | sh
    torana start --port 8143
    torana plugin install pii
    torana open   # add the local model as a provider, bind it to the pii plugin
    
    # 3. run Claude Code through it
    ANTHROPIC_BASE_URL="$(torana endpoint anthropic)" claude

Your normal Claude login and billing stay the same.

**How well does a small model do this?** 60 files with planted (fake) secrets, 60 harmless ones:

|Scanner|Secrets caught|Harmless files blocked|
|:-|:-|:-|
|Qwen2.5 3B|60 / 60|18 / 60|
|privacy-filter|58 / 60|9 / 60|
|Regex only|24 / 60|0 / 60|

**What I learned building it:**

* **Withhold, but say why.** The plugin replaces the whole result with a short reason, so Claude can change approach (for example, read a narrower range) instead of just retrying.
* **Valid JSON isn't a correct answer.** Qwen3 0.6B answered every case in clean JSON and missed all 60 secrets. Most sub-1B models couldn't even keep the format.
* **Prompt wording matters a lot.** Two rewordings of the same prompt for Qwen2.5 3B caught 37 and 49 of 52 secrets in real code.
* **Specialised detectors are fast but jumpy.** SecretMasker takes about 11 ms, but it mistakes random hashes for keys.

**Honest limits:**

* It adds about a second per tool result.
* It has false alarms. Expect the odd harmless file to be withheld.
* It's an extra layer, not a guarantee.

Full write-up with 15 models and detectors compared, plus the step-by-step setup (disclosure: I built Torana, it's open source and free): [https://torana.sh/blog/local-models-tool-output/](https://torana.sh/blog/local-models-tool-output/?utm_source=reddit&utm_medium=social&utm_content=claudecode-pii)

How are you keeping secrets out of Claude Code's context today? Deny rules, hooks, something else?
```



document fetched 2026-10-13 00:41 · canonical https://reddit.com/r/ClaudeCode/comments/1x4a6kg/claude_code_read_my_env_and_sent_the_api_key_to
