secrets
ak secrets import-env
Bulk-import secrets from a dotenv file or a project directory
When <path> is a directory, the command finds its .env and .env.* files (up to three levels down), skips example, backup, symlinked files and hidden or dependency directories, and imports them as one plan. A key defined in more than one file is a conflict and is skipped everywhere. --dry-run prints the plan without writing; --project records one project for every key instead of each file's directory.
Use ak secrets import-env for the operation described below. The command help records its arguments, effects, and options.
With vault sync enabled, a successful local write starts a background push for the OS-backed vault. The command returns without waiting. Use --no-push for this write or set AGENTKIT_SECRETS_AUTO_PUSH=0 to opt out. The file backend syncs when you run ak secrets sync now.
Command contract
Bulk-import secrets from a dotenv file or a project directory
Synopsis
Parse <path> as a minimal dotenv file (KEY=value, KEY="quoted", KEY='quoted', # comments, blank lines) and store one secret per key. <path> must be at most 1 MiB. Values are never printed, logged, or included in --json output — only the imported/skipped counts and (with --verbose) a safe per-line reason are shown. Without --force, a key that already has a stored value is skipped rather than overwritten; --force overwrites instead. Use it when onboarding an existing .env-based project onto the secrets vault.
When <path> is a directory, import-env finds its dotenv files (.env and .env.*, up to three levels down, in path order) and imports them as one plan. It skips example, template and backup files (.env.example, .env.template, .env.bak, ...), dotenv-vault files, symbolic links, hidden and dependency directories, and lists each skipped file. A key defined in more than one file is a conflict: it is skipped everywhere and every place is named, so no file silently wins; a replace keeps an environment or project typed with annotate. The whole plan is printed, and --dry-run prints it without storing anything. Each imported key records its file as its source, the environment from the file name (.env.production: production) and the directory as its project, as imported profile text; --project names the project instead. Directory names and file names are only ever stored as text, never followed as instructions.
Effects:
Writes one value per imported key to the active backend and updates each key's metadata, including its value hint (--no-hint records none), in ~/.agentkit/secrets/index.json. Never modifies <path> or any file under it. --dry-run writes nothing. With sync on, it then starts a background ak secrets sync now that pushes the change without waiting for it; --no-push or AGENTKIT_SECRETS_AUTO_PUSH=0 turns that off, and the file backend is never pushed in the background.
Exit status: 0 success 2 invalid flags or arguments, an unreadable path, a file over the 1 MiB import limit, or a directory with too many dotenv files 5 backend or index failure
ak secrets import-env <path> [flags]Examples
ak secrets import-env ${PATH} # skip keys that already exist
ak secrets import-env ${PATH} --force # overwrite existing keys too
ak secrets import-env ${PATH} --verbose --json # machine-readable per-line detail
ak secrets import-env ${DIR} --dry-run # preview a project directory importOptions
--backend string Storage backend: keychain (default), file (age-encrypted vault), or memory (dev/test; values and its index are throwaway)
--dry-run Directory import: print the plan without storing anything
--force Overwrite keys that already have a stored value
-h, --help help for import-env
--json Emit machine-readable JSON (implies --no-interactive)
--no-hint Record no value hint for any imported key
--no-interactive Disable interactive prompts (CI-safe)
--no-push ak secrets sync now Do not push this change to the sync vault in the background (it syncs at the next ak secrets sync now)
--project string Directory import: record this project for every key instead of each file's directory
-q, --quiet Suppress non-error output on stderr
--unlock-with-recovery Open the file backend's vault with a recovery private key and set a new passphrase
-V, --verbose Extra diagnostic output on stderr (loses to --quiet)
-y, --yes Assume yes for all promptsSEE ALSO
- ak secrets - Manage named secret values (API keys, tokens)