Skip to content

Security

Secrets and .env files: where your keys live

Where to keep API keys and passwords in a web project, why they never enter the repository or the browser, how to stop Claude Code from reading .env, and what to do if a key leaks.

Talqeen wrote this article and no editor has reviewed it yet. Search engines do not see this page until it is reviewed.

One API key in the wrong place can cost you a surprise bill or your users' data. Modern tools make the mistake easier: a model that reads your files, a framework that ships some variables to the browser, a public repository one click away. A few rules keep secrets where they belong.

1. A secret lives in an environment variable

Never in code, not even "for now":

const key = process.env.PAYMENT_API_KEY;

Locally, values go in .env.local; in hosting, in the project settings; in the repository, a .env.example with names and no values.

2. .env never enters the repository

.env
.env.*
!.env.example

What entered git history once stays there even if a later commit deletes it. A committed secret is an exposed secret.

3. What reaches the browser is public

In Next.js every variable starting with NEXT_PUBLIC_ is shipped to the browser. Never put a secret there; requests that need a key go through your server. Talqeen itself works this way: the browser never talks to the database directly, and the service key that bypasses row rules is read in one server file only.

4. Stop your tool from reading secrets

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)", "Bash(printenv:*)"]
  }
}

The Talqeen kit always writes these rules, plus key files such as *.pem. What the model does not read it cannot leak.

5. Do not paste a secret into the conversation

Copy the error message only, with the key replaced by REDACTED.

If a key leaks

Revoke it first, create a new one, check the logs for use of the old one, and close the path it leaked through. Deleting it from the repository is not enough: revoking is what protects you. Give every key the least scope its job needs.