Skip to Content
RcmadeDocs

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 / OptionTypeDescription
-f, --file <path>stringPath 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 / OptionTypeDescription
-f, --file <path>stringPath to the source or destination .env file (defaults to .env in current directory)
-o, --overridebooleanSave 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 / OptionTypeDescription
--format <type>stringFile 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*" >> .gitignore

If 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 || true

If 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 --:

package.json
{  "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 / OptionTypeDescription
-e, --env <name>(--environment <name>)stringTarget 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 diff

To compare two remote environments (e.g. development and staging):

ray diff development staging

5. 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 sync

6. Exit Codes Reference

Ray CLI uses deterministic exit codes to report execution status clearly:

CodeMeaningRecommended Action
0Success. The command completed with no errors.None required.
1Runtime or execution failure. A child process returned non-zero status or a general error occurred.Inspect process output or run with --verbose.
2Authentication failed. Token is missing, expired, or invalid.Run `ray login` or update `RAY_TOKEN`.
3Configuration or binding error. Project or environment context was not found.Run `ray init` or specify `--project` and `--env`.
4Network 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 .env files containing credentials were added to the git index or committed to a remote repository.
  • Cause: The .env file 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 || true
    git add .gitignore && git commit -m "chore: ignore .env files"
    Then rotate all exposed credentials immediately in the Developer Console.

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=3000 in ~/.bashrc or ~/.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 dev
    Flag / OptionTypeDescription
    --no-inheritbooleanPrevent child process from inheriting host workstation shell variables; inject vault secrets into a clean environment
    Alternatively, launch inside a sanitized subshell:
    env -i PATH="$PATH" ray run -- npm run dev

Stale Local Metadata Cache

  • Problem: Running ray run uses 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.