🕌

EmacsとGithub Copilotを仲良くさせる

に公開
2026/01/20

EmacsとGithub Copilotを連携させるための流れ。

もし同じことをする場合にメモとして。

前提

  • Github Copilotのライセンス登録とかは済ませている
  • Emacsはemacsclientを使っている
  • 管理は一つのツールで済ませたいので、Node.jsをaquaで管理

Nodejsインストール

Node.js Support に従ってaqua経由でNode.jsをインストール

export NPM_CONFIG_PREFIX="${HOME}/.npm"
export PATH="$NPM_CONFIG_PREFIX/bin:$PATH"
mkdir -p ${HOME}/.npm/bin

aqua g -i
→ nodejs/node を選択
aqua i -l
→ Nodejsインストール

最初の壁

node -v を実行してみる

ERRO[0005] check file_src is correct                     env=darwin/arm64 error=check file_src is correct: exe_path isn't found: stat ~/.config/aqua/aquaproj-aqua/pkgs/http/nodejs.org/dist/v25.2.1/node-v25.2.1-darwin-arm64.tar.gz/node-v25.2.1-darwin-arm64/bin/corepack: no such file or directory exe_name=node exe_path=~/.config/aqua/aquaproj-aqua/pkgs/http/nodejs.org/dist/v25.2.1/node-v25.2.1-darwin-arm64.tar.gz/node-v25.2.1-darwin-arm64/bin/corepack file_name=corepack package_name=nodejs/node package_version=v25.2.1 program=aqua program_version=2.53.9 registry=standard
ERRO[0005] executable files aren't found

解決策

aqua registryのバージョンが古いのが問題だった模様

aqua up -r を実行し、バージョンを上げたら実行できた

旧バージョン: v4.403.0
新バージョン: v4.451.1

copilot.el 導入

今回入れるのは copilot.el

https://github.com/copilot-emacs/copilot.el

Installation に従ってインストールを実施

init.el 編集

以下のようにinit.elに書いてあげる

(leaf editorconfig
  :doc "EditorConfig Plugin"
  :tag "builtin"
  :added "2026-01-05")

(leaf f
  :doc "Modern API for working with files and directories."
  :req "emacs-24.1" "s-1.7.0" "dash-2.2.0"
  :tag "directories" "files" "emacs>=24.1"
  :url "http://github.com/rejeep/f.el"
  :added "2026-01-05"
  :emacs>= 24.1
  :ensure t)

(leaf copilot
  :doc "An unofficial Copilot plugin"
  :req "emacs-27.2" "editorconfig-0.8.2" "jsonrpc-1.0.14" "f-0.20.0" "track-changes-1.4"
  :tag "copilot" "convenience" "emacs>=27.2"
  :url "https://github.com/copilot-emacs/copilot.el"
  :added "2026-01-05"
  :emacs>= 27.2
  :ensure t
  :after editorconfig jsonrpc track-changes
  :hook (prog-mode . copilot-mode))

byte-compileして、emacs daemon を restart

laguage server インストール

手順に従って M-x copilot-install-server を実行

次の壁

FATA[0000] aqua failed                                   doc=https://aquaproj.github.io/docs/reference/codes/004 env=darwin/arm64 error=command is not found exe_name=npm program=aqua program_version=2.53.9

npmがない、、なぜ、、、、

解決策

emacsclientにしたので、環境変数等が思った通りになっていなかった。。

具体的には、AQUA_GLOBAL_CONFIG が設定されておらず、aquaでインストールさせたnpmを探せなかった模様

init.elに以下を書いてあげる

(setenv "AQUA_GLOBAL_CONFIG" "<値は自分のaqua.yamlのパス>")

これで使えるようになった。

aqua registryのバージョンは結構ハマった、、、

続き copilot-chat.elも入れてみる

  • Githubのaccess_tokenを発行
    • Permissionはcopilot系をあげればいいかと
  • 以下コマンドを実行してkeychainにaccess_tokenを登録する
    • init.elにベタ書が嫌なので
security add-generic-password \
  -s github.com \
  -a mcp \
  -w ghp_xxxxxxxxxxxx

-s: サイト
-a: ユーザ名
-w: access_token

らしいが、今回はEmacsから参照できればいいので access_token 以外はなんでもいい

(leaf copilot-chat
  :doc "Copilot chat interface"
  :req "emacs-29.1" "aio-1.0" "request-0.3.2" "transient-0.8.3" "polymode-0.2.2" "org-9.4.6" "markdown-mode-2.6" "shell-maker-0.76.2" "mcp-0.1.0"
  :tag "tools" "convenience" "emacs>=29.1"
  :url "https://github.com/chep/copilot-chat.el"
  :added "2026-01-19"
  :emacs>= 29.1
  :ensure t
  :after aio polymode org markdown-mode shell-maker mcp
  :config
  (setopt mcp-hub-servers
          '(("github" .
             (:command
              "docker"
              :args
              ("run"
               "-i"
               "--rm"
               "-e"
               "GITHUB_PERSONAL_ACCESS_TOKEN"
               "ghcr.io/github/github-mcp-server")
              :env
              (:GITHUB_PERSONAL_ACCESS_TOKEN
               (auth-source-pick-first-password
                :host "github.com"
                :user "mcp")
               )))))
  (set copilot-chat)
  )
(leaf mcp
  :doc "Model Context Protocol."
  :req "emacs-30.1" "jsonrpc-1.0.25"
  :tag "tools" "emacs>=30.1"
  :url "https://github.com/lizqwerscott/mcp.el"
  :added "2026-01-19"
  :emacs>= 30.1
  :ensure t
  :after jsonrpc)
(leaf aio
  :doc "Async/await for Emacs Lisp."
  :req "emacs-26.1"
  :tag "emacs>=26.1"
  :url "https://github.com/skeeto/emacs-aio"
  :added "2026-01-19"
  :emacs>= 26.1
  :ensure t)
(leaf polymode
  :doc "Extensible framework for multiple major modes."
  :req "emacs-25"
  :tag "processes" "multi-modes" "languages" "emacs>=25"
  :url "https://github.com/polymode/polymode"
  :added "2026-01-19"
  :emacs>= 25
  :ensure t)
(leaf shell-maker
  :doc "Interaction mode for making comint shells."
  :req "emacs-27.1"
  :tag "emacs>=27.1"
  :url "https://github.com/xenodium/shell-maker"
  :added "2026-01-19"
  :emacs>= 27.1
  :ensure t)

init.elに上記のように書いてあげる。

書いてある通り docker コマンドが前提。ない場合は入れてあげる。

auth-source-pick-first-passwordのパラメータ
:host -> add-generic-password の -s に指定した値
:user -> add-generic-password の -u に指定した値

M-x copilot-chat-set-mcp-servers を実行。

恐らくこれでcpilot-chatが使えると思う

Discussion