> ## Documentation Index
> Fetch the complete documentation index at: https://stagehand-stg-1784.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# User Data Directory

> Persist browser data between sessions

### User Data Directory

Persist browser data between sessions using a custom user data directory:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Stagehand } from "@browserbasehq/stagehand";

  // For Browserbase sessions
  const stagehand = new Stagehand({
    env: "BROWSERBASE",
    browserbaseSessionCreateParams: {
      userDataDir: "/path/to/user/data/directory",
    },
  });

  // For Local sessions
  const localStagehand = new Stagehand({
    env: "LOCAL",
    localBrowserLaunchOptions: {
      userDataDir: "./browser-data",
    },
  });

  await stagehand.init();
  console.log("Session ID:", stagehand.sessionId);
  ```

  ```python Python theme={null}
  from stagehand import Stagehand

  # For Browserbase sessions
  stagehand = Stagehand(
      env="BROWSERBASE",
      browserbase_session_create_params={
          "user_data_dir": "/path/to/user/data/directory",
      },
  )

  # For Local sessions
  local_stagehand = Stagehand(
      env="LOCAL",
      local_browser_launch_options={
          "user_data_dir": "./browser-data",
      },
  )

  await stagehand.init()
  print(f"Session ID: {stagehand.session_id}")
  ```
</CodeGroup>
