Local Development Without .env Files
Migrate local development workflows from plaintext .env files to in-memory Ray Secrets with multi-environment switching and zero git leak risks.
Plaintext .env files are the leading cause of credential exposure on developer workstations. Files are frequently staged into git by mistake, secrets drift out of sync across teammates, and onboarding new engineers requires sharing sensitive credentials over insecure chat channels.
This guide walks you through completely replacing local .env files with Ray Secrets.
1. Import Existing .env Secrets
If your application already uses a .env or .env.local file, you can import all variables into your Ray Secrets vault in a single command:
ray push --file .env| Flag / Option | Type | Description |
|---|---|---|
-f, --file <path> | string | Path to the source or destination .env file (defaults to .env in current directory) |
The CLI parses the key-value pairs, encrypts them client-side, and stores them in your remote environment vault.
If you have developer-specific overrides in a .env.local file that should not overwrite team defaults, push them as personal overrides using the --override flag:
ray push --file .env.local --override| Flag / Option | Type | Description |
|---|---|---|
-f, --file <path> | string | Path to the source or destination .env file (defaults to .env in current directory) |
-o, --override | boolean | Save or update secrets as personal developer overrides without modifying shared team values |
Verify that the secrets are populated in the remote vault:
ray pull --format json| Flag / Option | Type | Description |
|---|---|---|
--format <type> | string | File serialization format for exported secrets (env, json, yaml, csv, shell, docker) |
2. Secure Your Repository Against Leakage
Once secrets are safely stored in Ray Secrets, remove physical .env files from your filesystem and update your .gitignore:
rm -f .env .env.local .env.development && echo ".env*" >> .gitignoreIf a .env file was previously committed to git, remove it from git tracking without deleting your working directory copies:
git rm --cached .env .env.* 2>/dev/null || trueIf production credentials were ever pushed to a public git repository, updating your .gitignore is not enough. You must immediately rotate and revoke those credentials in the Developer Console or at your upstream service providers.
3. Update NPM Package Scripts
To make runtime secret injection automatic for every engineer on your team, update your package.json scripts to prefix runtime commands with ray run --:
{ "scripts": { "dev": "ray run -- next dev", "build": "ray run -- next build", "start": "ray run -- next start", "lint": "next lint", "test": "ray run -- vitest" }}Now, any engineer who runs npm run dev or pnpm dev will automatically receive the latest secrets in process memory without any plaintext .env files written to disk.
4. Multi-Environment Switching & Parity Diffing
Working across different development, staging, or testing databases is effortless with Ray Secrets. You do not need multiple .env.staging or .env.test files.
Default Environment Binding
Your active environment and project binding are configured in .ray/workspace.json (typically pointing to development). Personal overrides are isolated in .ray/local.json, which is automatically added to .gitignore.
Temporary Environment Override
To run your application against a staging or preview environment without modifying local configuration files, pass the --env (--environment <name>) flag:
ray run --env staging -- npm run dev| Flag / Option | Type | Description |
|---|---|---|
-e, --env <name>(--environment <name>) | string | Target environment name (e.g. development, staging, production) to read or modify |
Inspecting Differences Across Environments
To inspect what secrets differ between your local overrides and the remote vault:
ray diffTo compare two remote environments (e.g. development and staging):
ray diff development staging5. Synchronizing & Refreshing Local Cache
When a teammate adds, renames, or updates secrets in the Developer Console or CLI, your local metadata cache can be synchronized immediately:
ray sync6. Exit Codes Reference
Ray CLI uses deterministic exit codes to report execution status clearly:
| Code | Meaning | Recommended Action |
|---|---|---|
| 0 | Success. The command completed with no errors. | None required. |
| 1 | Runtime or execution failure. A child process returned non-zero status or a general error occurred. | Inspect process output or run with --verbose. |
| 2 | Authentication failed. Token is missing, expired, or invalid. | Run `ray login` or update `RAY_TOKEN`. |
| 3 | Configuration or binding error. Project or environment context was not found. | Run `ray init` or specify `--project` and `--env`. |
| 4 | Network or API failure. Failed to reach the Ray Secrets vault. | Check internet connection or run `ray doctor`. |
7. Troubleshooting Local Development Issues
Accidental Git History Exposure
- Problem: Plaintext
.envfiles containing credentials were added to the git index or committed to a remote repository. - Cause: The
.envfile was created before adding.env*rules to.gitignore. - Fix: Remove the file from git tracking without deleting working directory copies, commit the gitignore rule, and rotate secrets:
git rm --cached .env .env.* 2>/dev/null || trueThen rotate all exposed credentials immediately in the Developer Console.git add .gitignore && git commit -m "chore: ignore .env files"
Host Shell Variable Collisions
- Problem: Injected vault secrets are shadowed or overridden by local workstation environment variables.
- Cause: A workstation variable was previously exported in your shell profile (e.g.
export PORT=3000in~/.bashrcor~/.zshrc). By default, parent shell variables take precedence over injected vault secrets. - Fix: To ignore host environment variables and run purely with vault secrets, pass
--no-inherit:ray run --no-inherit -- npm run devAlternatively, launch inside a sanitized subshell:Flag / Option Type Description --no-inheritboolean Prevent child process from inheriting host workstation shell variables; inject vault secrets into a clean environment env -i PATH="$PATH" ray run -- npm run dev
Stale Local Metadata Cache
- Problem: Running
ray runuses stale or previous secret values after another team member updated vault secrets. - Cause: Local cached workspace metadata has not refreshed.
- Fix: Force-refresh local workspace metadata and environment cache:
ray sync
Ready to eliminate plaintext secrets?
Create a workspace to organize environments, invite your team, and generate scoped Service Tokens for CI/CD.
CI/CD with Service Tokens
Automate secret injection in GitHub Actions, GitLab CI, and Docker using scoped non-interactive Service Tokens with zero plaintext on disk.
Zero-Disk Process Memory Injection
Learn how Ray CLI decrypts vault secrets in RAM and injects environment blocks into child processes with zero plaintext written to disk.