{"slug": "show-hn-q-a-repl-for-llm-inside-the-terminal", "title": "Show HN: Q a REPL for LLM inside the terminal", "summary": "A developer released q, a proof-of-concept C CLI that integrates an LLM into the terminal as a REPL, allowing users to execute shell commands and ask questions without leaving the command line. The tool streams responses from a local OpenAI-compatible API and supports features like numbered command execution and session recording. It is available on GitHub under the MIT license.", "body_md": "A proof of concept of interleaving the terminal/shell with the LLM. so you can do day to day shell commands and if stuck or want more clarification, in the same prompt the users post their question to the LLM, and get answers there, thus no need to hop to the browser. kind of nearby senior who can help clarify or provide examples for what you are trying to do. Examples (after launching it in repl mode with q --repl )\n\n$ q --repl --color\n\n``` bash\n1 $ show the last 100 nginx service logs without paging\nbash\n2 $ restart nginx and verify it is listening on ports 80 and 443\nbash\n3 $ list failed systemd units and show commands to inspect each failure\nbash\n4 $ show disk usage by top-level directories under /var\nbash\n5 $ find files larger than 1G under /home modified in the last 7 days\nbash\n6 $ check apt package holds and pending security upgrades\nbash\n7 $ create a systemd timer that runs /usr/local/bin/backup.sh daily at 02:30\nbash\n8 $ write an rsync command to mirror /srv/data to backup@example:/backups/data preserving permissions and deleting removed files\n9 $ ? top processes by memory with ps, sorted descending\n```\n\nand many others like:\n\n```\nshow ufw commands to allow ssh, http, and https then enable the firewall\ndiagnose DNS resolution problems using resolvectl, dig, and systemd-resolved logs\nshow commands to list users with sudo access\ngenerate a logrotate config for /var/log/myapp/*.log keeping 14 compressed daily logs\ncheck memory pressure and swap usage from the command line\nshow commands to inspect SMART health for /dev/sda\n```\n\nHope you got the drift. It is rough and rather large with ~7k of vibed code, and I had been using it as a daily driver.\n\nNote that the output of queries will depend on the LLM used.\n\nSometimes q will be confused with a query for a command (i.e. who or which), usually this can be workaround by Capitalizing the first word of a query.\n\nStill you can use ! to force a shell execution or ? to force a query.\n\nIf an LLM was asked for a shell/bash/zsh examples and these were fenced, then these are detected and are numbered from 1 to the last one. you can then type the number followed by dot (i.e. 2.) which will execute it without typing it.\n\nfor help use slash command /help which will show other commands.\n\nIn summary q is a small vibed (using codex) C CLI named `q`\n\nthat sends all command-line arguments as one `input1`\n\nstring to a local OpenAI-compatible Responses API using a Linux sysadmin system prompt. Responses are streamed to stdout as they arrive.\n\nNote that again, this is a proof of concept rather than finished work, and waiting until it is ready will take forever, thus opting to publish the code so other smarter people can have fun and run with it.\n\nBelow is the start of LLM generated content\n\n```\nmake\n```\n\nFor a stripped release binary:\n\n```\nmake release\n```\n\nInstall to `/usr/local/bin`\n\nby default:\n\n```\nsudo make install\n```\n\nRequires libcurl development headers:\n\n```\nsudo apt install build-essential libcurl4-openssl-dev\n```\n\nColors can be overridden at compile time with C macros such as `Q_COLOR_LLM_TEXT`\n\n, `Q_COLOR_CODE_EMULATOR`\n\n, `Q_COLOR_CODE_TTY`\n\n, `Q_COLOR_PROMPT_LINE_NO`\n\n, `Q_COLOR_EXIT_OK`\n\n, `Q_COLOR_EXIT_FAIL`\n\n, `Q_COLOR_MENU_SELECTED`\n\n, `Q_COLOR_TOOL_CONFIRM`\n\n, and `Q_COLOR_RESET`\n\n.\n\nUsage:\n\n```\n./q [--repl] [--keep-context] [--record-session] [--resume-session [id|last]] [--list-sessions] [--add-mcp-server url] [--remove-mcp-server name] [--list-mcp-servers] [--llm-timeout seconds] [--llm-turn-limit count] [--api-logging none|query|response|both|path] [--system-prompt-file filepath] [--think-loud] [--color] [query words...]\nexport OPENAI_API_KEY='your_api_key'\n./q --repl\n```\n\nFor local OpenAI-compatible servers that do not require auth, leave `OPENAI_API_KEY`\n\nunset.\n\nIf `LLM_SERVER`\n\nis unset or empty, `q`\n\nuses `127.0.0.1`\n\n.\nIf `LLM_PORT`\n\nis unset or empty, `q`\n\nuses `8080`\n\n.\nThe default endpoint is `http://127.0.0.1:8080/v1/responses`\n\n.\n\nAlso One-shot mode is also available when you do not want to enter the REPL:\n\n```\n./q find which process is using port 8080\nLLM_SERVER=127.0.0.1:8000 ./q check nginx logs last 50 lines\nLLM_SERVER=http://127.0.0.1:8000/v1/responses ./q check nginx logs last 50 lines\nLLM_PORT=1234 ./q check nginx logs last 50 lines\n```\n\nHTTP MCP servers:\n\n```\n./q --add-mcp-server http://127.0.0.1:3000/mcp\n./q --list-mcp-servers\n./q --remove-mcp-server name\n```\n\nRegistered HTTP MCP servers are stored in `~/.config/q/mcp-servers.tsv`\n\n. `--add-mcp-server`\n\nreads the server name from the MCP `initialize`\n\nresponse. At startup, `q`\n\nprobes registered servers with `initialize`\n\nand `tools/list`\n\n; live tools are appended to the builtin `get_time`\n\n, `read_file`\n\n, and `write_file`\n\ntools sent to the model.\n\nLimit LLM/tool follow-up turns:\n\n```\n./q --llm-turn-limit 4 check something\n```\n\nAPI logging:\n\n```\n./q --api-logging query find which process is using port 8080\n```\n\nModes are `none`\n\n, `query`\n\n, `response`\n\n, `both`\n\n, or an appendable file path. Default: `none`\n\n.\n\nBy default, streamed reasoning/thinking output is hidden and shown as animated dots on stderr. To show it:\n\n```\n./q --repl --think-loud\n```\n\nREPL slash commands include `/help`\n\n, `/keys`\n\n, `/show-system-prompt`\n\n, `/set-system-prompt path`\n\n, `/llm-timeout seconds`\n\n, `/llm-turn-limit count`\n\n, `/think-loud on|off`\n\n, `/api-logging none|query|response|both|path`\n\n, `/add-mcp-server url`\n\n, `/remove-mcp-server name`\n\n, `/list-mcp-servers`\n\n, `/truncate-context`\n\n, `/clear-completion-cache`\n\n, `/note text`\n\n, and `/exit`\n\n.\n\nOn startup, `q`\n\nchecks that the configured local LLM server is reachable before entering query or REPL mode.\n\nWith `--keep-context`\n\n, each new LLM request includes previous user/assistant turns from the current `q`\n\nrun. Without it, each request sends only the current input.\n\nSession files:\n\n```\n./q --record-session --repl\n./q --list-sessions\n./q --resume-session 1 --repl\n./q --resume-session --repl\n```\n\nRecorded sessions are stored in `~/.config/q/sessions/session-<timestamp>`\n\n. `--list-sessions`\n\nprints a numeric ID; use that number with `--resume-session N`\n\n, resume by timestamp/session id, or use `--resume-session last`\n\n. If no id is supplied to `--resume-session`\n\n, `last`\n\nis used. Recording/resuming a session does not automatically enable context; add `--keep-context`\n\nwhen you want prior turns sent to the LLM.\n\nInteractive REPL prompts look like `1 $ `\n\n, `2 $ `\n\n, etc. There are 8 spaces after `$`\n\n. With `--color`\n\n, the line number is dark red, exit code `0`\n\nis green, and nonzero exit codes are red.\n\nInteractive REPL line editing:\n\n```\nC-p  previous history item\nC-n  next history item\nC-a  beginning of line\nC-e  end of line\nC-k  delete to end of line\nC-w  delete previous word\nC-d  delete character at cursor\nDel  delete character at cursor\nC-f  forward character\nC-b  backward character\nC-l  clear screen\nHome beginning of line\nEnd  end of line\nTab  show completion suggestions\n```\n\nLong input lines redraw across wrapped terminal rows without duplicating the line.\n\nTab behavior:\n\n```\nAfter at least one typed character: complete slash commands, aliases, environment variables, directories, executable `./` files, or command arguments depending on cursor position.\nOn a token starting with - or --: infer the command before the option, read its man page, and ask the LLM to summarize relevant options below the input. If there is no manual entry, use the command's `--help` output instead.\n```\n\nCommand option summaries are cached globally in `~/.config/q-completions/`\n\n. Later `q`\n\ninstances reuse the cached summary and filter it by the current `-`\n\nor `--`\n\nprefix instead of asking the LLM again.\n\nTyping more text, including a space, redraws the input and clears the suggestion area.\n\nREPL escapes:\n\n```\n? which command shows open ports\n! which bash\n```\n\n`?`\n\nforces the line to the LLM. `!`\n\nforces the line to the shell. `/exit`\n\nexits the REPL. `/clear-completion-cache`\n\nremoves cached command option completions.\n\nAfter a shell command runs, `q`\n\ncaptures the command, combined stdout/stderr output, and exit code. Enter `??`\n\nto ask the LLM:\n\n```\nthe following command failed: 'the command', with output of 'the output', and exit code 'the exit code', what is the problem, or solution?\n```\n\nWhen an LLM reply contains fenced `bash`\n\n, `sh`\n\n, `shell`\n\n, or `zsh`\n\ncode blocks, REPL mode lists them as executable blocks:\n\n```\n1.\n``` bash\npwd\nType the number with a dot to execute it:\n\n```\n1.\n```\n\n`q`\n\nprints the selected command text, then a blank line, before executing it.\n\nOptional model override:\n\n```\nOPENAI_MODEL=gpt-5.5 ./q check nginx logs last 50 lines\n```\n\n", "url": "https://wpnews.pro/news/show-hn-q-a-repl-for-llm-inside-the-terminal", "canonical_source": "https://github.com/alaa-alawi/q", "published_at": "2026-07-07 19:37:50+00:00", "updated_at": "2026-07-07 20:01:03.140907+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-tools"], "entities": ["OpenAI", "GitHub", "q", "LLM", "REPL", "CLI", "libcurl", "systemd"], "alternates": {"html": "https://wpnews.pro/news/show-hn-q-a-repl-for-llm-inside-the-terminal", "markdown": "https://wpnews.pro/news/show-hn-q-a-repl-for-llm-inside-the-terminal.md", "text": "https://wpnews.pro/news/show-hn-q-a-repl-for-llm-inside-the-terminal.txt", "jsonld": "https://wpnews.pro/news/show-hn-q-a-repl-for-llm-inside-the-terminal.jsonld"}}