Skip to content

Add aisw save command#6

Closed
JulioJair wants to merge 6 commits intoburakdede:mainfrom
JulioJair:add-save-command
Closed

Add aisw save command#6
JulioJair wants to merge 6 commits intoburakdede:mainfrom
JulioJair:add-save-command

Conversation

@JulioJair
Copy link
Copy Markdown
Contributor

@JulioJair JulioJair commented Apr 15, 2026

Problem

aisw add runs a full interactive login flow. When it fails or is interrupted, the native claude login (or codex login, gemini login) is always available as a fallback — but there was no way to hand those credentials over to aisw afterward.

Beyond aisw init (which imports live credentials during first-run onboarding), there was no way to capture live credentials that are already working and store them as a named aisw profile at any point after setup.

Solution

aisw save <tool> <profile_name> captures whatever credentials the tool currently has live and stores them as a new aisw-managed profile — no login flow launched.

aisw save claude work
aisw save codex personal --label "Personal OpenAI account"
aisw save gemini work

After saving, the profile is immediately activated and applied to the live tool config, so aisw status is consistent right away. If the profile name already exists, aisw prompts for confirmation before overwriting (or accepts --yes to skip the prompt).

Scope

Supports all three tools, reading from each tool's live config location:

Tool Source
claude ~/.claude/.credentials.json or system keyring (macOS)
codex ~/.codex/auth.json
gemini ~/.gemini/.env (API key) or OAuth files in ~/.gemini/

aisw save is essentially aisw init but targeted — it runs the same import logic already present in init (live_credentials_snapshot_for_import, copy_live_oauth_files_into_profile, etc.) and the same deduplication identity helpers used by aisw add, but lets you choose exactly which tool and profile name to save to without going through the full interactive onboarding flow.

Changes

  • src/commands/save.rs — new command, ~370 lines including 10 tests
  • src/cli.rsSaveArgs struct and Save variant in Command
  • src/commands/mod.rs — dispatch wired up
  • docs/commands.mdaisw save section
  • completions/ — regenerated from build.rs

All 369 existing tests pass. New tests cover profile creation, config registration, active profile state, overwrite with --yes, and the no-credentials error path for each tool.

When claude login is run outside of aisw — for example after an
interrupted aisw add — the live credentials in ~/.claude belong to
no aisw-managed profile. aisw save captures those credentials and
stores them as a named profile without re-running the login flow.

The command reuses the same snapshot, identity deduplication, and
credential storage logic as add, and follows the same run/run_in
split for testability. Only claude is supported for now, matching
the constraint that other tools do not have the same live-file
capture path.
aisw save was Claude-only. Codex and Gemini expose the same manual-login
scenario (codex login, gemini login run outside aisw), so the same save
pattern applies: read live credentials from each tool's config directory
and store them as a new aisw-managed profile without launching any login
flow.

Codex reads ~/.codex/auth.json and writes config.toml to force file-backed
auth, matching the import path in aisw init. Gemini reads OAuth files from
~/.gemini/ or a .env API key, also matching init. Both branches deduplicate
against existing profiles using the same identity helpers as add and init.

Adds 6 new tests (create + config-registration + no-credentials error for
each tool). All 369 tests pass.
Remove the "claude only" note and table, document the live credential
source for each of the three tools, and add codex/gemini examples.
Previously save only applied credentials to the live config when
--set-active was passed. This meant aisw status still showed the old
profile as active after saving, which was confusing.

Now save always applies the saved credentials to the live tool config
and marks the profile as active, so status is immediately consistent.
--set-active is replaced by --yes (used for overwrite confirmation).
@burakdede
Copy link
Copy Markdown
Owner

Thanks for pushing this.

I think the direction is right, and I want to confirm the problem statement as I understand it: this is primarily a recovery/adoption flow for cases where aisw add is interrupted or fails, but native tool login (claude login / codex login / gemini login) has already left valid live credentials locally. In that state, users need a way to bring those already-working live credentials under aisw management as a named profile.

Given that goal, I think this fits better as aisw add <tool> <profile-name> --from-live rather than a new top-level command. Conceptually, it keeps everything under the existing “add profile from a source” model (--api-key, interactive OAuth, env, and now live credentials), and avoids introducing another verb users need to learn for essentially the same lifecycle step.

Adding a new top-level command here has a few downsides: it increases CLI surface area and docs/completion overhead, creates semantic overlap with add, and raises long-term consistency/maintenance complexity (more places where behavior and help text can drift). From a DX perspective, add --from-live is easier to discover, easier to explain, and clearer in intent for this recovery case.

So overall: directionally right problem to solve, and I’d recommend we solve it via add --from-live as the canonical path.

I would really love to merge this before the new version release this week, if you can reshape the PR in this direction. (or clean new PR)

@JulioJair
Copy link
Copy Markdown
Contributor Author

JulioJair commented Apr 16, 2026

Closing in favor of #7, which reshapes this as aisw add --from-live per your feedback. Thanks for the clear direction — made it easier to get it right. Also made --from-live auto-activate since the credentials are already live by definition.

@JulioJair JulioJair closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants