Run each `clai2 --web` session in its own directory, and ask where a new one runs
Part 36 of the clai2 web UI stack (… → #10349 → this PR). Based on #10349. No linked issue: requested by the CLAI maintainer.
Why. clai2 --web stayed tied to the directory it was launched from: a session saved in another repository or worktree opened read-only ("Start CLAI there to continue it"), and every new session ran in the launch directory. With part 35's sidebar listing every project and worktree, the browser should be able to continue any of them, and start a new session wherever the user picks.
What changes
- Under
clai2 --webonly, each session runs in its own directory.runtime/session_workspace.py'sSessionWorkspace.moveswitches the one live session between turns, the way--worktreestarts CLAI in a checkout:os.chdir(the headless web process has no terminal and holds one live session at a time, and CLAI's plugin contract is that the working directory is the session's), that directory's.clai/settings.jsonresolved again with saved settings and launch flags (CommandContext.use_project), and every plugin butwebloaded again (PluginLoader.restart). So the tools,repo_context/AGENTS.md, skills, MCP project files, and the system prompt are built for that directory. run_webattaches it:/resume IDfirst moves to the session's saved directory (Sessions.relocate),clai2 --web --resume IDstarts there, and a web-only/workspace DIRECTORYstarts a new session in an existing absolute directory. Nothing moves while a turn, a background fork, or a delegated task runs. A directory that no longer exists is refused with a clear error, so its session stays read-only (and--web --resumeof it fails at startup naming the session).host.sessions.follows_workspace(SessionCatalog),Snapshot.follows_workspace,Transcript.missing;POST /api/sessions/newtakes an optionalworkspace, validated as an existing absolute directory, and only the token-guarded UI supplies it.- Web UI: New session (and Cmd/Ctrl+Shift+O) opens a picker with the current directory first, then the projects and worktrees part 35 lists (removed ones left out), or a typed absolute path with inline errors. A session from another existing directory opens directly with no read-only banner; the header shows its directory; one whose directory is gone shows "Saved in X, which no longer exists. You can read it here."
- Docs: README web UI, PLUGINS.md (
web,host.sessions, worktree startup), AGENTS.md file map.
Verification.
- New tests:
test_sessions_continue_in_their_own_directories,test_a_session_moves_only_between_turns,test_a_terminal_session_stays_where_it_started(tests/clai2/test_web.py),test_run_web_works_in_each_sessions_directory,test_run_web_refuses_a_session_whose_directory_is_gone,test_run_web_reports_an_unknown_session, andtest_web_flag_runs_the_web_uinow checkssettings_for(tests/clai2/test_web_parts.py).tests/clai2: 4181 passed. 100% branch coverage of every added or changed line (session_workspace.py,cli/web.py,remote.py,app.py,protocol.pyat 100%; the new lines in_cli.py,command_context.py,loader.py,sessions.pycovered). Pyright, ruff,tsc --noEmitclean. - Headed Chromium against an isolated
clai2 --web -m testlaunched in repoalpha, with sessions inalpha, two linked worktrees, a removed worktree, a second repobeta, and a plain folder: opening each moved the process's working directory there (checked withlsof), a prompt run inbetasent noalphaAGENTS.mdor project instructions, the removed worktree opened read-only, the picker listedbeta · main,plain,alpha · feature-two,alpha · feature-one,alpha · main, a relative path was refused inline, and new sessions started inplainandalpha-feature-two. Dark and light screenshots. - Interactive
clai2in tmux:/workspaceis an unknown command and/resume IDof another directory still refuses, as before.
What changes for existing users. Only clai2 --web changes: sessions from other directories can now be continued there, and a new session asks where it runs. clai2, clai2 -p, and /web started from a terminal keep working in the directory they started in, with other directories' sessions read-only as before.
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.