https://github.com/codecaine-zz/ollama_console_markdown_display
Ollama Console Markdown Display
https://github.com/codecaine-zz/ollama_console_markdown_display
ai ai-tools bun clipboard copy javascript macos markdown ollama typescript
Last synced: 3 days ago
JSON representation
Ollama Console Markdown Display
- Host: GitHub
- URL: https://github.com/codecaine-zz/ollama_console_markdown_display
- Owner: codecaine-zz
- Created: 2026-04-13T00:10:57.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-13T02:10:48.000Z (2 months ago)
- Last Synced: 2026-04-13T02:24:31.272Z (2 months ago)
- Topics: ai, ai-tools, bun, clipboard, copy, javascript, macos, markdown, ollama, typescript
- Language: TypeScript
- Homepage:
- Size: 169 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ollama Console Markdown Display
Chat with Ollama models in your terminal with beautifully rendered markdown output and clipboard-copyable code blocks. Powered by Bun v1.3.12's `Bun.markdown.ansi()` API.
## Demo

## Requirements
- macOS (ARM or Intel)
- [Bun](https://bun.sh) v1.3.12+
- [Ollama](https://ollama.ai) installed (started automatically if not running)
## Usage
### One-liner mode
```bash
# Basic question
bun run index.ts "explain closures in JavaScript"
# Specify a model
bun run index.ts -m qwen3.5:4b "write fizzbuzz in python"
# Save response to a file
bun run index.ts -o response.md "create a REST API in Node.js"
# Enable thinking/reasoning mode
bun run index.ts -t "why is the sky blue"
# Combine flags: custom model + thinking + save output
bun run index.ts -m qwen3.5:27b -t -o answer.md "explain monads"
```
### Interactive chat mode
```bash
# Start chat with default model
bun run index.ts
# Start chat with a specific model
bun run index.ts -m qwen3.5:27b
# Start chat with thinking mode enabled
bun run index.ts -t
# Start chat with auto-save to file
bun run index.ts -o session.md
# Combine: specific model + thinking + output
bun run index.ts -m qwen3.5:4b -t -o log.md
```
### Read a markdown file
```bash
# Auto-detect .md file
bun run index.ts README.md
# Explicit flag
bun run index.ts -r notes.md
```
### Show help
```bash
bun run index.ts -h
```
### Options
| Flag | Description |
| --------------------- | ---------------------------------------- |
| `-m, --model ` | Model to use (default: `qwen3.5:latest`) |
| `-o, --output ` | Save response markdown to a file |
| `-r, --read ` | Render a markdown file in the terminal |
| `-t, --think` | Enable thinking/reasoning mode |
| `-h, --help` | Show help |
### Chat commands
| Command | Action |
| --------------- | --------------------------------- |
| `` | Copy code block #n to clipboard |
| `all` | Copy all code blocks to clipboard |
| `save ` | Save last response to a file |
| `model ` | Switch to a different model |
| `models` | List available Ollama models |
| `think` | Toggle thinking mode on/off |
| `think on/off` | Set thinking mode explicitly |
| `exit` / `quit` | End the chat |
After each response with code blocks, a copy prompt appears where you can type a block number, `all`, or press enter to continue chatting.
## Install as a global command
Bun's `--compile` flag produces unsigned ARM64 binaries that macOS kills on Apple Silicon. Use a shell wrapper instead:
```bash
# Make the wrapper script executable and link it into your PATH
chmod +x ollama-chat.sh
sudo ln -sf "$(pwd)/ollama-chat.sh" /usr/local/bin/ollama-chat
```
Now you can use it from anywhere:
```bash
ollama-chat "explain closures in JavaScript"
ollama-chat -m qwen3.5:27b -t "why is the sky blue"
ollama-chat README.md
```
## Features
- **Streaming** — tokens appear in real-time, then get replaced with formatted markdown
- **Rendered markdown** — headings, lists, bold, italic, code blocks with language labels
- **Read .md files** — render any markdown file in the terminal with syntax coloring
- **Code block clipboard** — numbered code blocks with `copy ` to pbcopy
- **Save output** — save responses to markdown files with `-o` flag or `save` command
- **Model switching** — switch models mid-chat with `model `, list with `models`
- **Thinking mode** — enable chain-of-thought reasoning with `-t` flag or `think` command
- **Conversation memory** — chat mode maintains full message history
- **Automatic Ollama startup** — detects if Ollama is running and starts it automatically if needed
## Automatic Ollama Startup
The main function includes an enhanced Ollama startup process that handles server availability automatically:
1. **Detection** — on launch, the app checks if Ollama is already running by pinging `http://localhost:11434/api/tags`
2. **Auto-start** — if Ollama is not running, it spawns `ollama serve` in the background and waits up to 15 seconds for it to become ready
3. **Error handling** — if Ollama fails to start (e.g. not installed), an error message is displayed with a link to the installation page at https://ollama.ai
4. **Graceful cleanup** — signal handlers (`SIGINT`, `SIGTERM`, `exit`) ensure the spawned Ollama process is stopped when the app exits
No manual server management is required — just run the app and it takes care of the rest.
## Note on compiled binaries
Bun's `--compile` flag currently produces unsigned ARM64 binaries that macOS kills on Apple Silicon. Use the shell wrapper install method above instead.