Updated Dec 1, 20266 min read

How to Handle Secrets in Local Development

How teams get API keys and signing keys onto developer laptops, where .env files and copied values go wrong, what password manager and cloud CLIs change, and how to keep local secret values out of the repository and away from AI coding agents.

Illustration for How to Handle Secrets in Local Development

Most backends need a few secrets before they start on a laptop, such as a payment provider key or a webhook signing key. They usually arrive as a .env file sent over chat, which works until a production value changes and the copies do not, or the file lands in a commit.

This guide compares the common ways to get secrets onto developer machines and what each one leaves exposed.

How do the options for local secrets compare?

Encore secrets.env filePassword manager or Doppler CLICloud secret manager CLI
Where the value livesEncore's secrets manager, synced on encore runA file in the project folderThe tool's vault, injected at startAWS Secrets Manager or Google Secret Manager
How a new developer gets itAutomatically, for every developer on the appCopied from a teammateGranted access to the vaultGranted IAM access to the secret
Per-machine override.secrets.local.cueEdit the filePersonal configEnvironment variable
Readable from the workspaceOnly the override file, if one existsYesNounless written outNounless written out
Same name in productionYesvalues set per environment typeDepends on the deploy setupYesper configYes
Missing valueWarning locally, deploy fails in the cloudUndefined at runtimeError at startError at start

Where do .env files go wrong?

A .env file is read at startup by a loader such as dotenv or by Node.js itself with the --env-file flag, and it works because nothing else is needed. The weak points sit around it: the file has to reach each developer, usually through chat or a shared note, a .env.example drifts from the real list of names, and one git add . before .gitignore is in place commits every value. GitGuardian counted 28.65 million new secrets in public GitHub commits in 2025 and found that about 28 percent of incidents start outside repositories, in tools like Slack and Jira, as its State of Secrets Sprawl 2026 reports.

AI coding agents add another reader, since an agent that can open files in the project can open .env unless the tool is told to skip it, and a value in the context of a session can end up in a log, a test fixture or a commit. The same GitGuardian report found that commits co-authored with Claude Code leaked secrets at about twice the baseline rate.

What do password manager and cloud CLIs change?

Tools that inject values at start, such as a password manager CLI or Doppler, run the dev server as a child process with the secrets in its environment, so nothing is written to the project folder and access is granted per person. Pulling from the cloud store works the same way with the AWS CLI get-secret-value command or gcloud secrets versions access, as long as every developer has IAM access to the right secrets and a script that maps them to variable names.

Both fix the copying, and both keep the mapping from secret to variable name outside the code, in a config file or a wrapper script that has to match what the code expects. A secret the code reads but the wrapper does not inject only shows up as an undefined value at runtime.

How does Encore handle secrets locally?

Encore

Encore brings infrastructure from code, and secrets are part of it: the code declares which secrets it uses, the values are stored per environment type in Encore's secrets manager, and encore run syncs the local values to every developer on the app, as the secrets docs describe. In your own AWS or GCP account the same names are replicated to AWS Secrets Manager or Google Secret Manager and injected into the services at runtime, so the code reads a secret the same way on a laptop and in production.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create links-app --example=ts/hello-world$ cd links-app && mkdir links

A signing key for download links is a typical local secret, since the feature cannot be tested without one. The links folder needs an encore.service.ts that exports new Service("links"), and the service declares the key and uses it to sign and check links that expire after an hour:

// links/links.ts import { api, APIError } from "encore.dev/api"; import { secret } from "encore.dev/config"; import { createHmac, timingSafeEqual } from "node:crypto"; const signingKey = secret("LinkSigningKey"); function sign(path: string, exp: number): string { const key = signingKey(); if (!key) throw APIError.failedPrecondition("LinkSigningKey is not set"); return createHmac("sha256", key).update(`${path}:${exp}`).digest("hex"); } interface CreateRequest { path: string; } interface SignedLink { path: string; exp: number; sig: string; } export const create = api( { expose: true, method: "POST", path: "/links" }, async ({ path }: CreateRequest): Promise<SignedLink> => { if (!path.startsWith("/files/")) throw APIError.invalidArgument("path must start with /files/"); const exp = Math.floor(Date.now() / 1000) + 3600; return { path, exp, sig: sign(path, exp) }; }, ); interface VerifyResponse { valid: boolean; } export const verify = api( { expose: true, method: "POST", path: "/links/verify" }, async (link: SignedLink): Promise<VerifyResponse> => { if (link.exp < Date.now() / 1000) return { valid: false }; const expected = Buffer.from(sign(link.path, link.exp)); const given = Buffer.from(link.sig); return { valid: expected.length === given.length && timingSafeEqual(expected, given) }; }, );

The value is set once for local development and synced to everyone on the app, and a developer who needs a different key on their own machine adds an override file next to encore.app, which belongs in .gitignore:

~/links-app
$ encore secret set --type local LinkSigningKey$ echo '.secrets.local.cue' >> .gitignore$ echo 'LinkSigningKey: "my-own-test-key"' > .secrets.local.cue$ encore run

encore run loads the local secret value. POST /links signs the path with that key, and POST /links/verify checks the signature and returns whether it is valid. A secret with no value is left empty locally and encore run prints warning: secrets not defined: LinkSigningKey, which is why sign refuses an empty key, and a deploy to a cloud environment fails until every secret has a value for that environment, which catches a missing key before it reaches users. Production values are set separately with encore secret set --type prod.

The repository holds only the secret names, so an AI coding agent that adds a second provider key declares it in code and asks for the value to be set, and the production value is not in the repository. Local values set for development are readable on the machine that runs encore run, and a .secrets.local.cue override is a file in the workspace. When the agent runs encore run to test its change, the synced local value is used.

Best fit: Teams that want every developer to get the same local secrets without copying files, with production values kept separate and no secret values in the repository.

Frequently asked questions

What is the safest way to store secrets for local development?

Keep the values out of the repository and out of chat, give each environment its own values, and load them at runtime from a store that tracks who can read them. A gitignored .env file is the minimum, and a secrets manager that syncs local values to each developer removes the copying.

Should .env files be committed to git?

No. Commit a .env.example with the variable names and no values, and add .env to .gitignore before the first commit. A value that was committed once stays in the history, so rotate it rather than only deleting the file.

Can AI coding agents read my .env file?

Yes. An agent that can read files in the project can read a .env file in that project unless the tool is configured to ignore it. Keeping production values in a secrets manager instead of a file in the workspace means the agent works with the secret name in code, though a local override in `.secrets.local.cue` and synced local values are readable on the machine that runs encore run.

How do I set a local secret value with Encore?

Declare the secret in code, then run encore secret set --type local with the secret name, and Encore syncs the value to every developer on the app when they run encore run. A .secrets.local.cue file next to encore.app overrides the value on one machine only.

Deploy to your cloud on AWS and Google Cloud without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders