iddo 6f2ea80060
Fix race between stopping and starting the receive thread (#2142)
* Fix race between stopping and starting the receive thread

When the last receive handler was removed, receiveThread was cleared
before the thread had stopped. A handler added in that window, e.g. by
a client reconnecting to the daemon in on-connection receive mode,
started a second receive thread. While the stop request for the old
thread was still set, each new thread ended immediately and started the
next one. When the old thread ended, it cleared the reference to the
newer thread and started yet another one, leaving two receive loops on
the same websocket. The unreferenced loop was never stopped and kept
receiving and acknowledging messages after all clients had gone.

Keep receiveThread set until the receive thread has finished and only
let the thread itself clear it. Its end block already starts a new
receive thread if handlers were added in the meantime. Clear a stop
request right before a new receive loop is started instead of when a
loop ends, so it can neither be cleared by another loop nor stop a
later one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add test for adding a receive handler while the receive thread stops

The receive loop is replaced by a fake one that can be held while it
stops, so the test doesn't connect to the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: iddo <917594+iddo@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 16:28:42 +02:00
2024-09-08 09:00:39 +02:00
2026-10-07 12:46:24 +02:00
2026-10-07 12:46:24 +02:00
2026-04-01 22:47:54 +02:00
2026-10-07 12:46:24 +02:00
2026-10-07 12:46:24 +02:00
2026-10-07 12:46:52 +02:00
2026-10-07 12:46:52 +02:00
2026-01-24 15:38:02 +01:00
2026-03-21 22:04:48 +01:00
2022-07-30 16:59:08 +02:00
2026-07-11 12:58:35 +02:00
2026-09-28 18:52:35 +02:00
2026-10-07 12:46:24 +02:00
2015-05-11 12:55:26 +02:00
2026-01-24 12:36:29 +01:00

signal-cli

signal-cli is a commandline interface for the Signal messenger. It supports registering, verifying, sending and receiving messages. signal-cli uses a patched libsignal-service-java, extracted from the Signal-Android source code. For registering you need a phone number where you can receive SMS or incoming calls. Existing accounts without a phone number can be linked from a compatible Signal mobile app.

signal-cli is primarily intended to be used on servers to notify admins of important events. For this use-case, it has a daemon mode with JSON-RPC interface (man page) and D-BUS interface (man page). For the JSON-RPC interface there's also a simple example client, written in Rust.

signal-cli needs to be kept up-to-date to keep up with Signal-Server changes. The official Signal clients expire after three months and then the Signal-Server can make incompatible changes. So signal-cli releases older than three months may not work correctly.

Installation

You can build signal-cli yourself or use the provided binary files, which should work on Linux, macOS and Windows. There's also a docker image and some Linux packages provided by the community.

System requirements:

  • at least Java Runtime Environment (JRE) 25

  • native library: libsignal-client

    The native libs are bundled for x86_64 Linux (with recent enough glibc), Windows and MacOS. For other systems/architectures see: Provide native lib for libsignal

Install system-wide on Linux [ JVM build ]

See latest version.

VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/AsamK/signal-cli/releases/latest | sed -e 's/^.*\/v//')
curl -L -O https://github.com/AsamK/signal-cli/releases/download/v"${VERSION}"/signal-cli-"${VERSION}".tar.gz
sudo tar xf signal-cli-"${VERSION}".tar.gz -C /opt
sudo ln -sf /opt/signal-cli-"${VERSION}"/bin/signal-cli /usr/local/bin/

Install system-wide on Linux [ GraalVM native build ]

VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/AsamK/signal-cli/releases/latest | sed -e 's/^.*\/v//')
curl -L -O https://github.com/AsamK/signal-cli/releases/download/v"${VERSION}"/signal-cli-"${VERSION}"-Linux-native.tar.gz
sudo tar xf signal-cli-"${VERSION}"-Linux-native.tar.gz -C /opt
sudo ln -sf /opt/signal-cli /usr/local/bin/

