selan.ai

Guide · Claude Code for a team

How do you stop Claude Code reading .env files and secrets?

Add Read deny rules such as Read(./.env) and Read(./.env.*) to permissions.deny, then turn on the sandbox so a script cannot open the file either. Deny rules hold in every permission mode. For a team, deliver them in managed settings so nobody can remove them. A secret can still reach the model in a command's output, and a gateway that redacts each request catches what the rules miss.

Which settings stop Claude Code reading .env?

Read deny rules. Without one, Claude Code reads files inside the working directory without asking. Put the rules in .claude/settings.json and commit it:

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)"
    ]
  }
}
  • Claude's own file tools are refused. So are redirection targets and the file commands Claude Code recognises in Bash, such as cat, head, tail, sed and tee.
  • A bare file name matches at any depth. Read(.env) and Read(**/.env) are the same rule, by gitignore's rules.
  • A ! rule carves a file back out. Read(*.env) followed by Read(!sample.env) blocks every .env file but sample.env, within the same settings file.
  • Every permission mode keeps them, auto and bypassPermissions included.
  • .claudeignore does nothing. Anthropic says to move its entries into Read deny rules.

What do Read deny rules not stop?

Three ways past them, each with Claude Code's own fix:

  • A command that does not name the file, such as grep -r pattern ., or a Python or Node script that opens it. Turn on the sandbox with /sandbox or sandbox.enabled, and set allowUnsandboxedCommands to false. Your Read deny paths then apply to every sandboxed command. The sandbox runs on macOS, Linux and WSL2; on native Windows, commands run unsandboxed.
  • Secrets in the environment. Sandboxed commands inherit Claude Code's environment, secrets included. sandbox.credentials unsets named variables for sandboxed commands, and CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 strips credentials from every subprocess Claude Code starts.
  • A secret in a command's output. Rules match tool calls. An allowed command such as kubectl get secret -o yaml, or a test that prints its config, returns the secret to the model.

The sandbox covers shell commands only. Claude's Read tool follows permission rules, so a sandbox.filesystem.denyRead entry alone does not stop it.

How do you enforce the rules for every developer?

A committed .claude/settings.json covers one repository's clones. Managed settings cover every machine. User and project settings cannot override them, and a Read(!.env) elsewhere does not cancel a managed Read(./.env). Anthropic delivers managed settings three ways:

  • Server-managed, from the claude.ai admin console, on a Team or Enterprise plan.
  • An MDM policy, through macOS managed preferences or the Windows registry.
  • A managed-settings.json file at a system path.
Behind a gateway, the admin console's rules never arrive. Server-managed settings need a direct connection to api.anthropic.com and a Team or Enterprise login, a CLAUDE_CODE_OAUTH_TOKEN or a directly configured API key. A non-default ANTHROPIC_BASE_URL exported in the shell skips the fetch, and a key from an apiKeyHelper does not trigger it. Use an MDM policy or a managed-settings.json file instead.

How does Selan keep secrets from reaching the provider?

Selan is a hosted gateway that runs Claude Code, Codex and Claude Desktop on the accounts your company already pays for. With secret scanning on, it sweeps every request for credentials and replaces each one it recognises before the request goes upstream.

  • Tool results are scanned. What cat .env printed or a file contained is swept, along with every message, the system prompt, tool definitions, the commands the model asked to run, and object keys.
  • Gitleaks' rule set, kept inside Selan. 215 rules, with ten left out for false matches or public ids and four added for Selan's own tokens.
  • It redacts and forwards. The model gets a placeholder such as [REDACTED: jwt], and the session carries on. If the scanner cannot be reached, the request is refused with a 503 and nothing is sent.
  • One switch for the company. An owner turns it on under Settings → Security, and it covers Claude Code, Codex and Desktop. It ships off, and each change is logged.
  • A feed without the secret. Logs → Secrets shows who sent which kind of credential and when. A detection keeps the rule, the count and twelve hex characters of a hash, never the value.

A token that signs nothing shows whether it is on. The provider keys stay off the laptops too, as in Claude Code without API keys.

A deny rule stops the read; redaction catches what gets read anyway.

Start for free

Free for up to three seats, and the Free plan needs no card.

When are Claude Code's own rules the better answer?

  • The secret should never leave the laptop. A deny rule stops the read on the machine. With Selan, the request carrying the secret reaches Selan's proxy, where it is held in memory for the length of the request and replaced before it goes on.
  • A secret with no known shape. Redaction catches credentials that match a rule. A password that reads as ordinary text gets through.
  • Every millisecond counts. Scanning holds each request until the sweep ends, so it adds a little latency.

Use both. A redaction is not a rotation: the value was in a file, shell or log first, so treat a row in the feed as a reason to rotate that key. The AI coding policy template writes this down as a rule, and skipping permissions safely covers the modes the deny rules survive. Keeping secrets out has the rest.

The short version

How Read deny rules, the sandbox, credential scrubbing and managed and server-managed settings work is as Anthropic's pages on permissions, sandboxing, best practices, environment variables and server-managed settings (code.claude.com/docs/en/permissions, /sandboxing, /best-practices, /env-vars and /server-managed-settings) stated it on 2 December 2026. These change: check the date before relying on them. What Selan does is as its docs and control app stated it then.