Getting Started
What is Tokengate?
Tokengate is an end-to-end encrypted environment variable manager for development teams. It replaces insecure practices like sharing .env files over Slack, email, or password managers with a purpose-built CLI and web dashboard.
Every environment has its own encryption password. Secrets are encrypted on your machine before they ever leave it. The Tokengate server stores only ciphertext and can never read your plaintext values. This is true zero-knowledge architecture.
How It Works
Tokengate uses a layered encryption model built on Web Crypto API standards:
- Each workspace has a workspace key (AES-256) generated at creation time
- The workspace key is wrapped per-device using RSA-OAEP 2048-bit key pairs
- Revision data is encrypted with a random per-revision data key (AES-256-GCM)
- Each data key is wrapped by the workspace key using AES-KW
- Content integrity is verified with SHA-256 content hashes
The result: your secrets are encrypted client-side, transmitted as ciphertext, and stored as ciphertext. Only devices with the workspace key can decrypt them.
Quick Start
Install the CLI
Install globally with Bun or npm. The CLI requires the Bun runtime.
Sign in with your browser
Run tokengate login to authenticate via the web dashboard. A device key pair is generated locally and registered with your account.
Initialize your project
Run tokengate init in your project directory. The wizard scans for .env files, lets you select a workspace and project, and maps each file to a remote environment.
Push and pull
Use tokengate push to encrypt and upload your local files, or tokengate pull to download and decrypt the latest revision from your team.
Installation
The Tokengate CLI is distributed as an npm package. Install it globally so the tokengate command is available everywhere.
With Bun (recommended)
With npm
Bun Required
The Tokengate CLI requires the Bun runtime to be installed on your system. Bun provides the native crypto APIs and fast startup time the CLI depends on. Install Bun at bun.sh if you do not already have it.
Verify Installation
CLI Commands
Running tokengate with no arguments enters smart mode. If you are not signed in or the current directory has no project configuration, it launches the guided setup wizard. If the project is already configured, it presents an interactive menu to push, pull, view history, or check status.
Authenticates the current device by opening your browser to the Tokengate web dashboard. A unique RSA-OAEP 2048-bit key pair is generated locally for this device. The public key is registered with your account while the private key stays on your machine. The optional [label] argument sets a human-readable name for the device (defaults to your hostname).
Removes all stored credentials from the current device, including the access token, device key pair, and cached workspace keys. This does not affect your account or other devices. After logging out, run tokengate login to re-authenticate.
Initializes the current directory as a Tokengate project. The wizard scans for all .env files in the working directory, prompts you to select a workspace and project (or create new ones), then maps each discovered file to a remote environment. A .tokengate.json config file is created to store the mappings.
Displays the current sync status for all mapped .env files. Shows which files are in sync with the remote, which have local changes pending push, and which have remote updates available to pull. Status is determined by comparing SHA-256 content hashes.
Scans all mapped .env files, identifies which have changed since the last sync (via content hash comparison), and uploads the changed files. Each file is encrypted client-side with the workspace key before transmission. A new revision is created for each pushed file.
Checks the remote for each mapped environment, compares content hashes, and downloads any files where the remote has a newer revision. Files are decrypted client-side using the workspace key and written to disk, overwriting the local version.
Shows the revision history for each environment mapped in the current project. Displays the revision number, timestamp, content hash, and which user pushed each revision. Useful for auditing changes and understanding when secrets were last updated.
Lists all workspaces your account has access to, including your role in each workspace (owner or member). Useful for verifying which workspaces are available before running tokengate init.
Configuration
Tokengate uses two configuration files: a project config in your repository and a global config on your machine.
.tokengate.json (Project Config)
Created by tokengate init in the root of your project directory. This file should be committed to version control so all team members share the same project and environment mappings. It does not contain any secrets.
| Field | Description |
|---|---|
| workspaceId | The Convex document ID of the workspace this project belongs to |
| workspaceName | Human-readable workspace name for display in CLI output |
| projectId | The Convex document ID of the project |
| projectName | Human-readable project name for display in CLI output |
| mappings | Object mapping local filenames to their remote environment. Each entry contains secretSetId, environmentId, and environmentName |
Global Config
Stored at ~/.config/tokengate/config.json with file permissions 0600 (owner read/write only). This file contains your device credentials and should never be shared or committed to version control.
| Field | Description |
|---|---|
| version | Config schema version (currently 3) |
| appUrl | The Tokengate web app URL (default: https://tokengate.dev) |
| convexUrl | The Convex backend URL, obtained during login |
| deviceId | Unique identifier for this device |
| deviceLabel | Human-readable device name set during login |
| accessToken | Authentication token for API requests |
| privateKey | RSA-OAEP private key (JWK format) for unwrapping workspace keys |
| publicKey | RSA-OAEP public key (JWK format) registered with the server |
Environment Variables
| Variable | Description |
|---|---|
| TOKENGATE_APP_URL | Override the default Tokengate web app URL. Useful for self-hosted deployments or local development. Defaults to https://tokengate.dev |
Multi-file Sync
Most projects use multiple .env files for different purposes: .env for shared defaults, .env.local for developer overrides, .env.production for production secrets. Tokengate handles all of them in a single workflow.
File Scanning
When you run tokengate init or tokengate push, the CLI scans the current working directory for files matching the pattern .env or .env.*. This includes files like:
.env- default environment variables.env.local- local developer overrides.env.development- development-specific variables.env.staging- staging environment variables.env.production- production secrets.env.test- test environment variables
Any file in the working directory that matches the /^\.env(\..+)?$/ regex pattern will be discovered. The scan is non-recursive and only checks the top-level directory.
Environment Mapping
During tokengate init, each discovered file is mapped to a remote environment within your project. A single environment can only be mapped to one local file. These mappings are stored in the .tokengate.json file and persist across push/pull operations.
If you add a new .env file later, run tokengate init again to add the new mapping. Your existing mappings are preserved.
Change Detection
Tokengate uses SHA-256 content hashing to detect changes efficiently. When you push, the CLI computes a hash of each local file and compares it to the content hash stored on the remote revision. Only files with different hashes are uploaded, saving bandwidth and avoiding unnecessary revisions.
The same mechanism works in reverse during pull: the CLI compares the remote content hash to a hash of your local file and only downloads files where the remote has changed.
Push/Pull Workflow
The typical workflow is straightforward:
- Edit your local
.envfiles as needed - Run
tokengate pushto upload changes - Team members run
tokengate pullto get the latest - Use
tokengate statusto check sync state at any time
File Selection
Both push and pull show you a table of all mapped files with their current status before making any changes. Files that are already in sync are skipped automatically. Only files with actual changes are transmitted.
Encryption
Tokengate implements a layered encryption architecture designed so the server never has access to plaintext secrets. All cryptographic operations use the Web Crypto API, a battle-tested standard available in all modern runtimes.
Workspace Key Model
Each workspace has a 256-bit AES workspace key generated at creation time. This key is the root of the encryption hierarchy and never leaves client devices in plaintext. When a new device is registered, the workspace key is wrapped (encrypted) using the device's RSA-OAEP 2048-bit public key, and the wrapped copy is stored on the server.
When the CLI needs the workspace key, it downloads the wrapped copy and unwraps it locally using the device's private key (which is stored only in ~/.config/tokengate/config.json).
Per-Revision Encryption
Each time you push a revision, the following process occurs entirely on your machine:
- A random 256-bit data key is generated for this specific revision
- A random 96-bit IV (initialization vector) is generated
- Your env file content is encrypted using AES-256-GCM with the data key and IV
- The data key is wrapped using the workspace key via AES-KW (Key Wrap)
- A SHA-256 content hash of the plaintext is computed for change detection
- The ciphertext, wrapped data key, and content hash are uploaded to the server
Why AES-KW?
AES Key Wrap (RFC 3394) is specifically designed for wrapping cryptographic keys. It provides both confidentiality and integrity protection for the wrapped key material, ensuring the data key cannot be tampered with in transit or storage.
Zero-Knowledge Architecture
The Tokengate server stores only:
- Encrypted ciphertext (AES-256-GCM output)
- Wrapped data keys (AES-KW output, only useful with the workspace key)
- Content hashes (SHA-256 of plaintext, used for change detection only)
- Wrapped workspace keys (RSA-OAEP output, one per device)
The server never sees your plaintext secrets, the workspace key in unwrapped form, or any per-revision data keys. Even with full database access, an attacker cannot decrypt your secrets without the RSA private key stored on an authorized device.
Recovery
When a workspace is created, a recovery phrase is generated from the raw workspace key using Base32 encoding. This phrase allows restoring workspace access if all devices are lost. Store it securely offline. The recovery phrase is shown once during workspace creation and cannot be retrieved again.
Important
If you lose your recovery phrase and all authorized devices, your encrypted data is permanently unrecoverable. There is no backdoor. This is by design.
Web Dashboard
The Tokengate web dashboard at tokengate.dev/dashboard provides a visual interface for managing your workspaces, projects, environments, and secrets. It complements the CLI for tasks that benefit from a graphical UI.
Workspace / Project / Environment Hierarchy
Tokengate organizes secrets in a three-level hierarchy:
- Workspace - the top-level container, typically one per organization or team. Each workspace has its own encryption key and member list.
- Project - a logical grouping within a workspace, usually mapping to a single code repository or service.
- Environment - a named set of secrets within a project, such as "default", "local", "staging", or "production". Each environment maps to one
.envfile.
Unlocking Environments
Environments are locked by default in the dashboard. To view or edit secrets, you must unlock the environment by providing the workspace credentials. The decryption happens entirely in your browser using the Web Crypto API. The plaintext is never sent to the server.
Key-Value Editor
Once unlocked, the dashboard presents a spreadsheet-style key-value editor where you can add, edit, or remove individual environment variables. Changes are encrypted and saved as a new revision when you click save. The editor highlights which keys have been modified since the last revision.
Revision History
Each environment maintains a complete revision history. You can view past revisions, see when they were created, and identify which team member pushed each change. This provides a full audit trail for secret changes across your team.
Browser Encryption
The web dashboard performs all encryption and decryption in the browser using the same Web Crypto APIs as the CLI. Your plaintext secrets exist only in browser memory and are never transmitted to or stored on the server.
Team Workflows
Tokengate is designed for teams. Multiple developers can push and pull secrets from the same project without stepping on each other's work.
Sharing Environments
To give a team member access to a project's secrets:
- Add them to the workspace via the web dashboard
- They install the CLI and run
tokengate loginto register their device - The workspace key is automatically wrapped for their device's public key
- They clone the repo (which includes
.tokengate.json) and runtokengate pull
Because .tokengate.json is committed to version control, new team members automatically get the correct project and environment mappings. They only need to authenticate their device once.
Conflict Detection
Tokengate uses revision numbers to detect conflicts. Each environment has a monotonically increasing revision counter. When you push, the CLI sends the expected revision number. If another team member pushed in the meantime, the server rejects the push and you must pull first to get the latest changes.
This optimistic concurrency model prevents accidental overwrites while keeping the workflow simple. In practice, environment variable changes are infrequent enough that conflicts are rare.
Recommended Team Setup
- One person creates the workspace via the web dashboard and saves the recovery phrase securely
- Add team members to the workspace through the dashboard
- Initialize the project with
tokengate initand commit.tokengate.jsonto your repository - Add
.env*to .gitignore to prevent accidental commits of secret files - Each developer runs
tokengate loginonce, thentokengate pullafter cloning the repo - Push changes after updating secrets locally, and communicate significant changes to the team
Git Integration
Make sure .env* patterns are in your .gitignore file. The .tokengate.json file should be committed since it contains only non-sensitive identifiers and environment mappings.
SDK (@tokengate/env)
The @tokengate/env SDK gives you type-safe, validated environment variables with zero-knowledge encryption. Define a schema, and the SDK fetches, decrypts, validates, and types your variables automatically.
Define a Schema
Create tokengate.config.ts in your project root:
Use in Your App
Schema Types
| Type | Parses to | Example |
|---|---|---|
string | string | "hello" |
number | number | "42" → 42 |
boolean | boolean | "true" / "1" / "yes" |
string[] | string[] | "a,b,c" → ["a","b","c"] |
number[] | number[] | "1,2,3" → [1,2,3] |
url | string | Validated URL |
email | string | Validated email |
port | number | 0–65535 |
enum | string | One of values |
Sources Priority
Variables load from these sources in order (first match wins):
- Cloud — Tokengate API (E2E encrypted, decrypted locally via
TOKENGATE_PASSWORD) - File — Local
.envfile - Process —
process.env
Generate Types
Next.js Integration
Wrap Your Config
Variables prefixed with NEXT_PUBLIC_ are automatically exposed to client-side code. All others are server-only.
Server Components / API Routes
Vite Integration
Add the Plugin
Variables prefixed with VITE_ are exposed to client code via import.meta.env. All variables are available in process.env during SSR/build.
Secret Scanning
Tokengate can scan your codebase for accidentally hardcoded secret values. It reads your mapped .env files, extracts the values, and searches all source files for matches.
CI Integration
tokengate scan exits with code 1 if leaks are found, making it easy to add to your CI pipeline as a pre-merge check.