Title: Resuming ChatGPT chats in CLI
Author: Alex Kirk
Published: September 25, 2023
Last modified: October 26, 2023

---

# Resuming ChatGPT chats in CLI

September 25, 2023

I have issued an update to my [CLI ChatGPT Client](https://github.com/akirk/cli-chatgpt)(
see [when I first announced it](https://alex.kirk.at/2023/05/24/cli-chatgpt-client-in-php/))
so that you can now resume conversations. Here is the new `--help` output (I personally
have an `alias cgt=path/to/chat.php` to have it quickly available):

    ```wp-block-code
    Usage: chat.php [-l] [-r [number]] [-s system_prompt] [conversation_input]

    Options:
      -l                 Resume last conversation.
      -r [number]        Resume a previous conversation and list 'number' conversations (default: 10).
      -s [system_prompt] Specify a system prompt preceeding the conversation.

    Arguments:
      conversation_input  Input for the first conversation.

    Notes:
      - To input multiline messages, send an empty message.
      - To end the conversation, enter "bye".

    Example usage:
      chat.php -l
        Resumes the last conversation.

      chat.php -r 5
        Resume a conversation and list the last 5 to choose from.

      chat.php -s "Only respond in emojis"
        Have an interesting conversation 🙂

      chat.php Tell me a joke
        Starts a new conversation with the given message.
    ```

The CLI client uses a streaming response, so you can watch as it generates your 
answer.

The resuming functionaliy also changed re-arranges the history in the chat cli folder
to a structure `chats/%Y/%M/history.%U.txt` (with `%Y` being a 4-digit year, `%M`
a two-digit month and `%U` the unix timestamp when it was started). The prompt is
readline compatibly with a history file so that you can quickly reuse previous questions.
You can avoid something to be added to history by prepending it with whitespace.

`chat.php -l` will quickly resume the last conversation but you can also resume 
other ones:

    ```wp-block-code
    $ cgt -r 3                                                                                                                                                     Resuming a conversation. Please choose one: 

    1) is there an alternative to the logwatch program that can send daily e-mails with reports on log file (1 answer, 248 words)

    2) please give me javascript that restarts a video when i click on it (2 answers, 237 words)

    3) does a one-letter domain like w.org (specifically) cost more than other .org domains? (3 answers, 253 words)

    Please enter the number of the conversation you want to resume (m for more):
    ```

To me, it is very powerful to have ChatGPT available in the CLI since I always have
a terminal open. Keeping searchable local history is also something that I like 
for later (offline) reference.

[AI](https://alex.kirk.at/category/ai/), [Explorations](https://alex.kirk.at/category/explorations/)

[ChatGPT](https://alex.kirk.at/tag/chatgpt/), [LLMs](https://alex.kirk.at/tag/llms/)

Read this next

[Previous Post](https://alex.kirk.at/2023/09/22/1882165/)

## One response to “Resuming ChatGPT chats in CLI”

 1. ![anonymous Avatar](https://secure.gravatar.com/avatar/?s=48&d=mm&r=g)
 2. [anonymous](https://alex.kirk.at/2023/10/20/chat-cli-renamed-and-added-ollama-support/)
 3. [October 20, 2023](https://alex.kirk.at/2023/09/25/resuming-chatgpt-chats-in-cli/comment-page-1/#comment-84661)
 4. I have added support for Ollama to my chat-cli tool (formerly named cli-chatgpt,
    see previous posts). Ollama is a very easy way to run llama2…
 5. [Log in to Reply](https://alex.kirk.at/wp-login.php?redirect_to=https%3A%2F%2Falex.kirk.at%2F2023%2F09%2F25%2Fresuming-chatgpt-chats-in-cli%2F)

### Leave a Reply 󠀁[Cancel reply](https://alex.kirk.at/2023/09/25/resuming-chatgpt-chats-in-cli/comment-page-1/?output_format=md#respond)󠁿

Only people in [my network](https://alex.kirk.at/friends/) can comment.

This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/)