Collaborate with LLMs directly in your terminal.
Ask, edit, summarize, and generate content inline in Markdown.
- 📝 Ask questions and insert AI answers directly into
.mdfiles. - ✍️ Edit sections with AI-powered rewrites (simplify, clarify, shorten, etc.).
- 📚 Summarize long notes or papers into concise takeaways.
- 📄 Generate blog posts and documentation in Markdown.
- 💬 Interactive chat mode with an LLM inside your terminal.
All AI-generated content is wrapped in <!-- AI: ... --> blocks, so you always know what’s machine-written.
# install globally
npm install -g mdchat
# or run once via npx
npx mdchat --helpRequirements: Node.js 20+
# 1) 30‑second interactive setup
mdchat config setup
# 2) Ask your first question
mdchat ask "What is machine learning?"# Ask a question (streaming by default for better UX)
mdchat ask "What is the capital of France?"
# Disable streaming if you prefer to see the complete response at once
mdchat ask "Explain quantum computing" --no-stream
# Save the answer to a file
mdchat ask "How does photosynthesis work?" -o biology.md# Insert AI-generated content into marked blocks based on surrounding context
mdchat insert document.md
# Preview what will be generated without making changes
mdchat insert document.md --preview
# Save to a different file instead of modifying the original
mdchat insert document.md -o enhanced-document.mdTo use the insert command, add HTML comment markers in your markdown file:
# My Document
Existing paragraph about topic A.
<!-- AI insert here -->
<!-- AI insert end -->
Existing paragraph about topic B.The AI will analyze the surrounding context and generate connecting content that flows naturally between the paragraphs.
# Summarize a single file
mdchat summarize document.md
# Summarize multiple files with glob patterns
mdchat summarize "docs/*.md"
# Summarize an entire directory
mdchat summarize ./research/
# Save summary to a file
mdchat summarize notes.md -o summary.md# Simplify a section
mdchat edit document.md --section "Complex Topic" --action simplify
# Expand on a topic
mdchat edit article.md --section "Introduction" --action expand
# Clarify technical content
mdchat edit guide.md --section "Setup" --action clarify# Interactive setup (recommended for first-time users)
mdchat config setup
# Manual configuration
mdchat config set provider openai
mdchat config set model gpt-4o
mdchat config set apiKey your-api-key
# View current configuration
mdchat config list# Show all headings with line numbers
mdchat sections README.md--provider <provider>: AI provider (openai, anthropic, ollama)--model <model>: Model to use (gpt-4o, claude-3-5-sonnet-20241022, llama3.2, etc.)--api-key <key>: API key for the provider--base-url <url>: Custom API base URL (for ollama or custom endpoints)
Ask a question (streaming by default):
mdchat ask "Write a comprehensive guide to Node.js best practices"Summarize multiple research papers:
mdchat summarize "research/papers/*.md" -o research-summary.mdEdit and improve a blog post:
mdchat edit blog-post.md --section "Conclusion" --action expandSet your API key as an environment variable:
export OPENAI_API_KEY="your-api-key-here"
# or
export ANTHROPIC_API_KEY="your-anthropic-key"Or configure it via the CLI:
mdchat config --api-key your-api-keyAll AI responses are wrapped in HTML comments for easy identification:
Your AI-generated content appears here.
This makes it clear what content was generated by AI vs. human-written.
- OpenAI: default provider. Common model:
gpt-4o.- Env: set
OPENAI_API_KEYor runmdchat config setupand paste your key.
- Env: set
- Anthropic (Claude): set
--provider anthropic --model claude-3-5-sonnet-20241022.- Env: set
ANTHROPIC_API_KEY.
- Env: set
- Ollama (local): run
ollama serve, install a model (e.g.,ollama pull llama3.2).- Use
--provider ollama --model llama3.2and optionally--base-url http://localhost:11434.
- Use
You can also persist these choices using:
mdchat config set provider openai
mdchat config set model gpt-4o
mdchat config set apiKey YOUR_KEY- macOS/Linux (bash/zsh):
export OPENAI_API_KEY="sk-..."- Windows PowerShell:
$env:OPENAI_API_KEY = "sk-..."- Windows CMD:
set OPENAI_API_KEY=sk-...-
"No provider/model configured"
- Run
mdchat config setupor pass--provider/--modelon the command.
- Run
-
"401/Forbidden or invalid API key"
- Verify your key is set (
mdchat config list) or env var is exported in the current shell.
- Verify your key is set (
-
Ollama errors like "connection refused" or "model not found"
- Start server:
ollama serve - Install model:
ollama pull llama3.2 - Then run with
--provider ollama --model llama3.2.
- Start server:
-
Streaming looks odd in files
- Use
--no-streamto print a complete response at once.
- Use
-
Save outputs to a file
- Use
-o notes.mdto append AI blocks to a markdown file.
- Use