Session Management
Sessions are the core concept in msw-cli. A session is a named, running daemon process that holds a WebSocket port and tracks the connected browser tab.
How sessions work
Section titled “How sessions work”When you run msw-cli open, it:
- Derives a session name from the current working directory (e.g.,
my-project). - Checks
~/.msw-cli/sessions/for an existing session with that name. - If one exists and the daemon is still alive, it reuses the existing port and prints it.
- If none exists (or the daemon died), it starts a new
@msw-mcp/coredaemon process, picks a port, and saves the session metadata.
Session metadata is stored as JSON files under ~/.msw-cli/sessions/:
~/.msw-cli/sessions/├── my-project.json└── another-app.jsonNaming sessions
Section titled “Naming sessions”By default, the session name is the basename of the current working directory.
Override it with -s, --session <name>:
# Name the session explicitlymsw-cli open -s staging
# Then target the same session from any directorymsw-cli -s staging add "http.get('/api/flag', () => HttpResponse.json({ enabled: true }))"msw-cli -s staging statusmsw-cli -s staging closeThis is useful when you want a consistent session name regardless of where you run the command.
Concurrent sessions
Section titled “Concurrent sessions”Multiple sessions can run simultaneously on different ports:
# Project A on port 6789 (default)cd ~/projects/app-amsw-cli open
# Project B auto-selects the next available portcd ~/projects/app-bmsw-cli open# → [MSW] Daemon started on ws://localhost:6790Each browser tab connects to its own daemon via MCP_SERVER_URL in .env.local.
Using a fixed port
Section titled “Using a fixed port”If your app is configured with a hardcoded MCP_SERVER_URL, pass --port to enforce the exact port:
msw-cli open --port 6789With --port, the command fails immediately if the port is already in use. Without --port, it auto-increments.
Listing and closing sessions
Section titled “Listing and closing sessions”# See all active sessionsmsw-cli list
# Close the current directory's sessionmsw-cli close
# Close a specific named sessionmsw-cli close staging
# Nuke all sessions at oncemsw-cli close-allSession isolation for CI
Section titled “Session isolation for CI”To prevent cross-test interference in CI, use a unique session name per job:
msw-cli open -s "ci-job-$CI_JOB_ID" --port "$MSW_PORT"# ... run tests ...msw-cli close -s "ci-job-$CI_JOB_ID"Session storage location
Section titled “Session storage location”All metadata lives in ~/.msw-cli/sessions/. This directory is created automatically on first use. You can safely delete it to clear all session state — equivalent to msw-cli close-all.