# Snippets

## Overview

In Termius, a **snippet** is a labeled shell script that you can save and run on different hosts without retyping it. Think of them as a cloud-synced library of your most-used or proven scripts/commands.

Snippets are stored in [Vaults](/getting-started/learn-about-vaults.md), synced across devices, and available to your team when you share the vault with a paid subscription. If you have a team, every member can contribute to the snippets library, making teamwork easier.

With snippets, you can:

* Run the same command on multiple hosts
* Run a startup snippet each time you connect to a host
* Paste or run commands from the terminal side panel
* Run saved commands from [Autocomplete](/terminal/autocomplete-and-shell-integration.md)
* Organize snippets with snippet packages
* Share approved commands with your team

## Create a snippet

{% tabs %}
{% tab title="Desktop" %}
On the Desktop, you can create a snippet either from the dedicated Snippets screen or from the side panel in the terminal. You can also use the AI to generate a snippet from your description.

#### From the Snippets screen

1. Open the `Vault` tab, then open the `Snippets` screen<br>

   <figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
2. Click `New Snippet`<br>

   <figure><img src="/files/eIhiHXRyvZvCPRwKvE7e" alt=""><figcaption></figcaption></figure>
3. In the `Action description` field, describe what the snippet does. Enter the command in the `Script` field. Termius saves the snippet automatically<br>

   <figure><img src="/files/rTiDCdFi7raKaKMBiU1j" alt=""><figcaption></figcaption></figure>

***

#### From the terminal side panel

1. Open the side panel with `Ctrl/Cmd + .`<br>

   <figure><img src="/files/BD0ydGkJNMIJ9wChJnGn" alt=""><figcaption></figcaption></figure>
2. Open the `Snippets` tab <i class="fa-brackets-curly">:brackets-curly:</i><br>

   <figure><img src="/files/WC9EXAmdQNAxS2VcnISl" alt=""><figcaption></figcaption></figure>
3. Click `New Snippet`

   <figure><img src="/files/Had9CXm9rR9zPHMDQhqv" alt=""><figcaption></figcaption></figure>
4. In the `Action description` field, describe what the snippet does. Enter the command in the `Script` field<br>

   <figure><img src="/files/mu0Wk2UIKHhGInCDfRCx" alt=""><figcaption></figcaption></figure>
5. Click `Save`

***

#### Generate with AI

1. Open the `New Snippet` editor from the Snippets screen or the terminal<br>

   <figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
2. In the `Action description` field, describe what the command should do in plain language<br>

   <figure><img src="/files/hx50dXak7RkN1RwnRr7Y" alt=""><figcaption></figcaption></figure>
3. Click the `magic wand` button
4. Termius generates the snippet and inserts it into the `Script` field
   {% endtab %}

{% tab title="Mobile" %}

#### From the Snippets screen

1. Tap the back arrow button `<` to open the **Vaults** screen, then open the `Snippets` screen<br>

   <div align="left"><figure><img src="/files/TZ1pRGG18ka51wufGMeA" alt="" width="375"><figcaption></figcaption></figure></div>
2. Tap the plus button and choose `New Snippet`<br>

   <div align="left"><figure><img src="/files/SNSztv4PXbOUXRVNI93a" alt="" width="375"><figcaption></figcaption></figure></div>
3. In the `Name` field, describe what the snippet does
4. Enter a command or a script in the `Script` field
5. `Save` the snippet<br>

   <div align="left"><figure><img src="/files/Y91hJPI2e5HQqg7UqCcW" alt="" width="375"><figcaption></figcaption></figure></div>

***

#### From the terminal

1. Open the additional keyboard by tapping the `4 squares` button. On iPad, open the right-side panel instead<br>

   <div align="left"><figure><img src="/files/8p1Ew0bvcPE2RMsNieqM" alt="" width="375"><figcaption></figcaption></figure></div>
2. Open the `Snippets` tab <i class="fa-brackets-curly">:brackets-curly:</i><br>

   <div align="left"><figure><img src="/files/77OZfts03BtBntX2y9O2" alt="" width="375"><figcaption></figcaption></figure></div>
3. Tap `Add new snippet` at the bottom of the list<br>

   <div align="left"><figure><img src="/files/sAZgd7rXnOVAvm92qKRy" alt="" width="375"><figcaption></figcaption></figure></div>
4. In the `Name` field, describe what the snippet does
5. Enter a command or a script in the `Script` field
6. `Save` the snippet<br>

   <div align="left"><figure><img src="/files/6keBja0CQTz33R1Znija" alt="" width="375"><figcaption></figcaption></figure></div>

{% endtab %}
{% endtabs %}

## Run snippets

{% tabs %}
{% tab title="From the terminal side panel" %}
To run a snippet from the terminal side panel:

1. Open the side panel with `Ctrl/Cmd + .`<br>

   <figure><img src="/files/BD0ydGkJNMIJ9wChJnGn" alt=""><figcaption></figcaption></figure>
2. Open the `Snippets` tab <i class="fa-brackets-curly">:brackets-curly:</i><br>

   <figure><img src="/files/WC9EXAmdQNAxS2VcnISl" alt=""><figcaption></figcaption></figure>
3. Hover over the snippet, then click `PASTE` or `RUN`:

   1. **Paste** inserts the snippet into the terminal without running it
   2. **Run** executes the snippet in the active terminal. You can also double-click the snippet

   <div align="left"><figure><img src="/files/crEaXrnBGlv2YpyPJPUp" alt=""><figcaption></figcaption></figure></div>

{% endtab %}

{% tab title="From Autocomplete" %}
When [Autocomplete](/terminal/autocomplete-and-shell-integration.md#enable-autocomplete) is enabled, Termius suggests snippets as you type. It checks both the snippet name and the snippet content.

1. Enable `Autocomplete` in Termius Settings or from the terminal side panel<br>

   <figure><img src="/files/Js3n0vBYGopyGYwlG2ht" alt=""><figcaption></figcaption></figure>
2. Start typing the snippet name in the terminal
3. Select the snippet from the Autocomplete suggestions<br>

   <figure><img src="/files/P9ZZDdT9jYA1EAvMaVO5" alt=""><figcaption></figcaption></figure>
4. Termius inserts the snippet body into the terminal and executes it
   {% endtab %}
   {% endtabs %}

### Execute a snippet on multiple hosts

Snippets can be executed on multiple hosts at the same time. Use this for updates, health checks, and config changes.

You can save a default set of target hosts for a snippet. The next time you run it from the `Snippets` screen, Termius preselects those hosts.

{% tabs %}
{% tab title="Multi-execution from the Snippets screen" %}
Running a snippet from the **Snippets** screen creates new connections to the selected hosts.

To run a snippet in existing sessions instead, use the terminal side panel.

To execute a snippet on multiple hosts from the **Snippets** screen:

1. Open the `Vault` tab, then open the `Snippets` screen<br>

   <figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
2. Double-click the snippet, or click the `pen` icon to edit it
3. Select the target hosts<br>

   <figure><img src="/files/hRVEcfrfigxAaGKoDbOm" alt=""><figcaption></figcaption></figure>
4. Click `Run`
5. Termius creates a workspace with the selected hosts
   1. The connection flow may ask for input if some host credentials are not saved
   2. After the hosts connect, Termius runs the snippet
   3. To stop execution, close a host tab or close the workspace tab

Click `Save targets` to store the selected hosts in the snippet. The next time you run it from the `Snippets` screen, those hosts are preselected.
{% endtab %}

{% tab title="Multi-execution from the Terminal side panel" %}
This feature allows you to run a snippet in all currently active terminals.

To execute a snippet on multiple hosts from the **terminal** **side panel**:

1. Open the side panel with `Ctrl/Cmd + .`<br>

   <figure><img src="/files/BD0ydGkJNMIJ9wChJnGn" alt=""><figcaption></figcaption></figure>
2. Open the `Snippets` tab <i class="fa-brackets-curly">:brackets-curly:</i><br>

   <figure><img src="/files/WC9EXAmdQNAxS2VcnISl" alt=""><figcaption></figcaption></figure>
3. Right-click the snippet you want to run on multiple hosts
4. Click `Run in all tabs` in the context menu<br>

   <figure><img src="/files/UuU7jqRL68GD9VUs6oVt" alt=""><figcaption></figcaption></figure>

{% endtab %}
{% endtabs %}

## Set up startup snippets

A startup snippet is a command that runs automatically every time you connect to a host.

Use it to open a directory, activate a virtual environment, run checks, or attach to an existing tmux session.

**To enable a startup snippet for a host:**

1. Open the `Host Details` screen
2. Scroll down to the `Startup Command` field and choose the snippet<br>

   <figure><img src="/files/Gtkmz1hoEaIIf6JBMlVb" alt=""><figcaption></figcaption></figure>
3. Save the host on mobile. On desktop, Termius saves it automatically

## Organize snippets with packages

Snippets can be organized into **packages**. They work like folders. Create a package for a project, host category, or task type, then move related snippets into it.

### Create a snippet package

{% tabs %}
{% tab title="Desktop" %}
To create a snippet package on the **desktop**:

1. Open the `Vault` tab, then open the `Snippets` screen<br>

   <figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
2. Click the chevron next to `New Snippet`, then click `New snippet package`<br>

   <figure><img src="/files/aCWZsW74Gk0ARjhl7ywm" alt=""><figcaption></figcaption></figure>
3. Enter the package name in the `Label` field. Termius saves the package automatically<br>

   <figure><img src="/files/JPkocOl2GfuK5TwRaPTF" alt=""><figcaption></figcaption></figure>

{% endtab %}

{% tab title="Mobile" %}
To create a snippet package on mobile:

1. Tap the back arrow button `<` to open the **Vaults** screen, then open the `Snippets` screen<br>

   <div align="left"><figure><img src="/files/TZ1pRGG18ka51wufGMeA" alt="" width="375"><figcaption></figcaption></figure></div>
2. Tap the plus button and choose `New snippet package`<br>

   <div align="left"><figure><img src="/files/SNSztv4PXbOUXRVNI93a" alt="" width="375"><figcaption></figcaption></figure></div>
3. Enter the package `Name`<br>

   <div align="left"><figure><img src="/files/7h6al46xy7eiVqJ4YV90" alt="" width="375"><figcaption></figcaption></figure></div>
4. `Save` the snippet package
   {% endtab %}
   {% endtabs %}

### Move snippets into packages

To add a snippet to a package:

* Open the `Edit Snippet` screen and select the package<br>

  <figure><img src="/files/Z2BhhIeUsouq6vbhMC6l" alt=""><figcaption></figcaption></figure>
* Or, on the `Snippets` screen, select several snippets and drag them into a package<br>

  <figure><img src="/files/iz8wsrPe9aLG9eg6EXHt" alt=""><figcaption></figcaption></figure>

## Share snippets within your team

Snippets are stored in vaults and follow the same access model as other vault content. Shared snippets sync automatically and are available to every team member with access to that vault.

**To move snippets between vaults:**

{% stepper %}
{% step %}
Open the `Vault` tab, then open the `Snippets` screen

<figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Right-click the snippet, then choose an action:

* **Copy to:** will create a copy of the selected snippet in the target vault
* **Move to:** will transfer the snippet to the target vault

<figure><img src="/files/rOSodmQMgixGrv6nXCDa" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Select the target vault, then choose where to store credentials

<figure><img src="/files/Jqm0Y5o46QPXDEkCNTYs" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

You can also open the `Edit Snippet` screen and choose the vault there.

<figure><img src="/files/XvxSrb49inX8K1bYOJED" alt=""><figcaption></figcaption></figure>

## Delete snippets

If you no longer need a snippet, you can delete it from the `Snippets` screen or from the side panel in the terminal.

{% hint style="warning" %}
If the snippet is stored in a shared vault, removing it deletes it for everyone with access to that vault.
{% endhint %}

{% tabs %}
{% tab title="From the Snippets screen" %}
To delete a snippet from the Snippets screen:

1. Open the `Vault` tab, then open the `Snippets` screen<br>

   <figure><img src="/files/IOh4sobrBjI7czv1RlFj" alt=""><figcaption></figcaption></figure>
2. Delete the snippet in one of these ways:
   * Right-click the snippet, then click `Remove`, or<br>

     <figure><img src="/files/PE9CN0jpaD2PZTFByjOR" alt=""><figcaption></figcaption></figure>
   * Open the `Edit Snippet` screen, click the three-dots menu, then click `Remove`<br>

     <figure><img src="/files/U1CUxCBLoczlrcQ3XhfH" alt=""><figcaption></figcaption></figure>

{% endtab %}

{% tab title="From the terminal side panel" %}
To delete a snippet from the terminal side panel:

1. Open the side panel with `Ctrl/Cmd + .`<br>

   <figure><img src="/files/BD0ydGkJNMIJ9wChJnGn" alt=""><figcaption></figcaption></figure>
2. Open the `Snippets` tab <i class="fa-brackets-curly">:brackets-curly:</i><br>

   <figure><img src="/files/WC9EXAmdQNAxS2VcnISl" alt=""><figcaption></figcaption></figure>
3. Right-click the snippet, then click `Remove` <br>

   <div align="left"><figure><img src="/files/99r5a7VnFmVZWGpkABr8" alt=""><figcaption></figcaption></figure></div>

{% endtab %}
{% endtabs %}

## Pro tips

**Meaningful names**

Use clear snippet names to make them easier to find with [Autocomplete](/terminal/autocomplete-and-shell-integration.md). Start typing and select the right suggestion.

**Snippet variables**

Termius does not support variables in the snippet editor yet. You can use the `export` command in a startup snippet to define environment variables for other snippets. You can also set environment variables in the `Host Edit` screen.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.termius.com/terminal/snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
