HeadlinesBriefing favicon HeadlinesBriefing.com

VS Code tmux Integration: Persistent Sessions

DEV Community •
×

Developers using VS Code and tmux want the integrated terminal to automatically join the correct session without manual commands. A native configuration uses `terminal.integrated.profiles` to launch tmux with a session named after the workspace folder. This approach is simple and ensures one project maps to one persistent session, keeping panes and layouts intact across editor restarts.

However, VS Code's settings lack conditional logic, preventing developers from grouping related projects under a single tmux session. For instance, multiple frontend and backend folders (`fe-dashboard`, `be-api`) can't be routed to a shared 'work' session using folder-name patterns. This limitation forces separate sessions for conceptually connected work, breaking context and layout persistence.

The robust solution moves session logic to the shell by detecting VS Code's environment variables like `VSCODE_PID` and `TERM_PROGRAM=vscode`. A shell script can then apply custom rules—grouping projects by naming patterns—and launch tmux accordingly. This method offers flexible grouping, avoids session duplication, and requires no plugins, relying on stable, unofficial variables.