concurrently

repository·main·Indexed 27 days ago

https://github.com/open-cli-tools/concurrently

A tool for running multiple commands concurrently in a single terminal session with prefixed output and cross-platform support. Version 10.0.4 provides both a Command Line Interface (CLI) and a programmatic API to execute commands in parallel, featuring output control, success condition monitoring, process restarting, and IPC support.

Tokens
9.9K
Snippets
35
Records
66
Agent score
92%

What's inside concurrently

  1. Overview of Concurrently

    main
    Concurrently is a tool designed to run multiple commands simultaneously. It can be used via a Command Line Interface (CLI) or through its programmatic API. When using either interface, be aware that shell resolution rules apply to how commands are parsed and executed.
  2. Use passthrough arguments with concurrently

    main
    When running commands via concurrently, additional flags passed to the CLI (e.g., npm run build -- --flag) are often parsed by concurrently itself instead of being passed to the underlying commands. To fix this, use the --passthrough-arguments or -P flag. This flag instructs concurrently to take everything following a -- delimiter and distribute it to the input commands using specific placeholders.
  3. Install concurrently

    main

    You can install concurrently either globally for system-wide use or locally as a development dependency for a specific project. It is recommended to add it to devDependencies.

    # Global installation
    npm i -g concurrently
    yarn global add concurrently
    pnpm add -g concurrently
    bun add -g concurrently
    
    # Local installation (recommended for devDependencies)
    npm i -D concurrently
    yarn add -D concurrently
    pnpm add -D concurrently
    bun add -d concurrently
  4. Inherit shell configuration from npm, pnpm, or yarn v1

    main

    When running concurrently through a package.json script using npm, pnpm, or yarn v1, concurrently will inherit and use the script-shell configuration from the package manager. This allows you to set a global shell for your scripts via the package manager's config.

    npm config set script-shell /bin/bash
    npm dev # Runs the dev script on bash. Concurrently will also run commands using bash.
  5. Override the default shell in concurrently

    main

    By default, concurrently uses cmd.exe on Windows and /bin/sh on other platforms. If you need to use a different shell (for example, to use Unix-style syntax like BROWSER=none on Windows by using Git Bash), you can provide an explicit shell override. This override takes precedence over all other configurations.

    # Via CLI
    concurrently --shell "C:\Program Files\Git\bin\bash.exe" "echo Hello world | xargs -n 1 echo"
    
    # Via API
    concurrently(['echo Hello world | xargs -n 1 echo'], {
      shell: 'C:\\Program Files\\Git\\bin\\bash.exe',
    });
  6. Terminate all commands only when a command fails

    main

    Use the --kill-others-on-fail flag to terminate all other running commands only if one of them exits with a non-zero exit code. This is useful in build pipelines where you want to abort all processes if any single build step fails.

    $ concurrently --kill-others-on-fail 'npm run app1:build' 'npm run app2:build'
  7. Use concurrently via CLI

    main

    Run multiple commands concurrently by passing them as quoted strings. The command concurrently also has a shorthand alias conc.

    Important for Windows users: Windows only supports double quotes. When using concurrently inside a package.json script on Windows, you must escape the double quotes.

  8. Use Concurrently via CLI

    main
    Concurrently provides a CLI for running multiple commands in parallel. The CLI supports various features including command prefixing, output control, success condition monitoring, command restarting, and custom configuration. For advanced usage, you can pass arguments through to the underlying commands.
  9. Terminate all commands when any command exits

    main

    Use the --kill-others flag to ensure that concurrently terminates all other running commands as soon as the first command exits, regardless of whether it succeeded or failed (exit code 0 or non-zero). This is useful for stopping a long-running server process once a test suite completes.

    $ concurrently --kill-others --names server,test 'npm start' 'npm test'
  10. Use package manager shortcuts in concurrently

    main

    You can use shorthand syntax to execute scripts from package.json or deno.(json|jsonc) files. When using these shortcuts, concurrently automatically assigns the command name based on the script name.

    Supported shortcuts:

    • npm:<script> expands to npm run <script>
    • pnpm:<script> expands to pnpm run <script>
    • yarn:<script> expands to yarn run <script>
    • bun:<script> expands to bun run <script>
    • node:<script> expands to node --run <script> (Requires Node 22+)
    • deno:<script> expands to deno task <script>
    $ concurrently 'pnpm:lint:js'
    # Is equivalent to
    $ concurrently -n lint:js 'pnpm run lint:js'
  11. Scope colors to specific parts of a prefix template

    main

    When using a custom --prefix template, you can restrict coloring to specific segments using {color} and {/color} markers. Any text outside these markers will use the terminal's default color.

    • {color}: Starts the colored region.
    • {/color}: Ends the colored region.

    If a marker is left unclosed, the color will extend to the end (for {color}) or from the start (for {/color}) of the prefix.