Skip to content

bug(cli/setup): archon setup silently overwrites repo .env and loses secrets #1303

@133Felix

Description

@133Felix

Problem

archon setup unconditionally overwrites <repo>/.env on every run. No existence check, no backup, no confirmation prompt. Any user-added secrets — tokens, custom vars, credentials the wizard doesn't know about — are permanently lost.

This is a data-loss bug. .env is gitignored, so there is no recovery path; users rediscover the loss only when a platform adapter fails to authenticate and they have to re-collect every secret from scratch.

Where it happens

  • packages/cli/src/commands/setup.ts:1311-1331writeEnvFiles() calls writeFileSync(repoEnvPath, content) unconditionally for both ~/.archon/.env and <repo>/.env.
  • packages/cli/src/commands/setup.ts:1567-1614 — "Add platforms" mode makes it worse: the written SetupConfig is built from boolean presence flags returned by checkExistingConfig(), which never reads the actual values. Result on every "Add" run:
    • database is hardcoded to { type: 'sqlite' } → silently downgrades an existing PostgreSQL config
    • claudeApiKey / claudeOauthToken / codexTokens are undefined → auth lines are dropped from the regenerated file

Impact

  • Lost secrets on every archon setup re-run touching an existing repo
  • Silent PostgreSQL→SQLite downgrade in "Add" mode
  • Forced re-collection of bot tokens, webhook secrets, API keys
  • Happens on the documented onboarding path

Proposed Fix

  1. Refuse to overwrite an existing non-empty <repo>/.env without explicit consent. Default to a timestamped backup + non-destructive merge (only add keys that don't already exist).
  2. In "Add" mode, parse the existing file and carry all values forward; only write keys the user changed this run.
  3. Explicit --force flag for users who actually want to regenerate.

Relationship to #1196

Same user journey, two angles:

Landing #1196 avoids the overwrite for the scaffold-only path but doesn't fix it for users legitimately updating config. Both should ship — ideally together.

Severity

Data-loss bug → priority: high. No git history, no backup, no undo.

Definition of Done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions