DEV Community

Cover image for How to let AI code with your real API keys (without leaking them)
Mason Wyatt
Mason Wyatt

Posted on

How to let AI code with your real API keys (without leaking them)

You want Claude to integrate Stripe. You want Cursor to build your OpenAI pipeline. But your API keys are in .env, and AI can read them.

GitGuardian found 39.6 million secrets leaked on GitHub in 2025. AI-assisted commits leak at 2x the baseline rate.

Phantom fixes this in one command.

The Problem

When you use AI coding tools, your .env secrets enter the LLM context window:

  • Claude Code reads .env to understand your project
  • Cursor indexes your workspace files
  • Copilot suggests code containing your keys

Those keys can leak via session logs, prompt injection, or training data.

The Solution: Phantom Tokens

$ npx phantom-secrets init
Enter fullscreen mode Exit fullscreen mode

One command:

  1. Reads your .env and detects real secrets
  2. Stores them in your OS keychain (encrypted)
  3. Rewrites .env with worthless phantom tokens
  4. Auto-configures Claude Code MCP server

Your .env now looks like:

OPENAI_API_KEY=phm_a7f3b9e2c1d4f6a8...
STRIPE_SECRET_KEY=phm_2ccb5a1e9f8d7b3c...
Enter fullscreen mode Exit fullscreen mode

These tokens are worthless. Safe to leak. Safe for AI to read.

How It Works

When your code makes an API call, Phantom's local proxy intercepts it:

  1. AI writes code using phantom tokens
  2. Code calls http://127.0.0.1:PORT/openai/v1/chat/completions
  3. Proxy replaces phm_... with your real API key
  4. Forwards the request over TLS to the real API
  5. Your code works perfectly. AI never knew.
$ phantom exec -- node app.js
# Proxy running on 127.0.0.1:54321
# Real keys injected at network layer
Enter fullscreen mode Exit fullscreen mode

Works With Every AI Tool

Phantom ships an MCP server with 9 tools. Works with Claude Code, Cursor, Windsurf, and Codex.

Claude Code:

$ claude mcp add phantom-secrets-mcp -- npx phantom-secrets-mcp
Enter fullscreen mode Exit fullscreen mode

Cursor / Windsurf / Codex:

{"phantom": {"command": "npx", "args": ["phantom-secrets-mcp"]}}
Enter fullscreen mode Exit fullscreen mode

Once configured, just tell your AI: "protect my API keys" — it handles everything.

Cloud Sync

Sync your vault across machines with end-to-end encryption:

$ phantom login        # GitHub OAuth
$ phantom cloud push   # Encrypted upload
$ phantom cloud pull   # On another machine
Enter fullscreen mode Exit fullscreen mode

The server never sees your plaintext secrets. ChaCha20-Poly1305 encryption with keys that never leave your device.

Try It

$ npx phantom-secrets init
Enter fullscreen mode Exit fullscreen mode

New since launch: cloud sync, export/import, streaming proxy support, team vaults, and MCP tools for Claude Code, Cursor, Windsurf, and Codex.

Top comments (0)