Skip to content

feat(cli): add custom session id startup flag#924

Open
tt-a1i wants to merge 1 commit into
MoonshotAI:mainfrom
tt-a1i:fix/session-id-create
Open

feat(cli): add custom session id startup flag#924
tt-a1i wants to merge 1 commit into
MoonshotAI:mainfrom
tt-a1i:fix/session-id-create

Conversation

@tt-a1i

@tt-a1i tt-a1i commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Fixes #820.

Adds a new --session-id <id> startup flag for callers that want a stable session id:

  • resumes the matching session when it already exists in the current workdir
  • creates a new session with that id when it does not exist
  • keeps --session resume-only
  • rejects ids that already exist under another workdir and prints a cd hint
  • supports the hidden --session_id alias for compatibility with the issue request

Also updates EN/ZH docs, CLI validation, tests, and the changeset.

Validation

  • pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/options.test.ts test/cli/session-flag-picker.test.ts test/cli/run-prompt.test.ts test/tui/kimi-tui-startup.test.ts
  • pnpm --filter @moonshot-ai/kimi-code exec vitest run
  • pnpm --filter @moonshot-ai/kimi-code run typecheck
  • pnpm exec oxlint --type-aware apps/kimi-code/src/cli/commands.ts apps/kimi-code/src/cli/options.ts apps/kimi-code/src/cli/run-prompt.ts apps/kimi-code/src/main.ts apps/kimi-code/src/tui/kimi-tui.ts apps/kimi-code/src/tui/types.ts apps/kimi-code/test/cli/options.test.ts apps/kimi-code/test/cli/run-prompt.test.ts apps/kimi-code/test/cli/session-flag-picker.test.ts apps/kimi-code/test/tui/kimi-tui-startup.test.ts --quiet
  • pnpm --filter @moonshot-ai/kimi-code run build
  • git diff --check

Checklist

  • Tests updated
  • Docs updated
  • Changeset added

AI Assistance Disclosure

I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.

@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 927ec4b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tt-a1i tt-a1i marked this pull request as ready for review June 20, 2026 04:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 927ec4ba70

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +578 to +581
session = await this.harness.createSession({
...createSessionOptions,
id: startup.sessionIdFlag,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve custom session IDs after OAuth login

When kimi --session-id foo is started with a missing or expired OAuth login, this initial createSession call can throw isOAuthLoginRequiredError and init() enters the login-required state. After the user completes /login, AuthFlowController.activateModelAfterLogin() creates the session without passing startup.sessionIdFlag, so the eventual session gets a generated id instead of the user-specified foo. This breaks the create-with-stable-id path specifically for first-time/expired-login startup; carry the pending custom id into the post-login create path.

Useful? React with 👍 / 👎.

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.

需要--session_id参数,用来传入自定id,创建新session

1 participant