# How to Give Claude Code Access to Secrets Safely (Without .env Files)

> Last updated: 2026-12-03 | Canonical URL: https://lisovault.com/guides/claude-code-mcp-secrets

Pasting API keys into plaintext .env files or Claude Code's chat context exposes production credentials to prompt injection, git leaks, and cloud conversation logs. With liso mcp, you configure Claude Code in one command using a scoped la1.<id>.<key> agent token restricted to specific vaults or folders, require human biometric/OS approval before secret reads, inject keys directly into child processes via run_with_secrets (with automatic stdout/stderr redaction), and hard-block your recovery phrase and master password at the cryptographic layer.

## Step-by-Step Setup

### Step 1: Install the liso CLI and unlock a session

Install the signed Apache-2.0 liso binary, sign in via QR pairing (liso login --qr) or your 12-word recovery phrase, and export a time-limited session key (12h max / 2h idle default).

```bash
# Install liso CLI (verifies SHA-256 and optional Sigstore cosign)
curl -fsSLO https://raw.githubusercontent.com/Liso-Vault/liso/main/dart/cli/install/install.sh
bash install.sh --require-cosign

# Pair with your unlocked Liso app and start a local session
liso login --qr
export LISO_SESSION="$(liso unlock --raw)"
```

### Step 2: Create a least-privilege profile for Claude Code

Scope Claude Code strictly to a non-production vault, folder, or tag—and enable --exec so Claude can run commands with injected secrets without reading raw values into context.

```bash
# Restrict Claude Code to the "Staging" folder in your "Work" vault
liso mcp profile add claude-dev \
  --vault Work \
  --folder Staging \
  --exec \
  --approval first-use \
  --ttl 12h
```

### Step 3: Write Claude Code's MCP config automatically

Run liso mcp setup to mint a cryptographically bound la1.<id>.<key> token for that profile, back up ~/.claude.json, and merge the liso MCP server entry with private 0600 file permissions.

```bash
liso mcp setup \
  --client claude-code \
  --profile claude-dev \
  --create-token \
  --write
```

### Step 4: Link desktop biometric approvals and run doctor

Optionally link the Liso desktop app over HMAC-SHA256 local IPC for Touch ID / biometric confirmations (otherwise Liso falls back to a native macOS/Linux/Windows OS dialog), then verify with liso mcp doctor.

```bash
# Route approvals to the Liso desktop app (optional; native OS dialog works out of the box)
liso mcp link-app

# Verify account, token validity, approver health, and ~/.claude.json wiring
liso mcp doctor
```

### Step 5: Use run_with_secrets and audit every call locally

Ask Claude Code to execute deploy or test commands via run_with_secrets with liso:// references so credentials never enter the LLM transcript, and inspect the hash-chained local audit log anytime.

```bash
# Tail the hash-chained local audit log (never uploaded to any server)
liso mcp audit tail

# Immediately revoke every active session key and agent token on this machine
liso lock
```

## Security Model & Threat Defenses

| Threat / Scenario | How Liso 2 Mitigates It |
| --- | --- |
| Prompt injection asks Claude for your recovery phrase | Hard-blocked in every mode (even --approval none): arguments, labels, BIP-39 checksums against your Recovery Auth key, Argon2id password slot, and encoded in-memory keys are all blocked before output. |
| Agent prints an injected API key to stdout/stderr | run_with_secrets injects liso:// secrets into argv (no shell), strips LISO_* env vars, and redacts raw, base64, URL-encoded, JSON-escaped, and hex forms of every secret from command output. |
| Compromised script tries to run liso export with the agent token | Normal CLI commands reject la1.<id>.<key> tokens with exit code 8. Editing the profile policy on disk invalidates the token's authenticated XChaCha20 kid hash. |
| Agent probes for secrets in your personal or finance vaults | Items outside the profile's --vault / --folder / --tag scope return identical not-found responses so the agent cannot enumerate restricted vaults. |

## Claude Code MCP Secrets FAQ

### Where does liso mcp setup write Claude Code's configuration?

liso mcp setup --client claude-code --create-token --write backs up ~/.claude.json, merges the liso MCP server entry with your scoped LISO_AGENT_TOKEN, and enforces private 0600 file permissions.

### Does Claude Code ever see my master password or Liso session key?

No. Claude Code only receives a scoped la1.<id>.<key> agent token bound to a single profile's vault/folder/tag rules and TTL. Your master password, recovery phrase, and full LISO_SESSION never enter Claude Code's environment.

### What happens if I don't have the Liso desktop app running during a Claude Code session?

Liso falls back automatically from desktop app IPC to a native OS confirmation dialog (osascript on macOS, zenity/kdialog on Linux, MessageBoxTimeoutW on Windows) that defaults to Deny after 60 seconds. If no interactive approver is reachable, requests fail closed.

### Can I use the same Liso MCP setup with OpenAI Codex CLI or Windsurf too?

Yes. liso mcp setup supports claude-code, claude-desktop, cursor, vscode, windsurf, and codex—you can mint separate scoped profiles and tokens for each AI coding tool.
