Secretless
Credential protection for AI coding tools. Prevents API key leakage in LLM contexts.
Setup
npm install -g secretless-ainpx secretless-ai initnpx secretless-ai verifyHow It Works
Secretless intercepts credential access at the tool level. Instead of credentials appearing in LLM context (conversation history, tool calls, file reads), tools reference environment variables. Secretless manages the lifecycle:
- Scans project for credential patterns (API keys, tokens, connection strings)
- Migrates credentials to a secure backend (OS keychain, 1Password, vault)
- Replaces hardcoded values with
$ENV_VARreferences - Adds file patterns to block lists (prevents AI tools from reading .env files)
- Injects a CLAUDE.md / .cursorrules section instructing tools to use env vars
Storage Backends
| Backend | Platform | Description |
|---|---|---|
| OS Keychain | macOS, Windows, Linux | Native keychain integration (Keychain Access, Credential Manager, libsecret) |
| 1Password | All | 1Password CLI integration for team credential sharing |
| HashiCorp Vault | All | KV v2 secrets engine with cross-device/cluster sync and Vault token auth. Best for enterprise, self-hosted, and team secrets. |
| GCP Secret Manager | All | Google Cloud Secret Manager with IAM integration, automatic versioning, and native Cloud Run/GKE support. Best for GCP-native infrastructure. |
| .env file | All | Fallback with 0600 permissions (not recommended for teams) |
MCP Context Protection
When AI tools use MCP servers, credentials can leak through:
- Tool call parameters (MCP server configs with inline API keys)
- File reads (.env, config files with embedded credentials)
- Conversation history (credentials pasted into chat)
- Error messages (stack traces revealing connection strings)
Secretless blocks all these vectors by ensuring credentials never enter the LLM context window.
HashiCorp Vault Backend
The Vault backend connects to a HashiCorp Vault instance using the KV v2 secrets engine. Secrets are read and written through the Vault HTTP API with token-based authentication. This backend is suited for teams that self-host their secret infrastructure or need cross-cluster credential synchronization.
npx secretless-ai backend set vault \ --vault-addr https://vault.example.com \ --vault-token $VAULT_TOKEN \ --vault-mount secret \ --vault-path secretless
npx secretless-ai migrate --from local --to vault| Parameter | Environment Variable | Description |
|---|---|---|
| --vault-addr | VAULT_ADDR | Vault server URL (e.g., https://vault.example.com) |
| --vault-token | VAULT_TOKEN | Authentication token for Vault API access |
| --vault-mount | VAULT_MOUNT | KV v2 mount path (default: secret) |
| --vault-path | VAULT_PATH | Path prefix within the mount (default: secretless) |
| --vault-namespace | VAULT_NAMESPACE | Vault namespace for enterprise isolation (optional) |
GCP Secret Manager Backend
The GCP Secret Manager backend stores secrets in Google Cloud Secret Manager using the REST API with zero SDK dependency. Authentication uses Application Default Credentials (ADC) or a service account key file. This backend integrates natively with Cloud Run, GKE, and Cloud Functions.
# Authenticate with GCP (one-time) gcloud auth application-default login # Set as the active backend npx secretless-ai backend set gcp-sm
npx secretless-ai migrate --from local --to gcp-sm| Configuration | Environment Variable | Description |
|---|---|---|
| Project ID | gcp.projectId in config.json | GCP project containing the secrets. Auto-detected from service account key or ADC. |
| Key file | GOOGLE_APPLICATION_CREDENTIALS | Path to service account key JSON file (alternative to ADC) |
Credential Scope Discovery
Credential Scope Discovery detects when the permissions associated with a credential change after it was initially stored. This covers both scope expansion (a token gains new permissions) and scope contraction (permissions are revoked). Detecting scope drift is important because a compromised token that silently gains elevated permissions can be exploited without triggering traditional secret rotation alerts.
Supported Providers
| Provider | Detection Method | Status |
|---|---|---|
| GCP | testIamPermissions API | Available |
| HashiCorp Vault | capabilities-self endpoint | Available |
| AWS | IAM policy simulation | Planned |
Commands
| Command | Description |
|---|---|
| npx secretless-ai scope discover | Probe current permissions for all stored credentials and record the initial scope baseline. |
| npx secretless-ai scope check | Compare current permissions against the stored baseline. Reports expanded or contracted scopes. |
| npx secretless-ai scope list | Display the recorded scope baselines for all credentials. |
| npx secretless-ai scope reset | Clear stored baselines and re-discover current scopes. |
$ npx secretless-ai scope discover GCP_SERVICE_KEY 12 permissions recorded VAULT_TOKEN 5 capabilities recorded $ npx secretless-ai scope check GCP_SERVICE_KEY EXPANDED +2 permissions (storage.objects.delete, iam.roles.create) VAULT_TOKEN OK no change
Broker Integration
Scope discovery integrates with the credential broker. Adding scopeCheck: true to a broker policy rule causes the broker to verify the credential scope baseline before granting access. If the scope has expanded since the last baseline, the broker blocks the request and logs a scope drift event.
{
"rules": [
{
"credential": "GCP_SERVICE_KEY",
"allow": ["my-deploy-script"],
"scopeCheck": true
}
]
}Custom Deny Rules
Organizations can define additional deny patterns specific to their environment. These extend the built-in 49 credential patterns with company-specific env vars, config files, and CLI tools.
# Safe to commit -- contains patterns, not secrets env: - ACME_* - INTERNAL_* files: - "*.acme-credentials" - ".corp-config" bash: - "curl*internal.corp.com*" - "corp-vault*get*"
Patterns use glob syntax where * matches any characters. Each pattern generates deny rules that block AI tools from accessing matching env vars, files, or running matching commands.
| Command | Description |
|---|---|
| npx secretless-ai rules init | Create a .secretless-rules.yaml template in the current directory |
| npx secretless-ai rules list | Show active custom rules and the number of deny rules they generate |
| npx secretless-ai rules test "PATTERN" [--env|--file|--bash] | Preview generated deny rules for a pattern |
After editing the rules file, run npx secretless-ai init to apply changes to your AI tool configurations.
Secret Management
Secretless provides encrypted secret storage with multiple backend support. Secrets are stored outside the project directory and injected at runtime.
| Command | Description |
|---|---|
| npx secretless-ai secret set NAME=VALUE | Store a secret in the active backend |
| npx secretless-ai secret list | List stored secret names (values are never displayed) |
| npx secretless-ai secret get NAME | Retrieve a secret value (requires biometric on supported backends) |
| npx secretless-ai secret rm NAME | Delete a stored secret |
| npx secretless-ai run -- <command> | Run a command with all stored secrets injected as env vars |
| npx secretless-ai import <file> | Import secrets from a .env file into the active backend |
| npx secretless-ai import --detect | Auto-detect .env files in the current directory and import all |
| npx secretless-ai env | Output export statements for stored secrets (source-able in shell) |
$ npx secretless-ai secret set OPENAI_API_KEY=sk-... Stored: OPENAI_API_KEY $ npx secretless-ai run -- python app.py # app.py can read process.env.OPENAI_API_KEY at runtime
Credential Broker
The credential broker is a local daemon that mediates access to stored secrets. Instead of injecting all secrets into a process environment, the broker grants access per-request based on configurable policies. This enables rate limiting, trust-based access control, and audit logging for credential usage.
| Command | Description |
|---|---|
| npx secretless-ai broker start [--port N] [--policy-file PATH] | Start the broker daemon |
| npx secretless-ai broker stop | Stop the broker daemon |
| npx secretless-ai broker status | Show broker status, uptime, and request count |
Policy constraints include rateLimit (max requests per time window), minTrustScore (AIM integration), requireCapability (named permission check), and scopeCheck (scope drift detection). Default policy is deny-all — only explicitly allowed credentials are accessible.
The broker authenticates clients using bearer tokens. On startup, the broker generates a cryptographically random token (32 bytes via crypto.randomBytes) and writes it to ~/.secretless-ai/broker.token with mode 0600. Clients must include this token in the Authorization: Bearer header. Token comparison uses crypto.timingSafeEqual to prevent timing side-channel attacks.
Security Architecture
All cryptographic operations use Node.js built-in crypto module with no third-party dependencies.
| Function | Algorithm | Details |
|---|---|---|
| Secret encryption | AES-256-GCM | Authenticated encryption with 96-bit IV, 128-bit auth tag |
| Key derivation | scrypt | N=16384, r=8, p=1, 32-byte derived key |
| Session integrity | HMAC-SHA256 | Timing-safe verification of session state files |
| Broker auth | Bearer token | 32-byte random token, timing-safe comparison |
| Transcript redaction | Pattern matching | Regex-based credential detection with context-aware replacement |
All symmetric primitives (AES-256, HMAC-SHA256, scrypt) are not affected by quantum computing advances. Asymmetric operations (GCP JWT signing via RS256) are handled by cloud provider infrastructure and outside the scope of this tool.
Transcript Protection
AI tools store conversation transcripts locally. If a credential was accidentally pasted into a conversation, it persists in the transcript file. Secretless can scan and redact credentials from stored transcripts.
| Command | Description |
|---|---|
| npx secretless-ai clean | Scan and redact credentials in stored transcripts |
| npx secretless-ai clean --history | Scan transcript history files |
| npx secretless-ai watch start | Monitor transcript files in real-time and redact on write |
| npx secretless-ai watch stop | Stop the transcript monitor |
| npx secretless-ai watch status | Check if the monitor is running |