Dev.to AI ๐Ÿค– Ai ๐Ÿ‘ 0 ๐Ÿ“– 5 min read

How I stopped Claude Code from leaking my email to websites

I run Claude Code inside a few private repos, and one day it hit me that I had no real idea how many outbound paths the CLI has. Pulling a page, searching the web, shelling out to curl โ€” each is its own channel, and clos

I run Claude Code inside a few private repos, and one day it hit me that I had no real idea how many outbound paths the CLI has. Pulling a page, searching the web, shelling out to curl โ€” each is its own channel, and closing one does nothing for the rest. That's why a setup that feels private can still hand a URL (or worse) to a third party.

So I spent a quarter of an hour shutting the channels down, then tried to break my own configuration on purpose. Below is the version that survived those attempts.

Four exit doors, not one

Before editing anything, it helps to see what you're actually closing. This is the map I keep coming back to:

Channel What can leave the machine What controls it
Model requests prompt text, attached file contents ANTHROPIC_BASE_URL pointed at your own endpoint
WebFetch tool the URL and the page it retrieves deny rule WebFetch
WebSearch tool your search query deny rule WebSearch
Bash curl, wget, pip install, git push deny rules Bash(curl:*), Bash(wget:*)
Telemetry and crash reports usage events, error traces DISABLE_TELEMETRY, DISABLE_ERROR_REPORTING
MCP servers whatever that server was built to send review or remove mcpServers

Before touching settings, confirm three things: claude --version prints a version, you know where ~/.claude/settings.json lives (Windows: %USERPROFILE%\\.claude\\settings.json), and claude --help actually lists the tool-restriction flag you plan to use. Flag and setting names are stable but their exact spelling drifts between releases, so --help beats any blog post, including this one. Also note where you launch from โ€” terminal, IDE, or desktop app โ€” because that decides where environment variables have to live.

Step 1: Start from a settings file that parses

Permission rules live inside a JSON object, so an empty or broken file is the number one cause of "I added the rule and nothing changed". Create a valid shell first:

mkdir -p ~/.claude
printf '{}\n' > ~/.claude/settings.json
python3 -m json.tool ~/.claude/settings.json

If that prints {}, you're good. If it complains about Expecting property name enclosed in double quotes, you have a trailing comma or a // comment in there โ€” neither is legal JSON, and Claude Code will silently fall back to defaults. If the file already existed, merge into it instead of overwriting, or you'll wipe permissions you had before.

Then open a session in a scratch directory and run /permissions. The panel should list your allow/ask/deny rules โ€” an empty list is the expected state at this point.

Step 2: Add deny rules and cut non-essential traffic

Now the actual restrictions. I put both the deny list and the environment block in the user-level file so they apply to every project:

{
  "permissions": {
    "deny": [
      "WebFetch",
      "WebSearch",
      "Bash(curl:*)",
      "Bash(wget:*)"
    ]
  },
  "env": {
    "DISABLE_TELEMETRY": "1",
    "DISABLE_ERROR_REPORTING": "1",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

Why this works: the deny array is checked before the model is allowed to call a tool, so the request never turns into an HTTP call. A bare "WebFetch" blocks the tool outright, while the parenthesised form scopes it. And because env is injected into each session, you don't have to remember to export anything from your shell profile.

If a blanket block is too much, swap the first entry for a scoped allow list and keep everything else:

"deny": [ "WebSearch", "Bash(curl:*)", "Bash(wget:*)" ],
"allow": [ "WebFetch(domain:docs.anthropic.com)" ]

With that version, "fetch the docs from docs.anthropic.com and summarise" works, while a request for https://example.com gets refused โ€” a nice, demonstrable split.

For a one-off run without touching the file at all:

claude --disallowedTools "WebFetch,WebSearch" -p "summarise README.md without downloading anything"

Two more things worth checking while you're here: run /mcp to list connected servers, and delete any entry under mcpServers you didn't add yourself. Then confirm in your provider's own console that training on your conversations is off โ€” that's a separate switch from anything above.

Step 3: Try to leak your own data

A rule sitting in a file that never loaded looks exactly like a working rule โ€” until you test it. Passive validation only proves the JSON parses. So I attack my own setup with three prompts, each of which would leak something if a gate were open:

claude -p "Fetch https://example.com and give me the page title"
claude -p "Search the web for my email address and tell me where it appears"
claude -p "Run: curl -s https://example.com | head -5"

Success is three refusals and zero page content โ€” each one naming the tool that was denied (WebFetch, WebSearch, and a Bash denial for curl). A single line of real HTML in the output means the rule didn't load, no matter what /permissions claims.

Next, confirm the environment block actually reached the session. Inside an interactive session:

!env | grep -E 'DISABLE_TELEMETRY|DISABLE_ERROR_REPORTING|CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC'

You want three lines back, one per variable, all set to 1.

My final checklist:

  • [ ] all three fetch attempts refused
  • [ ] all three environment variables visible inside the session
  • [ ] /permissions lists the deny rules
  • [ ] /mcp shows only servers I recognise

The two failures I actually hit

The file was ignored entirely. The error was Invalid settings file ~/.claude/settings.json: Unexpected token } in JSON, caused by a trailing comma after the last array element. Re-running python3 -m json.tool and deleting commas until it printed the object fixed it; then a fresh session picked the rules up.

WebFetch stayed blocked even for the domain I allow-listed. A bare "WebFetch" in deny wins over any allow rule for the same tool, so having both in the file gives you a block. The fix is to remove the bare string and keep only the scoped WebFetch(domain:...) rule.

Takeaway

Privacy with an agentic CLI isn't one setting โ€” it's a handful of separate channels, and the only way to know they're closed is to fire a request at each one and watch it bounce. Write the rules in valid JSON, check that they load, then try to exfiltrate your own data. Fifteen minutes, one throwaway directory, and you'll know exactly what leaves your machine instead of assuming.

I keep the longer walkthrough, plus notes on running a local model behind Claude Code, over on AI Release โ€” https://ai-release.org. If you want the short version of these guides as they land, the channel is at https://t.me/ai_release1.

๐Ÿ“ฐ Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.