AI Mode for Emacs The ai-mode package brings AI-assisted coding, chat, completion, refactoring, and bug fixing directly into Emacs, with multi-backend support for OpenAI, Anthropic, Hugging Face, and Google Generative AI. The package is installable via MELPA using M-x package-install RET ai-mode RET, with separate backend packages such as ai-mode-openai, ai-mode-anthropic, and ai-mode-google-genai, or manually by cloning the ai-mode repository and its backend repositories into a directory like ~/.emacs.d/plugins/. The package adds buffer-bound chat sessions, real-time completion previews, project-wide context indexing, and structured request auditing to the Emacs workflow. AI mode for Emacs is a comprehensive package that integrates powerful artificial intelligence capabilities directly into your Emacs workflow. This package transforms Emacs into an AI-enhanced development environment, providing intelligent assistance for coding, writing, and general text manipulation tasks. The modular architecture ensures maintainability, testability, and extensibility. - Interactive AI Chat with Buffer Binding : Directly engage with AI models for real-time problem-solving, code review, and general assistance. Create dedicated chat sessions bound to specific buffers with rich context integration, smart startup strategies, and context-based chat creation from response buffers. - Intelligent Code Completion : Receive interactive, multi-candidate code suggestions and completions. It supports real-time previews, navigation through candidates, dynamic context adjustment, and integration of user instructions. - Code Modification & Refactoring : Streamline development by leveraging AI to intelligently modify, improve, and refactor existing code. - Code Analysis & Documentation : Generate comprehensive explanations, documentation, and insightful analysis for code blocks and functions, enhancing readability and maintainability. - Automated Bug Detection & Fixing : Utilize AI to detect common issues and suggest fixes directly within your buffer. - Multi-Backend Support : Seamlessly integrate with various AI providers, including OpenAI, Anthropic, Hugging Face, and Google Generative AI, for diverse model access. - Customizable Commands : Tailor AI operations to your specific development needs by defining custom commands and integrating them seamlessly into your Emacs setup. - Advanced Context Management : Manage global, buffer-local, and temporary context pools, with extended context capabilities including project-wide indexing, memory files, and comprehensive context enrichment. - Real-time Previews & Progress Indicators : Get instant visual feedback for completions and track the progress of ongoing AI requests. - Structured Request Auditing : Detailed logging of AI requests, contexts, and responses for debugging, performance analysis, and security auditing with improved callback system and error handling. Whether you're debugging complex code, exploring new technologies, or enhancing your documentation, AI mode provides the tools to accelerate your productivity and enhance your Emacs experience. The easiest and recommended way to install this package is through MELPA. To configure MELPA, add the following lines to your ~/.emacs file: package-initialize add-to-list 'package-archives ' "melpa" . "http://melpa.org/packages/" Then, run the command: M-x package-install RET ai-mode RET M-x package-install RET ai-mode-openai RET If you plan to use OpenAI API M-x package-install RET ai-mode-anthropic RET If you plan to use Anthropic M-x package-install RET ai-mode-google-genai RET If you plan to use Google Generative AI You might want to refresh the package contents if you haven't done so recently by running: M-x package-refresh-contents RET If you prefer to manage packages manually or use a different package manager, clone the ai-mode repository and its related backend repositories into a common directory, for example, ~/.emacs.d/plugins/ : bash $ mkdir -p ~/.emacs.d/plugins $ cd ~/.emacs.d/plugins $ git clone https://github.com/ai-mode/ai-mode $ git clone https://github.com/ai-mode/ai-mode-openai If you plan to use OpenAI API $ git clone https://github.com/ai-mode/ai-mode-anthropic If you plan to use Anthropic $ git clone https://github.com/ai-mode/ai-mode-deepseek If you plan to use DeepSeek $ git clone https://github.com/ai-mode/ai-mode-hf If you plan to use Hugging Face $ git clone https://github.com/ai-mode/ai-mode-google-genai If you plan to use Google Generative AI $ git clone https://github.com/ai-mode/ob-ai If you plan to use Org Babel integration Then, add the ~/.emacs.d/plugins/ directory to your Emacs load-path in your ~/.emacs or init.el file. For use-package , you can configure it by adding the following to your init.el or .emacs : add-to-list 'load-path expand-file-name "~/.emacs.d/plugins/" ;; You can then use use-package as usual for ai-mode and its backends, ;; as they will be discoverable on your load-path. AI Mode's functionality is highly customizable. While this package provides the core framework, integration with specific AI models like OpenAI, Anthropic, etc. is handled by separate backend packages. To enable a specific backend, you typically load its package and then register its model-providing function with ai-mode . This makes its models available for use in ai-mode and ai-chat . Remember to configure any necessary API keys as per the backend's documentation. Here's an example of a comprehensive use-package configuration for ai-mode , including how to enable various backends and the ai-debug package: use-package ai-mode :defer t :config progn global-ai-mode ;; Set global keybindings for code completion global-set-key kbd "C-