mirror of
https://github.com/hanzoai/hanzo.el.git
synced 2026-10-30 18:34:28 +00:00
main
GitHub does not resolve a URL in uses:, so it rejected the workflow and the site never published. Claude-Session: https://claude.ai/code/session_01HuMDfgFssPUptYUzgZ6Cp8
hanzo.el
Hanzo AI integration for Emacs. AI-powered code completion, explanation, refactoring, and more using Claude, GPT-4, Gemini, Ollama, and any OpenAI-compatible API.
Features
- Multiple LLM Providers: Claude, GPT-4, Gemini, Ollama, and any OpenAI-compatible API
- LLM Gateway Support: Use Hanzo LLM Gateway for unified access to 100+ providers
- AI-Powered Commands: Completion, explanation, refactoring, tests, documentation, review
- WebSocket Bridge: Allow AI agents to control Emacs (MCP/ZAP)
Requirements
- Emacs 27.1+
request.el(optional, for better HTTP handling)markdown-mode(optional, for output formatting)
Installation
Using straight.el:
(straight-use-package
'(hanzo :type git :host github :repo "hanzoai/hanzo.el"))
(require 'hanzo)
(setq hanzo-model "claude-sonnet-4-20250514")
Using use-package with straight:
(use-package hanzo
:straight (:host github :repo "hanzoai/hanzo.el")
:config
(setq hanzo-model "claude-sonnet-4-20250514")
(setq hanzo-api-key (getenv "ANTHROPIC_API_KEY"))
(hanzo-setup-keybindings))
Manual:
git clone https://github.com/hanzoai/hanzo.el ~/.emacs.d/site-lisp/hanzo.el
(add-to-list 'load-path "~/.emacs.d/site-lisp/hanzo.el")
(require 'hanzo)
Configuration
;; Model settings
(setq hanzo-model "claude-sonnet-4-20250514") ; Default model
(setq hanzo-provider "anthropic") ; anthropic, openai, google, ollama
(setq hanzo-mode "api") ; api, mcp, ollama
;; API settings
(setq hanzo-api-key (getenv "ANTHROPIC_API_KEY"))
(setq hanzo-llm-gateway "http://localhost:4000") ; LLM Gateway URL
(setq hanzo-ollama-url "http://localhost:11434") ; Ollama URL
;; Generation settings
(setq hanzo-temperature 0.2)
(setq hanzo-max-tokens 4096)
;; System prompt
(setq hanzo-system-prompt "You are an expert programmer...")
;; Set up keybindings (optional)
(hanzo-setup-keybindings) ; Binds to C-c h prefix
Environment Variables
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="..."
Commands
| Command | Description |
|---|---|
M-x hanzo-chat |
Chat with AI (prompts for input) |
M-x hanzo-complete |
Complete code at point |
M-x hanzo-explain |
Explain selected region |
M-x hanzo-refactor |
Refactor selection with instruction |
M-x hanzo-fix |
Fix bugs in selection |
M-x hanzo-tests |
Generate tests for selection |
M-x hanzo-docs |
Add documentation to selection |
M-x hanzo-review |
Review code for issues |
M-x hanzo-set-model |
Change the AI model |
M-x hanzo-set-mode |
Change connection mode |
M-x hanzo-version |
Show version and config |
Keybindings
Call (hanzo-setup-keybindings) to enable default keybindings:
| Key | Command |
|---|---|
C-c h h |
hanzo-chat |
C-c h c |
hanzo-complete |
C-c h e |
hanzo-explain |
C-c h r |
hanzo-refactor |
C-c h f |
hanzo-fix |
C-c h t |
hanzo-tests |
C-c h d |
hanzo-docs |
C-c h v |
hanzo-review |
C-c h m |
hanzo-set-model |
Custom prefix:
(hanzo-setup-keybindings "C-c a") ; Use C-c a prefix instead
Available Models
Anthropic
claude-sonnet-4-20250514(default)claude-opus-4-20250514claude-3-5-sonnet-20241022
OpenAI
gpt-4-turbogpt-4oo1-preview
gemini-1.5-progemini-1.5-flash
Ollama (local)
ollama:llama3.2ollama:codellamaollama:deepseek-coder
Using with LLM Gateway
For unified access to 100+ LLM providers:
# Start LLM Gateway
docker run -p 4000:4000 hanzoai/llm
# Or install directly
pip install hanzo-llm
hanzo-llm serve
Configure Emacs:
(setq hanzo-llm-gateway "http://localhost:4000")
(setq hanzo-model "claude-sonnet-4-20250514")
Using with Ollama
For local models:
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Pull models
ollama pull llama3.2
ollama pull codellama
Configure Emacs:
(setq hanzo-mode "ollama")
(setq hanzo-model "codellama")
Integration with Doom Emacs
Add to ~/.doom.d/packages.el:
(package! hanzo
:recipe (:host github :repo "hanzoai/hanzo.el"))
Add to ~/.doom.d/config.el:
(use-package! hanzo
:config
(setq hanzo-model "claude-sonnet-4-20250514")
(map! :leader
(:prefix ("h" . "hanzo")
:desc "Chat" "h" #'hanzo-chat
:desc "Complete" "c" #'hanzo-complete
:desc "Explain" "e" #'hanzo-explain
:desc "Refactor" "r" #'hanzo-refactor
:desc "Fix" "f" #'hanzo-fix
:desc "Tests" "t" #'hanzo-tests
:desc "Docs" "d" #'hanzo-docs
:desc "Review" "v" #'hanzo-review)))
Integration with Spacemacs
Add to dotspacemacs-additional-packages:
(hanzo :location (recipe :fetcher github :repo "hanzoai/hanzo.el"))
Configure in dotspacemacs/user-config:
(use-package hanzo
:config
(setq hanzo-model "claude-sonnet-4-20250514")
(spacemacs/set-leader-keys
"ah" 'hanzo-chat
"ac" 'hanzo-complete
"ae" 'hanzo-explain
"ar" 'hanzo-refactor
"af" 'hanzo-fix
"at" 'hanzo-tests
"ad" 'hanzo-docs
"av" 'hanzo-review))
License
MIT - Hanzo AI Inc
Languages
Emacs Lisp
100%