Emacs package for AI assistance using yagi.
- Emacs 27.1+
- yagi executable in PATH
- API key configured via environment variable
Emacs 29+ built-in:
(use-package yagi
:vc (:url "https://github.com/knwoop/emacs-yagi" :branch "main")
:config
(yagi-mode 1))(leaf yagi
:vc (:url "https://github.com/knwoop/emacs-yagi" :branch "main")
:global-minor-mode yagi-mode)git clone https://github.com/knwoop/emacs-yagi ~/.emacs.d/site-lisp/emacs-yagiAdd to your init.el:
(add-to-list 'load-path "~/.emacs.d/site-lisp/emacs-yagi")
(require 'yagi)
(yagi-mode 1)Set your API key in your shell profile (.bashrc, .zshrc, etc.):
export OPENAI_API_KEY="your-key-here"
# or
export ANTHROPIC_API_KEY="your-key-here"
# or
export GEMINI_API_KEY="your-key-here";; Path to yagi executable (default: "yagi")
(setq yagi-executable "yagi")
;; Model to use (default: "openai")
;; Can also be set via YAGI_MODEL environment variable
(setq yagi-model "openai")
;; Show prompt in response buffer (default: t)
(setq yagi-show-prompt t)| Command | Description | Region Required |
|---|---|---|
M-x yagi-chat |
Chat with AI (with optional code context) | No |
M-x yagi-prompt |
Ask AI a question | No |
M-x yagi-explain |
Explain selected code | Yes |
M-x yagi-refactor |
Refactor selected code | Yes |
M-x yagi-comment |
Add comments to selected code | Yes |
M-x yagi-fix |
Fix bugs in selected code | Yes |
M-x yagi-chat-reset |
Clear chat conversation history | No |
M-x yagi-apply |
Apply pending refactored code | No |
When yagi-mode is enabled, the following keybindings are available under the C-c Y prefix:
| Key | Command |
|---|---|
C-c Y c |
yagi-chat |
C-c Y p |
yagi-prompt |
C-c Y e |
yagi-explain |
C-c Y r |
yagi-refactor |
C-c Y m |
yagi-comment |
C-c Y f |
yagi-fix |
C-c Y x |
yagi-chat-reset |
- Select a region and press
C-c Y eto explain the code - Select code and run
M-x yagi-chat RET how can I improve this? RET - Run
M-x yagi-prompt RET what is the time complexity of quicksort? RET - Select code,
C-c Y rto refactor, review in response buffer, pressato apply - Select code,
C-c Y fto fix bugs, confirm withyto apply
yagi supports many AI providers. Set the corresponding API key environment variable:
- OpenAI (
OPENAI_API_KEY) - Anthropic (
ANTHROPIC_API_KEY) - Google Gemini (
GEMINI_API_KEY) - DeepSeek (
DEEPSEEK_API_KEY) - Groq (
GROQ_API_KEY) - xAI (
XAI_API_KEY) - Mistral (
MISTRAL_API_KEY) - Perplexity (
PERPLEXITY_API_KEY) - Cerebras (
CEREBRAS_API_KEY) - Cohere (
COHERE_API_KEY) - OpenRouter (
OPENROUTER_API_KEY) - SambaNova (
SAMBANOVA_API_KEY) - GLM (
GLM_API_KEY)
Make sure yagi is installed and in your PATH:
# Install yagi
go install github.com/yagi-agent/yagi@latest
# Verify
which yagiMake sure your API key environment variable is set:
# Check if key is set
echo $OPENAI_API_KEY
# If not set, add to your shell profile
export OPENAI_API_KEY="your-key-here"If running Emacs from a GUI launcher, environment variables from your shell may not be available. Consider using exec-path-from-shell to inherit them.
MIT