Workspace folders are not preserved after switching or reloading an agent
Summary
When a chat starts, ChatSession passes add_dirs to the initial AgentThread.
However, switch_agent() and reload_agent() create a replacement AgentThread without passing add_dirs. Since the default is an empty list, additional workspace folders are no longer available after switching providers or reloading the agent.
_reconnect_chat_view() does not cover these cases. It creates a new ChatSession after a plugin or Sublime restart, while provider switching and agent reloads keep the existing ChatSession and replace only its AgentThread.
Steps to reproduce
- Open a project with multiple workspace folders.
- Enable:
{
"share_workspace_folders": true
}
- Start a TermMate chat.
- Confirm that the agent can access a file in a secondary workspace folder.
- Switch providers or resume an existing session.
- Ask the agent to access the same file again.
Expected behavior
The replacement agent retains access to the currently shared workspace folders.
Actual behavior
The secondary workspace folders are no longer available to the replacement agent.
Suggested fix
Recompute the current workspace context in both switch_agent() and reload_agent():
share_folders = settings.get("share_workspace_folders", False)
cwd = get_best_dir(self.chat_view)
add_dirs = get_all_folders(self.chat_view) if share_folders else []
self.cwd = cwd
self.add_dirs = add_dirs
self.agent_thread = AgentThread(
cwd,
self._handle_agent_message,
cli_path=cli_path,
anthropic_config=anthropic_config,
add_dirs=add_dirs
)
Recomputing is preferable to reusing the original self.add_dirs, since the workspace folders or share_workspace_folders setting may have changed since the chat was created.
Issue #4 is fixed in the current main branch. Closing as resolved.