Asking Claude Code not to read .env does not equal security — a "Swiss cheese" design for protecting secrets with permission rules, hooks, and a sandbox
请求Claude Code不要读取.env并不等于安全——用权限规则、钩子与沙箱保护秘密信息的“瑞士奶酪”设计
A developer presents a five-layer configuration scheme for protecting secrets such as .env in Claude Code, and verifies the interception effect with 15 manually constructed hook inputs. The five layers are: not storing plaintext secrets locally (using 1Password CLI's op run to write only references), permissions.deny permission rules, PreToolUse hooks, a sandbox, and a quota and key rotation process prepared on the assumption of a leak. The author says the hooks can block cat .env and printenv, but rewriting the command syntax (such as concatenating with quotes in the shell) can bypass the regex, and the sandbox only encloses Bash commands and their child processes, not the Read tool, MCP servers, or the hooks themselves. The article also mentions that on October 17, OpenCode disclosed that its old Console system had been illegally accessed and user API keys may have leaked, and that on October 15, Symantec disclosed an analysis of the Aoki infostealer malware targeting AI coding tool credentials.
The author breaks down the five complementary configuration layers one by one, with measured interception results and the residual gaps of each layer, so you can check your own Claude Code project's secret exposure surface against them.