This is a command line client for using ChatGPT. You can easily ask questions (responses are streamed in real time), tweak system prompt (or other params), include local files, pipe the response and ask follow up questions.
chatgpt-cli.demo.mov
go install github.com/edofic/chatgpt-cli@latest
It uses the API so you need to provide your own token via OPENAI_API_KEY environment variable.
export OPENAI_API_KEY=your_api_keyWithout any params the arguments (plural, you can omit the quotes) are taken to be your message
$ chatgpt-cli 'what is the capital of france?' /tmp
The capital of France is Paris.Note responses are streamed as they are generated (just as on the web UI) which gives you something almost immediately even for longer responses.
Pass - as the message to read the prompt from stdin. Useful for piping in content.
$ cat notes.txt | chatgpt-cli -Two flags let you tune the model output:
-maxTokenssets the maximum number of tokens to generate (default500)-temperaturesets the sampling temperature (default0)
$ chatgpt-cli -maxTokens 2000 -temperature 0.7 'write a short poem about Go'If you invoke the CLI without a message, it drops into an interactive REPL. Type a message and press Enter to send; the response streams back and the session stays open for follow-ups. Press Ctrl-D (or Ctrl-C) to exit.
$ chatgpt-cli
> what is the capital of france?
The capital of France is Paris.
> and germany?
The capital of Germany is Berlin.
>Flags like -c, -systemMsg, and -includeFile work the same way in interactive mode. Each exchange is saved to the session file, so you can resume later with -c.
You can pass -c to continue last session and ask follow up questions.
$ chatgpt-cli -c 'what about germany?'
The capital of Germany is Berlin.Session is stored in /tmp/chatgpt-cli-last-session.json - there is only one "last session".
You can configure the system prompt and tweak behavior this way
$ chatgpt-cli -systemMsg 'You are an assistant that speaks like Shakespeare.' 'what is the capital of france?'
The fair capital of France is known as Paris, my would-be lord.You can pass in local files as additional messages
$ chatgpt-cli -includeFile main.go 'what is this in one sentence?'
This is a Go programming language script that uses the OpenAI API to provide a command-line interface for interacting with the ChatGPT AI model to generate chat messages.Or you can store the output
chatgpt-cli 'write a dockerfile for a Go program, omit any explanation' | tee Dockerfile
FROM golang:latest
WORKDIR /app
COPY . .
RUN go build -o myApp .
CMD ["./myApp"]Currently this tool defaults to gpt-5.4-mini.
You can alternatively use any other available model by specifying the model
name in an environment variable
export OPENAI_MODEL=gpt-4oTo point at any OpenAI-compatible API (e.g. a local LLM server or a proxy), set OPENAI_ENDPOINT:
export OPENAI_ENDPOINT='http://localhost:8080/v1'To use Azure hosted models specify two more environment variables on top of your API key
OPENAI_AZURE_ENDPOINT='https://<your subdomain>.openai.azure.com/'
OPENAI_AZURE_MODEL='<your model deployment name>'| Flag | Default | Description |
|---|---|---|
-maxTokens |
500 |
Maximum number of tokens to generate |
-temperature |
0 |
Sampling temperature |
-systemMsg |
"" |
System message to include with the prompt |
-includeFile |
"" |
File to include as an additional user message |
-c |
false |
Continue last session |
| Variable | Description |
|---|---|
OPENAI_API_KEY |
API key (required) |
OPENAI_MODEL |
Override the default model (gpt-5.4-mini) |
OPENAI_ENDPOINT |
Base URL for an OpenAI-compatible API |
OPENAI_AZURE_ENDPOINT |
Azure OpenAI endpoint URL |
OPENAI_AZURE_MODEL |
Azure deployment name |