Skip to content

feat(cli): add multi-session management subcommands for Codex CLI #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

kshitizz36
Copy link

@kshitizz36 kshitizz36 commented Apr 22, 2025

Multi-Session Management for Codex CLI

Overview

This PR introduces enhanced session management functionality to the Codex CLI. Users can now save, list, load, and delete sessions using either autogenerated IDs or custom session names. The update extends the session-manager module (now supporting optional fields like cwd and firstPrompt), modifies the CLI parsing logic to handle new session subcommands, and includes additional unit tests.

Changes

  • CLI Additions:
    • Updated src/cli.tsx to add new session subcommands:
      • codex session save [name]
      • codex session list
      • codex session load <id/name>
      • codex session delete <id/name>
  • Session Manager Enhancements:
    • Extended TerminalChatSession type (in src/utils/session.ts) with optional fields (cwd and firstPrompt)
    • Updated session storage in src/utils/session-manager.ts to handle the new fields.
  • Testing:
    • Added/updated tests in tests/session-manager.test.ts to cover session creation, loading, updating, and deletion.
  • Formatting:
    • Applied Prettier formatting to all modified files.
  1. Verify session commands manually:
    • Save a session:
      codex session save my-feature
      
    • List sessions:
      codex session list
      
    • Load a session:
      codex session load my-feature
      
    • Delete a session:
      codex session delete my-feature
      

@kshitizz36 kshitizz36 changed the title feature/multi session cli feat(cli): add multi-session management subcommands for Codex CLI Apr 22, 2025
@tibo-openai
Copy link
Collaborator

Could you explain in details and give examples of the expected flow here? For example, it's not clear to me when one would use save as you would have to do that before you actually have interacted with codex?

Additionally, seems that CI isn't passing, please check that and make sure it passes and I will have another look, thanks for the contribution!

kshitizz36 and others added 3 commits April 22, 2025 20:19
- Updated TerminalChatSession type to include 'cwd' and 'firstPrompt'.

- Added non-null assertions in session-manager.test.ts to fix TS2532 errors.

- Ensures type-checking passes for session management tests.
@kshitizz36 kshitizz36 force-pushed the feature/multi-session-cli branch from e6ef157 to 0dd840e Compare April 22, 2025 15:43
@kshitizz36 kshitizz36 force-pushed the feature/multi-session-cli branch from 6b156f1 to 981a810 Compare April 22, 2025 15:54
@kshitizz36
Copy link
Author

kshitizz36 commented Apr 22, 2025

@tibo-openai

Clarification on the Multi-Session Expected Flow

The save command is not meant to be used before interacting with Codex. Instead, it's designed to capture the state of an already ongoing or completed interactive session.

Here's a more refined breakdown of the intended flow with examples:

  1. Start an Interactive Session: You begin a standard interactive session with Codex, setting initial context or just asking a question.

    codex "How do I list files in a directory?"
  2. Develop the Session Context: You continue interacting, potentially providing custom instructions, changing the model, or having a multi-turn conversation that builds valuable context.

    # Inside the interactive session...
    > Add examples for different OS?
    > Use the gpt-4 model for this conversation.
    > Actually, I also need to know how to find files recursively.

    At this point, the session holds information about the initial prompt, the follow-up questions, potentially model changes, and any custom instructions that were set.

  3. Save the Session: Now, with the session containing useful context, you decide you might want to come back to this specific conversation or configuration later. You use the session save command, giving it a memorable name.

    # Still inside or immediately after the interactive session...
    codex session save file-operations-helper

    This command captures the current state (model used, custom instructions, conversation history if the session object stores it, working directory, etc.) and saves it under the name file-operations-helper.

  4. Switch Context or Exit: You can now safely exit the current session or start a new, unrelated one.

  5. List Saved Sessions: Later, you can see all your saved sessions.

    codex session list
    ID                      Model     Timestamp           Description
    file-operations-helper  gpt-3.5   2023-10-27T10:00:00  "How do I list files...
    project-setup-help      gpt-4     2023-10-26T15:30:00  "Help me set up my Node.js project..."
    
  6. Load a Saved Session: When you want to resume working on file operations, you load the saved session.

    codex session load file-operations-helper

    This command finds the saved state for file-operations-helper and restores it, effectively putting you back into the context you saved earlier, including the model and any specific instructions or history associated with that session.

  7. Continue or Delete: You can continue the conversation from where you left off, or delete the session if it's no longer needed.

So, in summary, the save command is used imperatively by the user during or after an interactive session to snapshot its current state, not as a prerequisite to starting an interaction.

@moku23
Copy link

moku23 commented Apr 22, 2025

that's very helpful, excelcially when error happens for example exceed quota limit and you need to write again initial promp

@kshitizz36
Copy link
Author

@tibo-openai @fouad-openai PTAL

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.

3 participants