Free, ultrafast, extensible AI code completion tool for Emacs
Codeium autocompletes your code with AI in all major IDEs. We launched this implementation of the Codeium plugin for Emacs to bring this modern coding superpower to more developers. Check out our playground if you want to quickly try out Codeium online.
codeium.el provides a completion-at-point-functions
backend. It is designed to be use with a front-end, such as company-mode, corfu, or the built-in completion-at-point
.
codeium.el is an open source client and (mostly) written by Alan Chen. It uses a proprietary language server binary, currently downloaded (automatically, with confirmation) from here. Use M-x codeium-diagnose
to see apis/fields that would be sent to the local language server, and the command used to run the local language server. Customize codeium-api-enabled
, codeium-fields-regexps
and codeium-command
to change them.
Contributions are welcome! Feel free to submit pull requests and issues related to the package.
-
Install Emacs, ensuring the version of Emacs you are running is compiled with libxml2. You can check this by using the
(libxml-available-p)
function within Emacs Lisp. This function returns t (true) if libxml2 is available in your current Emacs session. -
Install a text-completion frontend of your choice. (We recommend company-mode or corfu).
-
Install
Exafunction/codeium.el
using your emacs package manager of choice, or manually. See Installation Options below. -
Run
M-x codeium-install
to set up the package. -
Add
codeium-completion-at-point
to yourcompletion-at-point-functions
. -
Start seeing suggestions!
You can see all customization options via M-x customize
.
(better documentation coming soon!)
Here is an example configuration:
;; we recommend using use-package to organize your init.el
(use-package codeium
;; if you use straight
;; :straight '(:type git :host github :repo "Exafunction/codeium.el")
;; otherwise, make sure that the codeium.el file is on load-path
:init
;; use globally
(add-to-list 'completion-at-point-functions #'codeium-completion-at-point)
;; or on a hook
;; (add-hook 'python-mode-hook
;; (lambda ()
;; (setq-local completion-at-point-functions '(codeium-completion-at-point))))
;; if you want multiple completion backends, use cape (https://github.com/minad/cape):
;; (add-hook 'python-mode-hook
;; (lambda ()
;; (setq-local completion-at-point-functions
;; (list (cape-capf-super #'codeium-completion-at-point #'lsp-completion-at-point)))))
;; an async company-backend is coming soon!
;; codeium-completion-at-point is autoloaded, but you can
;; optionally set a timer, which might speed up things as the
;; codeium local language server takes ~0.2s to start up
;; (add-hook 'emacs-startup-hook
;; (lambda () (run-with-timer 0.1 nil #'codeium-init)))
;; :defer t ;; lazy loading, if you want
:config
(setq use-dialog-box nil) ;; do not use popup boxes
;; if you don't want to use customize to save the api-key
;; (setq codeium/metadata/api_key "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
;; get codeium status in the modeline
(setq codeium-mode-line-enable
(lambda (api) (not (memq api '(CancelRequest Heartbeat AcceptCompletion)))))
(add-to-list 'mode-line-format '(:eval (car-safe codeium-mode-line)) t)
;; alternatively for a more extensive mode-line
;; (add-to-list 'mode-line-format '(-50 "" codeium-mode-line) t)
;; use M-x codeium-diagnose to see apis/fields that would be sent to the local language server
(setq codeium-api-enabled
(lambda (api)
(memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion))))
;; you can also set a config for a single buffer like this:
;; (add-hook 'python-mode-hook
;; (lambda ()
;; (setq-local codeium/editor_options/tab_size 4)))
;; You can overwrite all the codeium configs!
;; for example, we recommend limiting the string sent to codeium for better performance
(defun my-codeium/document/text ()
(buffer-substring-no-properties (max (- (point) 3000) (point-min)) (min (+ (point) 1000) (point-max))))
;; if you change the text, you should also change the cursor_offset
;; warning: this is measured by UTF-8 encoded bytes
(defun my-codeium/document/cursor_offset ()
(codeium-utf8-byte-length
(buffer-substring-no-properties (max (- (point) 3000) (point-min)) (point))))
(setq codeium/document/text 'my-codeium/document/text)
(setq codeium/document/cursor_offset 'my-codeium/document/cursor_offset))
Here is an example configuration for company-mode.
(use-package company
:defer 0.1
:config
(global-company-mode t)
(setq-default
company-idle-delay 0.05
company-require-match nil
company-minimum-prefix-length 0
;; get only preview
company-frontends '(company-preview-frontend)
;; also get a drop down
;; company-frontends '(company-pseudo-tooltip-frontend company-preview-frontend)
))
You can also access codeium.el from elisp; here is a snippet that returns
the full response of a GetCompletions
request:
(cl-letf*
(
;; making a new codeium-state (thus a new local language server process)
;; takes ~0.2 seconds; avoid when possible
(state (codeium-state-make :name "example"))
((codeium-config 'codeium/document/text state) "def fibi(n):")
((codeium-config 'codeium/document/cursor_offset state) 12)
((codeium-config 'codeium-api-enabled state) (lambda (api) (eq api 'GetCompletions))))
(unwind-protect
(progn
(codeium-init state)
;; make async requests using codeium-request
(cdr (codeium-request-synchronously 'GetCompletions state nil)))
;; cleans up temp files, kill process. Scheduled async requests on this state will be dropped.
(codeium-reset state)))
Note that, among other things, you get probabilities for each token! We would love to see a PR or your own package that uses those!
If you want to authenticate automatically, add your codeium api key to one of auth-sources
. For example
~/.authinfo.gpg:
machine codeium.com login apikey secret <insert_api_key_here>
(straight-use-package '(codeium :type git :host github :repo "Exafunction/codeium.el"))
In packages.el
add the following:
(package! codeium :recipe (:host github :repo "Exafunction/codeium.el"))
Add the example configuration to your config.el
file.
Run the following.
git clone --depth 1 https://github.com/Exafunction/codeium.el ~/.emacs.d/codeium.el
Add the following to your ~/.emacs.d/init.el
file.
(add-to-list 'load-path "~/.emacs.d/codeium.el")
Do you have a working installation for another Emacs environment (Spacemacs)? Submit a PR so we can share it with others!