serena-shared
serena-shared
Run one Serena server per repository and share it between all your coding-agent sessions (Claude Code, Codex, and other MCP clients), instead of starting a new Serena and a new set of language servers for every session.
Works on macOS and Linux.
Why you might want this
Normally each agent session starts its own Serena. Serena in turn starts language servers
(tsserver, pyright, gopls, ...) for the project. If you keep several sessions open in the
same repository, you pay for all of that several times:
memory: every session holds its own copy of the language servers;
CPU: every new session indexes the project again, which slows session startup;
consistency: separate Serena instances can overwrite each other's
.serena/cache.
Serena can serve several clients from one server, but a server works on one project at a time. A single global server would let one session switch the project under another session (Serena docs, oraios/serena#1235).
serena-shared solves this by starting one server per repository and per client type, on demand, and connecting each session to the right one.
Related MCP server: agent-bus
Before you start
You need:
macOS or Linux. Windows is not supported.
uv, to install the tool.
Serena 2.x, installed as a command. Check with:
serena --versionIf that prints a version, you are ready. If not, install Serena:
uv tool install serena-agentserena-shared needs the
serenacommand to be a regular launcher file, asuv tool installandpipxcreate. Configurations that run Serena throughuvx --from git+...each time are not shared; they keep working as before. To share a pinned Serena version, pointSERENA_SHARED_SERENAat theserenalauncher inside that version's environment.
Install
Install serena-shared:
uv tool install git+https://github.com/wnz99/serena-sharedCheck that it is on your
PATH:serena-shared --versionThis prints Serena's version, because serena-shared passes any command it does not handle straight to Serena. If the command is not found, run
uv tool update-shelland open a new terminal.
Set up your agents
serena-shared is a drop-in replacement for the serena command. In each agent's MCP settings,
change the command from serena to serena-shared and keep the arguments as they are. The
arguments must include --project-from-cwd; that is what tells serena-shared which repository
a session belongs to.
Claude Code
If you already have a Serena server configured, remove it first:
claude mcp remove serena -s userThen add it back through serena-shared:
claude mcp add serena -s user -- serena-shared start-mcp-server --context=claude-code --project-from-cwdCodex
In ~/.codex/config.toml, set the Serena entry to:
[mcp_servers.serena]
command = "serena-shared"
args = ["start-mcp-server", "--context=codex", "--project-from-cwd"]If you already have extra Serena arguments there (for example --agent-interface tools), keep
them. Codex gives an MCP server 10 seconds to start by default. On a slow or busy machine you
can allow more with startup_timeout_sec = 30 in the same section.
Other MCP clients
Use the same pattern: command serena-shared, arguments as you would pass to serena,
including start-mcp-server, the right --context for your client, and --project-from-cwd.
Apply the change
Restart your agent sessions. Sessions that are already running keep their old Serena until they restart.
Check that it works
Open two sessions in the same repository.
Look for the shared server:
ls ~/.local/state/serena-shared/ cat ~/.local/state/serena-shared/*/server.jsonYou should see one
server.jsonper repository and client type, with"state": "running". Two Claude Code sessions in the same repository share one entry. A Claude Code session and a Codex session in the same repository get one entry each, because each client type uses a different Serena context and tool set.For Claude Code,
claude mcp get serenashould showStatus: ✔ Connected.
Shared startup failures are reported to the client instead of launching a private Serena.
Rootless folders and invocations without --project-from-cwd still pass through to Serena.
Settings
All settings are optional environment variables. Set them in the agent's MCP configuration
(the env section) or in your shell.
Variable | Default | What it does |
|
| Path to the Serena command to run |
|
| How long a server keeps running after its last session closes |
|
| Where sockets, locks and logs are kept. It must be a folder that belongs to you. Keep the path short: Unix socket paths are limited to about 100 characters |
Each server writes its log to <state dir>/<server id>/server.log. When a server starts and
the log is larger than 5 MB, the old log is moved to server.log.1.
Options that control how the shared server is reached (--transport, --host, --port,
--project), Serena's web dashboard options and --enable-gui-log-window are set by
serena-shared; any values you pass for them are ignored.
Upgrade
Reinstall from the repository to get the latest version:
uv tool install --reinstall git+https://github.com/wnz99/serena-sharedThen restart your agent sessions. Servers started by the previous version keep running for their existing sessions and stop on their own after the idle timeout.
Uninstall
Change your agents' MCP settings back from
serena-sharedtoserena, and restart them.Remove the tool:
uv tool uninstall serena-sharedOptionally delete its state directory:
rm -rf ~/.local/state/serena-shared. Running servers stop on their own after the idle timeout.
How it works
When an agent starts serena-shared start-mcp-server --project-from-cwd ..., serena-shared:
Finds the repository root the same way Serena does: the nearest folder, going up from the session's folder, that contains
.serena/project.ymlor.git. Git worktrees count as their own repositories.Prepares a copy of the requested Serena context with
single_project: true, so the shared server does not offeractivate_projectand no session can switch it to another project.Connects to the running server for this repository, Serena installation and set of arguments, or starts one. Different contexts, such as
claude-codeandcodex, get separate servers so each client gets its own tool set.Connects stdin/stdout to a shared relay broker for that server key. On macOS, the client becomes the system
ncprocess; Linux and systems without Apple'sncuse a standard-library Python byte proxy. The HTTP/async runtime runs once per broker, rather than once per connected agent session.
Each active session holds a worker lease. After five minutes without client requests, the broker closes an initialized session and releases its lease. A later request reattaches to the worker and repeats initialization internally, without replaying tool calls or exposing a second initialization response. Sessions with in-flight work, unanswered server requests, resource subscriptions or custom logging settings remain attached. Initialization capabilities must match after reconnect; otherwise the client receives an error and must restart. Server notifications are not delivered while a session is suspended. A broker exits five minutes after its last client disconnects.
When no worker leases remain for the configured idle timeout, the server stops together with its language servers. If a server or its supervisor crashes, the next session start cleans it up and starts a fresh one.
If a shared server cannot be started or reached within the startup budget, the client receives an error. A server that is merely slow to start keeps starting in the background, and a later client can use it. Startup contention never creates duplicate private servers.
Any other use of the command (for example serena-shared --version, or a configuration without
--project-from-cwd) runs Serena directly, unchanged.
Security
Shared servers listen on a Unix socket inside the state directory, which only your user can
access (permissions 0700). They do not open a network port: serena-shared turns off Serena's
web dashboard for shared servers, because a background server has no use for it and the
dashboard would listen on a local TCP port. Serena's MCP server also keeps its protection
against requests from web pages (DNS-rebinding protection).
serena-shared refuses to use a state directory that is a symlink or belongs to another user, and reports an error.
Limitations
Serena handles one tool call at a time per server. Sessions sharing a server wait for each other's long-running calls.
A server keeps the environment (for example
PATH) of the session that started it.If a server stops while sessions are connected, those sessions lose Serena until they restart.
State folders for repositories or worktrees you have deleted are not removed automatically. Delete them from the state directory when no server is running.
serena-shared starts Serena through its normal command-line entry point but asks the web server (uvicorn) to listen on a Unix socket. A future Serena release that stops using uvicorn would require an update to serena-shared.
Development
uv sync
uv run pytest -qThe integration tests start real Serena servers and need serena on your PATH. They take
about a minute.
License
MIT. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
Shared memory for coding agents. Stop re-explaining your codebase every session.
An MCP memory server. One memory your agents share — across models, devices and apps.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA local-first MCP server for coordinating parallel AI coding sessions with tools like Claude Code and Codex in a single repository.2MIT
- AlicenseAqualityDmaintenanceEnables multiple coding agents (Claude Code, Codex, Cursor) to discover each other's sessions, search transcripts, ask questions, and handoff tasks through a shared MCP server.54 npmMIT
- AlicenseNot gradedqualityBmaintenanceMCP server that provides cross-session awareness for Claude Code, tracking active sessions, file conflicts, and shared todos to enable agent coordination without blocking tool calls.860 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables multiple Claude Code sessions to share a single HTTP MCP endpoint, lazily spawning stdio MCP servers only when their tools are called, reducing idle processes and memory usage.MIT