> ## Documentation Index
> Fetch the complete documentation index at: https://chatcli.edilsonfreitas.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: Managing Multiple Projects with Contexts and Sessions

> Learn how to combine /context and /session to create an efficient workflow when switching between different projects.

Switching between projects can break your workflow, especially when each one has its own codebase and issue history. This recipe shows how to use **Persistent Contexts** and **Session Management** to switch between projects instantly and in an organized way.

## The Problem

You work on two projects: `Project A` (a Go API) and `Project B` (a React frontend). One moment you are debugging a bug in the API; the next, you need to implement a new feature in the frontend. Keeping the conversation history and file context separate for each is a challenge.

## Ingredients

* Two or more project directories on your machine.

***

## The Workflow

The strategy is to create a **Context** for each project's codebase and a **Session** for each task's conversation history.

<Steps>
  <Step title="Create Persistent Contexts for Each Project">
    First, let's create "snapshots" of the codebases. We will do this once for each project.

    Navigate to the `Project A` folder:

    ```bash theme={"system"}
    /context create project-a-api ./cmd ./internal --mode smart --description "Main Go API for Project A" --tags go,api
    ```

    Now, navigate to the `Project B` folder:

    ```bash theme={"system"}
    /context create project-b-frontend ./src --mode chunked --description "React frontend for Project B" --tags react,frontend
    ```

    <Info>
      **What did we do?** We created two persistent contexts. Now, ChatCLI "knows" the structure of these two projects and we can refer to them by name (`project-a-api`, `project-b-frontend`) at any time, from anywhere on your system.
    </Info>
  </Step>

  <Step title="Start Working on Project A">
    Let's begin debugging the bug in the API.

    1. **Load (or create) a conversation session:**

       ```bash theme={"system"}
       /session load debug-api-project-a
       ```

       *(If the session does not exist, it will be created when you save.)*

    2. **Attach the project context:**

       ```bash theme={"system"}
       /context attach project-a-api
       ```

    Now, your prompt will indicate that the session and context are active. You can start asking questions about the API code, and ChatCLI will automatically send the relevant files to the AI.

    ```text theme={"system"}
    debug-api-project-a > Where is the JWT validation logic?
    ```
  </Step>

  <Step title="Switch to Project B">
    Your lead asks you to pause the debug and work on a new feature in the frontend.

    1. **Save the current session:** All your debug history will be preserved.

       ```bash theme={"system"}
       /session save debug-api-project-a
       ```

    2. **Detach the old context:**

       ```bash theme={"system"}
       /context detach project-a-api
       ```

    3. **Load the session and context for Project B:**

       ```bash theme={"system"}
       /session load feature-frontend-project-b
       /context attach project-b-frontend
       ```

    Done! In seconds, you have completely switched environments. Your conversation history is now about the frontend feature, and the AI has all of `Project B`'s code as context.

    ```text theme={"system"}
    feature-frontend-project-b > Create a new React component called 'UserProfile' that displays name and email.
    ```
  </Step>

  <Step title="Returning to Project A">
    Frontend task completed? Going back to the API debug is just as simple.

    ```bash theme={"system"}
    /session save feature-frontend-project-b
    /context detach project-b-frontend
    /session load debug-api-project-a
    /context attach project-a-api
    ```

    <Tip>
      **Result:** You created a workflow where you can switch between complex projects in seconds, preserving both your conversation history and the complete codebase context, without ever needing to resend a single file manually.
    </Tip>
  </Step>
</Steps>
