Stop AI agents reading .env files and SSH keys
Telling an AI agent not to read your .env file works until it doesn't: a long session, a confusing error, or a web page that tells it to. A hook turns the request into a refusal. LLLanyard can add one to Claude Code, and an audit command shows what an agent could still reach.
Turn on the Claude Code hook
lllanyard setup claude-code --hooks
This adds a check to Claude Code's settings (your other settings and hooks are kept). Before every file read, edit, search or shell command, Claude Code asks LLLanyard whether the call touches a secret. If it names a .env file, an SSH private key or a credential file such as ~/.aws/credentials, the call is refused and Claude is told to use lllanyard exec or lllanyard ssh instead.
.env.example,.env.sampleand.env.templateare allowed, and so are public keys,known_hostsand~/.ssh/config.- Commands that start with
lllanyardare always allowed. - It takes about a tenth of a second, never uses the network, and lets through anything it can't make sense of, so it won't get in the way of your work.
lllanyard setup claude-code --removeremoves it.
Its limits
The hook looks at the paths a call names. A command that builds a path while it runs gets past it, so it stops a careless or tricked agent, not a determined attacker. For a hard boundary, run the tool under lllanyard tool add --sandbox.
See what's left with lllanyard audit
$ lllanyard audit
HIGH 2 plaintext keys in files an AI agent can read
openai sk-proj…FfC1 ~/.zshrc:1
fix: lllanyard scan --import --apply --redact
HIGH SSH private key on disk with no passphrase: ~/.ssh/id_ed25519
fix: lllanyard ssh add <name> --host user@host --key-file ~/.ssh/id_ed25519
MEDIUM OpenAI Codex is installed but not set up to use LLLanyard
fix: lllanyard setup codex
It looks for plaintext keys in .env files, shell profiles and MCP configs, SSH private keys in ~/.ssh, keys overdue for rotation, SSH logins that have expired, and AI tools that are installed but not connected. It prints where things are with masked values, never a secret. The exit code is 1 if anything needs fixing, so you can run it in a script; --json gives the same as data.
Recommended order
- Run
lllanyard audit. - Move the plaintext keys into the keychain with
lllanyard scan --import --apply --redact. - Add your SSH keys with
lllanyard ssh add, check they work, and delete the files. - Connect your tools with
lllanyard setup, and turn on the hook for Claude Code. - Run the audit again.
Try it: LLLanyard is free for up to 10 keys.
npm install -g @lllanyard/cli lllanyard doctor
More guides
- Keep API keys out of Claude Code
- .env files and AI coding agents
- Keep MCP server secrets out of config files
- Connect your own devices with LLLanyard Pro
- Share LLLanyard across your devices or with your team
- Run scripts with API keys from Claude Desktop
- Let AI agents use SSH without seeing your keys
- Keep keys out of Codex, Copilot, Gemini, Windsurf and Cursor