OpenCode
Add Alexein to OpenCode with one command and sign in, so it searches your memory and saves what it learns in every project.
OpenCode searches your Alexein memory before it answers, and saves what you tell it and what you build together. This page is for OpenCode 2 or newer.
1. Add Alexein
Run this command:
opencode mcp add alexein --url https://api.alexein.ai/v1/mcp --global--global adds Alexein for you in every project. Leave it out to add it to this project only.
npx @alexein/cli connect --only opencode runs the same command for you, and offers the sign-in after it.
Sign in. In a terminal, run:
opencode mcp auth alexeinYour browser opens Alexein's sign-in. In OpenCode, you can also run /mcps, choose alexein and sign in.
Sign in, keep Read and save so OpenCode can save, and select Allow. There is no key to copy.
Or add the alexein entry to OpenCode's settings yourself, under mcp.servers, and sign in as above:
{
"mcp": {
"servers": {
"alexein": {
"type": "remote",
"url": "https://api.alexein.ai/v1/mcp"
}
}
}
}Over SSH or in a container, the sign-in asks you to paste the address your browser ends on after Allow. To
disconnect, run opencode mcp logout alexein, or select Disconnect on it in
My memory › AI assistants.
Or with a key
For scripts and CI, where nobody is there to sign in, use a personal key instead.
- Open My memory › Personal keys and select Create key. Label it
OpenCode, choose Read and write so OpenCode can save, and copy the key. It is shown once. - Put it in an environment variable, in the shell profile OpenCode starts from (
~/.zshrc,~/.bashrc):
export ALEXEIN_API_KEY="ax_..."- Add the
alexeinentry with the key's header, and sign-in turned off:
{
"mcp": {
"servers": {
"alexein": {
"type": "remote",
"url": "https://api.alexein.ai/v1/mcp",
"oauth": false,
"headers": {
"Authorization": "Bearer {env:ALEXEIN_API_KEY}",
"X-Alexein-User": "me"
}
}
}
}
}OpenCode fills in {env:ALEXEIN_API_KEY} from the environment, so the key is not written into the file.
X-Alexein-User: me names your own memory.
2. Teach it to use memory
Add these lines to ~/.config/opencode/AGENTS.md, the instructions OpenCode reads in every project. Create the
file if it does not exist.
Use Alexein as my memory.
Before you answer anything about me, my work or my plans, search it with memory_search.
When I tell you something new, save it with memory_add, without asking.
Save small details too: preferences, people, places, dates and decisions.
Never save passwords, keys or other secrets.Start a new session for OpenCode to read it.
3. Check it works
Run opencode mcp list in a terminal, or /mcps in OpenCode. alexein is listed.
Ask: "What do you remember about me?" OpenCode calls memory_search.
Tell it something new about you. Then open My memory: it is there within a few minutes.
Troubleshooting
alexeinneeds sign-in, or answers401. Runopencode mcp auth alexeinagain. With a key:ALEXEIN_API_KEYis not set in the shell OpenCode started from. Set it and start OpenCode again.- The entry is ignored. On OpenCode 1, update OpenCode; the entry above is OpenCode 2's.
memory_addis missing. You chose Read only when you signed in, or the key is Read. Runopencode mcp logout alexeinand sign in again with Read and save, or create a Read and write key.
More in Troubleshooting.
Didn’t find what you needed? Ask the team