{"id":17220878,"url":"https://github.com/kojix2/chatgpt-cli","last_synced_at":"2025-04-13T22:32:53.531Z","repository":{"id":150239306,"uuid":"611585471","full_name":"kojix2/chatgpt-cli","owner":"kojix2","description":"Yet another ChatGPT command line tool","archived":false,"fork":false,"pushed_at":"2024-04-15T00:18:16.000Z","size":3216,"stargazers_count":24,"open_issues_count":6,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-21T02:15:32.967Z","etag":null,"topics":["chatgpt","cli","command-line","crystal","terminal"],"latest_commit_sha":null,"homepage":"https://kojix2.github.io/chatgpt-cli/","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kojix2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"kojix2"}},"created_at":"2023-03-09T05:54:24.000Z","updated_at":"2024-05-31T01:43:14.804Z","dependencies_parsed_at":null,"dependency_job_id":"d3f7fd7d-01ec-4d1c-8959-e94d1bac5763","html_url":"https://github.com/kojix2/chatgpt-cli","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fchatgpt-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fchatgpt-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fchatgpt-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kojix2%2Fchatgpt-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kojix2","download_url":"https://codeload.github.com/kojix2/chatgpt-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790808,"owners_count":21162092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","cli","command-line","crystal","terminal"],"created_at":"2024-10-15T03:53:30.586Z","updated_at":"2025-04-13T22:32:53.506Z","avatar_url":"https://github.com/kojix2.png","language":"Crystal","funding_links":["https://ko-fi.com/kojix2"],"categories":[],"sub_categories":[],"readme":"# ChatGPT CLI\n\n[![build](https://github.com/kojix2/chatgpt-cli/actions/workflows/build.yml/badge.svg)](https://github.com/kojix2/chatgpt-cli/actions/workflows/build.yml)\n\n:eight_spoked_asterisk: Yet another [ChatGPT](https://openai.com/chatgpt) command line tool.\n\n2025-01-24\n- ChatGPT CLI is not currently being actively developed.\n- I recommend using [aichat](https://github.com/sigoden/aichat).\n- However, I will continue to accept pull requests and issues.\n\n## Features\n\n- Interactive mode using [GNU Readline](https://tiswww.case.edu/php/chet/readline/rltop.html).\n- Support for batch mode and  mustache templates. (experimental)\n- Ready-to-use system messages.\n- Expand file contents from the `%{file/path}`.\n- Magic commands to `%clear`, `%pop`, `%list`, `%w`, `%save`, and `%load` data.\n- Execute system `!{commands}` and pass captured stdout and stderr.\n- Code blocks in the response can be referenced from `$CODE0`, `$CODE1`...\n- Syntax highlighting for code blocks using [`bat`](https://github.com/sharkdp/bat).\n- Output [`%HTML`](https://github.com/hidao80/MonopolyGPT).\n- Support for clipboard.\n\n## Installation\n\n### GitHub Release\n\nDownload binaries from [Github Release](https://github.com/kojix2/chatgpt-cli/releases/latest).\n\n### homebrew\n\n[![chatgpt-cli (macos)](https://github.com/kojix2/homebrew-brew/actions/workflows/chatgpt-cli-macos.yml/badge.svg)](https://github.com/kojix2/homebrew-brew/actions/workflows/chatgpt-cli-macos.yml)\n[![chatgpt-cli (ubuntu)](https://github.com/kojix2/homebrew-brew/actions/workflows/chatgpt-cli-ubuntu.yml/badge.svg)](https://github.com/kojix2/homebrew-brew/actions/workflows/chatgpt-cli-ubuntu.yml)\n\n```sh\nbrew install kojix2/brew/chatgpt-cli\n```\n\n### From source code (recommended)\n\n- [Install Crystal](https://crystal-lang.org/install/)\n- `sudo apt install libreadline-dev`\n- `brew install readline`\n\n```bash\ngit clone https://github.com/kojix2/chatgpt-cli\ncd chatgpt-cli\nsudo make install\n```\n\nPlease deactivate Conda environments when building to ensure correct linking.\n\n### Set your [OpenAI API key](https://platform.openai.com/account/api-keys)\n\n```bash\nexport OPENAI_API_KEY=\"your_openai_api_key\"\n```\n\n### Proxy settings (optional)\n\n```\nexport HTTP_PROXY=http://[IP]:[port]\nexport HTTPS_PROXY=https://[IP]:[port]\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eWindows\u003c/b\u003e\u003c/summary\u003e\n\nSet the environment variable `CHATGPT_CLI_CONFIG`.\n\nThe path to the directory where the configuration file will be saved. This is required on Windows.\n\n\u003c/details\u003e\n\n## Usage\n\n### Interactive mode\n\n```\nchatgpt i\n```\n\n- To exit, type `exit`, `quit`, or press `Ctrl + D`.\n- You can cancel a query to ChatGPT with `Ctrl + C`.\n- GNU Readline supports [Emacs shortcuts](https://en.wikipedia.org/wiki/GNU_Readline), such as `↑` and `↓`.\n- Line breaks are not currently supported.\n\n### Batch mode\n\n```\nchatgpt\n```\n\n```sh\necho \"hello\" | chatgpt\n# How can I assist you today?\n\necho \"It's okay now. Rest.\" | chatgpt -r\n# Thank you for your concern. I hope you have a pleasant day as well. Feel free to reach out if you need any assistance in the future. Take care and rest well!\n```\n\n(under development)\n\n```sh\ncat paper.txt | chatgpt -m \"Please summarize this paper.\"\n```\n\n```sh\nchatgpt -m \"Please summarize this paper.\" paper.txt\n```\n\n```sh\nchatgpt -M gpt-4 -m \"Please write a simple commit message\" \u003c(git diff --cached)\n```\n\n#### Mustache template\n\nRun chatgpt script with the [crustache](https://github.com/makenowjust/crustache) template engine. (experimental)\n\n```\nPlease translate the following text into {{language}}.\n```\n\n```sh\ncat document.txt | chatgpt run -M gpt-4 translate.txt -- --language spanish\n```\n\n### Magic Commands\n\nDuring the dialogue, you can use a variety of magic commands. `%help`\n\n| Magic Command          | Description                                                        |\n| ---------------------- | ------------------------------------------------------------------ |\n| `%list` `%list[n]` `n` | Displays the message(s).                                           |\n| `%clear`               | Clear all messages. Change the topic and set token back to zero.   |\n| `%pop \u003cn\u003e`             | Remove the last n messages and response [1].                       |\n| `%shift \u003cn\u003e`           | Remove first n messages and responses [1].                         |\n| `%copy \u003cn\u003e`            | Save the nth message to the clipboard. [-1]                        |\n| `%write \u003cfilename\u003e`    | Write the most recent message to a file. Save the text or code.    |\n| `%w \u003cfilename\u003e`        | Alias for `write`.                                                 |\n| `%config`              | Edit the config file. Open a text editor and rewrite the settings. |\n| `%system`              | Show the current system message.                                   |\n| `%system \u003cmessage\u003e`    | Set a new system message.                                          |\n| `%edit`                | Edit data in JSON format. You are free to tamper with the past.    |\n| `%html \u003cfilename\u003e`     | Export the conversation to HTML and launch your browser.           |\n| `%save \u003cfilename\u003e`     | Save the data. This allows you to do things like \"save session\".   |\n| `%load \u003cfilename\u003e`     | Load the data. This allows you to do things like \"load session\".   |\n| `%resume`              | Load data from auto-saved data file.                               |\n| `%model \u003cname\u003e`        | Change the model.                                                  |\n| `%tokens`              | Show number of tokens used from the ChatGPT response.              |\n| `%webapp`              | Open the ChatGPT website.                                          |\n| `%debug`               | Show debug message.                                                |\n| `%help`                | Show the help. Humans forget commands.                             |\n\nNote that for `%config`, `%data`, and other commands launch an editor. The editor used can be set by the `EDITOR` environment variable.\n\n### System Commands\n\nExecute the system command.\n\n```\n!pwd\n```\n\nExecute the system command and capture `%STDOUT` and `%STDERR`.\n\n```\n!!git diff --cached\n```\n\n### Embed files\n\n```\nImprove the code: %{my/script.py}\n```\n\n```\nFind the bugs: %{src/*.py}\n```\n\n### Embed Standard Output\n\n`!{command}` Execute the command and insert standard output and standard error output.\n\n```\nPlease write a commit message: !{git diff}\n```\n\n`%STDOUT` - captured standard output of `!!{command}`\n\n```\nPlease write a commit message: %STDOUT\n```\n\n`%STDERR` - captured standard error output of `!!{command}`\n\n```\nExplain this error message: %STDERR\n```\n\n### Extract code blocks\n\n#### Syntax highlighting\n\nThe [`bat`](https://github.com/sharkdp/bat) command is required. You can use the development version by setting the following environment variables and compiling.\n\n- `CHATGPT_BAT=1 shards build` Only code blocks are targeted for syntax highlighting.\n- `CHATGPT_BAT=2 shards build` The entire response is considered markdown and subject to syntax highlighting.\n\n#### Code block temporary file path `$CODE0` `$CODE1`\n\n- Code blocks are extracted and stored in temporary files\n- `$CODE0`, `$CODE1`, ... are path to the temporary files.\n\n```\nWrite code to display 1 to 10 in Python and Ruby.\n```\n\n````md\nPython:\n\n```python\nfor i in range(1, 11):\n    print(i)\n```\n\nRuby:\n\n```ruby\n(1..10).each { |i| puts i }\n```\n````\n\n```\n! python $CODE0\n! ruby $CODE1\n```\n\nSave the code block to a file. (There is obvious room for improvement here)\n\n```\n!cp $CODE0 src/client.cr\n```\n\n## Configuration\n\nRun `chatgpt config` to get the path to the configuration file.\n\n`config.json` is located in `~/.config/chatgpt-cli/` by default.\n\n- `embedded_patterns`: Defines patterns for `%{}`, `!{}`, `%STDOUT` and `%STDERR`\n- `extraction pattern`: Defines patterns for code block extraction.\n- `terminal_colors`: Set colors for `chatgpt`, `warning`, `debug`, `stdout` and `stderr`.\n\nTo edit, run `chatgpt config --edit`. Or use `%config` in interactive mode.\nTo reset, run `chatgpt config --reset`.\n\n[config.json](config.json)\n\n## Uninstallation\n\nChatGPT CLI uses the following 3 files and directories. This is all there is to it.\n\n```sh\nrm /usr/local/bin/chatgpt   # Remove the executable\nrm -r ~/.config/chatgpt-cli # Remove the config directory\nrm ~/.chatgpt_history       # Remove command history\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [https://github.com/kojix2/chatgpt-cli](https://github.com/kojix2/chatgpt-cli).\n\n## Development\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eOverview\u003c/b\u003e\u003c/summary\u003e\n\n![overview](https://raw.githubusercontent.com/kojix2/chatgpt-cli/main/docs/overview.png)\n\n\u003c/details\u003e\n\n```\ncrystal spec\n```\n\n- You can quickly try development by using [Gitpod](https://www.gitpod.io/).\n\n## Acknowledgements\n\nThis tool has been greatly influenced, both directly and indirectly, by the creative work of the following individuals.\n\n- @mamantoha - [http_proxy](https://github.com/mamantoha/http_proxy)\n- @hkalexling - [Mango/src/util/proxy.cr](https://github.com/getmango/Mango/blob/master/src/util/proxy.cr)\n- @hidao80 - [MonopolyGPT](https://github.com/hidao80/MonopolyGPT)\n- @lancecarlson - [clipboard_manager.cr](https://github.com/lancecarlson/chatcopy)\n- @makenowjust - [crustache](https://github.com/makenowjust/crustache)\n- @Flipez - [spinner](https://github.com/Flipez/spinner)\n\n## License\n\nThis project is open source and available under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fchatgpt-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkojix2%2Fchatgpt-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkojix2%2Fchatgpt-cli/lists"}