How to split the terminal when running tasks in VSCode?

The following should work:

{
    "type": "process",
    "label": "terminal",
    "command": "/bin/bash",  // <-- your shell here
    "args": [
        "-l"  // login shell for bash
    ],
    "problemMatcher": [],
    "presentation": {
        "echo": false,  // silence "Executing task ..."
        "focus": true,
        "group": "sxs",  // some arbitrary name for the group
        "panel": "dedicated"
    },
    "runOptions": {
        "runOn": "folderOpen"
    }
}

Here, I'm auto-launching (and setting the focus on) the terminal when the folder is opened in vscode -- and further tasks that share the same presentation.group gets placed in split terminals when they're run (with new vs. reused splits depending on their presentation.panel)

Note: For this example, you may or may not need the -l option depending on your settings for terminal.integrated.shell*, terminal.integrated.automationShell* and terminal.integrated.inheritEnv -- this issue has some discussion on what is involved in setting up the shell environment.


Direct support for this was added in the January 2019 update.

Setting the same name for the presentation.group property of each task will cause the tasks to appear in split terminals. From the VS Code documentation:

group: Controls whether the task is executed in a specific terminal group using split panes. Tasks in the same group (specified by a string value) will use split terminals to present instead of a new terminal panel.


When creating your task make sure to have the presentation.reveal option set to always and presentation.panel option set to new. That way the output is always revealed and a new terminal is created on every task run

Example:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run tests",
            "type": "shell",
            "command": "./scripts/test.sh",
            "windows": {
                "command": ".\\scripts\\test.cmd"
            },
            "group": "test",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }
    ]
}

More info at: Tasks in Visual Studio Code

EDIT: Since you want new tasks into split terminals, maybe this info helps. I don't think it is possible to do it: Launch task directly into split terminal