You can find further instructions on the Wiki:

Usage

For a complete usage overview please read the man page and the wiki.

For a numbered account, ACCOUNT is your phone number in international format and must include the country calling code. Hence it should start with a "+" sign. (See Wikipedia for a list of all country codes.) For a linked account without a phone number, use its ACI (Account ID) instead. See the wiki for further documentation.

  • Link to an existing account

    If you have an existing Signal account, with or without a phone number, you can link signal-cli to it with:

    signal-cli link
    
  • Register a number (with SMS verification)

    Alternatively, if you don't have an existing Signal account, you can register one from signal-cli. Note that this will unregister any existing client associated with the same number.

    signal-cli -a ACCOUNT register
    

    You can register Signal using a landline number. In this case, you need to follow the procedure below:

    • Attempt a SMS verification process first (signal-cli -a ACCOUNT register)

      • You will get an error 400 (InvalidTransportModeException), this is normal
    • Wait 60 seconds

    • Attempt a voice call verification by adding the --voice switch and wait for the call:

      signal-cli -a ACCOUNT register --voice
      

    Registering may require solving a CAPTCHA challenge: Registration with captcha

  • Verify the number using the code received via SMS or voice, optionally add --pin PIN_CODE if you've added a pin code to your account

    signal-cli -a ACCOUNT verify CODE
    
  • Send a message

    signal-cli -a ACCOUNT send -m "This is a message" RECIPIENT
    
  • Send a message to a username, usernames need to be prefixed with u:

    signal-cli -a ACCOUNT send -m "This is a message" u:USERNAME.000
    
  • Pipe the message content from another process.

    uname -a | signal-cli -a ACCOUNT send --message-from-stdin RECIPIENT
    
  • Receive messages

    signal-cli -a ACCOUNT receive
    

Hint: The Signal protocol expects that incoming messages are regularly received (using daemon or receive command). This is required for the encryption to work efficiently and for getting updates to groups, expiration timer and other features.

Storage

The password and cryptographic keys are created when registering and stored in the current users home directory:

$XDG_DATA_HOME/signal-cli/data/
$HOME/.local/share/signal-cli/data/

Building

This project uses Gradle for building and maintaining dependencies. If you have a recent gradle version installed, you can replace ./gradlew with gradle in the following steps.

  1. Checkout the source somewhere on your filesystem with

    git clone https://github.com/AsamK/signal-cli.git
    
  2. Execute Gradle:

    ./gradlew build
    

    2a. Create shell wrapper in build/install/signal-cli/bin:

    ./gradlew installDist
    

    2b. Create tar file in build/distributions:

    ./gradlew distTar
    

    2c. Create a fat tar file in build/libs/signal-cli-fat:

    ./gradlew fatJar
    

    2d. Compile and run signal-cli:

    ./gradlew run --args="--help"
    

JSON Schemas for the JSON-RPC mode

  1. Generate JSON Schema files for all the JSON-RPC data classes (src/main/java/org/asamk/signal/json):

    ./gradlew jsonSchemas
    
  2. The generated files can be found in the build/generated/META-INF/schemas folder.

Building a native binary with GraalVM (EXPERIMENTAL)

It is possible to build a native binary with GraalVM. This is still experimental and will not work in all situations.

  1. Install GraalVM and setup the environment

  2. Execute Gradle:

    ./gradlew nativeCompile
    

    The binary is available at build/native/nativeCompile/signal-cli

FAQ and Troubleshooting

For frequently asked questions and issues have a look at the wiki.

License

This project uses libsignal-service-java from Open Whisper Systems:

https://github.com/WhisperSystems/libsignal-service-java

Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html

Description
signal-cli provides an unofficial commandline, JSON-RPC and dbus interface for the Signal messenger.
Readme GPL-3.0
Languages
Java 96.6%
Rust 2.5%
Shell 0.8%
Kotlin 0.1%