AI agents on the Mac
Set up Claude Code on a Mac without leaking your keys
Install Claude Code on macOS, keep your API key in the Keychain with apiKeyHelper, block .env files with deny rules, and add MCP servers without plain-text keys.
Updated 8 October 2026 3 min read
The short answer
Install Claude Code with the native installer or Homebrew, then keep secrets out of its reach: point apiKeyHelper at a script that reads your key from the Keychain, add deny rules for .env and secrets folders in .claude/settings.json, and don’t pass API keys to MCP servers with -e, which writes them into the config in plain text.
Install
# native installer
curl -fsSL https://claude.ai/install.sh | bash
# or Homebrew
brew install --cask claude-codeRun claude in a project folder and sign in. Claude Code keeps its user settings in ~/.claude/, shared project settings in .claude/settings.json, and your personal project overrides in .claude/settings.local.json, which stays out of Git.
If you use an API key, keep it in the Keychain
Instead of exporting ANTHROPIC_API_KEY in your shell profile, store the key in the Keychain and let Claude Code fetch it through apiKeyHelper, a script whose output is used as the key:
security add-generic-password -a "$USER" -s anthropic-api-key -w{
"apiKeyHelper": "security find-generic-password -a \"$USER\" -s anthropic-api-key -w"
}Deny the files it shouldn’t read
{
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Read(~/.ssh/**)"]
}
}Deny rules win over allow rules. Commit the project file so everyone on the repo gets the same protection.
Add MCP servers without plain-text keys
Servers are added with claude mcp add, scoped to you (--scope user), the project (--scope project, saved in .mcp.json) or just this checkout (local, the default):
claude mcp add my-server -- /usr/local/bin/my-mcp-serverDay to day
- Keep the default permission prompts on for commands and edits; approve each new kind of action deliberately.
- Start agents in the project folder, not your home folder, so “read everything” means the project.
- Recent versions can run shell commands in a sandbox (
/sandbox), which limits file and network access. Checkclaude --helpfor your version.
The safe way to do this
MoltenRock Connect
One local MCP server for 30 business platforms
MoltenRock Connect is one MCP server for Claude Code that holds the keys for 30 business platforms, so none go in your config.
Get MoltenRock ConnectQuestions developers ask
Where does Claude Code store its settings on macOS?
User settings in ~/.claude/settings.json, project settings in .claude/settings.json and personal project overrides in .claude/settings.local.json. Project MCP servers go in .mcp.json.
How do I stop Claude Code reading my .env file?
Add deny rules such as "Read(./.env)" to permissions.deny in .claude/settings.json.
Is it safe to give Claude Code my Stripe or Shopify key?
Not as a plain key in its config. Use a local MCP server that holds the keys and lets the agent read, and require your approval for any change.