shared-typescript-lsp
A plugin for Claude Code, Anthropic's coding agent, that lets every session on your machine share one TypeScript language server instead of starting one each, so several sessions in a large repo can together use less memory. A language server is the background process that works out type errors, definitions and references for an editor, and Claude Code normally starts a separate one for each session. A language server and its editor talk over the Language Server Protocol (LSP), which is where the "lsp" in this plugin's name comes from.
TypeScript 7 is Microsoft's rewrite of the TypeScript compiler, built for speed, and it ships its own language server. That server reports type errors only when asked, so the plugin also asks for them after each edit and passes them to Claude Code.
The problem
I run a lot of Claude Code sessions at once, each in its own git worktree (a second checkout of the same repo, on another branch). Claude Code starts a separate TypeScript language server for every session. In blackhole, a private project of mine, each of those servers grows to about 590 MB once it has loaded a couple of packages. Blackhole is a mid-size TypeScript monorepo, which is one repository holding many packages.
At that size, five sessions in five worktrees would come to about three gigabytes of servers. I think most of that is the same type information held five times. I haven't measured five sessions sharing one server yet: the figures under "Memory" below come from two worktrees with one file open, which is less than those 590 MB servers had loaded.
TypeScript 7 adds a second problem. Its built-in server, started with tsc --lsp (tsc is the TypeScript compiler's own command), only reports type errors when the client asks for them. Here the client is Claude Code, and in the versions I've used it doesn't ask: it waits for the server to send errors on its own after an edit. So with TypeScript 7 the agent edits a file, breaks the types and gets no error back.
What it does
- One server per repo and TypeScript version. Each file a session opens goes to a server for its repo and the TypeScript version installed nearest to it: the closest
node_modules/typescript in the folders above the file (node_modules is where a package manager puts a repo's installed packages). Worktrees of the same repo share a server, and different repos never do, even on the same version, so a crash or a slow load in one project can't hold up another. This works whichever package manager installed TypeScript: npm, pnpm, Yarn or Bun. A repo that mixes TypeScript versions gets one server per version.
- Each session sees only its own worktree. A small daemon (a background process that the first session starts) sits between the sessions and the server. Each session talks to the daemon through a shim, a small process of its own. The daemon keeps each session's requests and replies apart, so a session gets only its own type errors and find-references results.
- Type errors after every edit. After each open, change or save, the plugin asks TypeScript 7's server for errors on the session's open files and sends them to Claude Code. The edited file goes first because, as far as I can tell, Claude Code checks for errors as soon as the edit returns and stops waiting soon after.
- Older TypeScript still works. Files under TypeScript 6 or earlier go to typescript-language-server, a widely used open-source language server for those versions, shared in the same way. That server sends its own errors.
- New packages are picked up. When you install a package in one worktree, an import that showed "Cannot find module" there stops showing it by the next edit, with no restart. Other worktrees are left as they were. In the versions I've used, Claude Code doesn't tell language servers when files change on disk, but TypeScript 7's server watches each project's files itself,
node_modules included, as long as the client hasn't offered to do the watching. The plugin makes sure it hasn't.
- A warm start. Claude Code seems to start a language server on a session's first edit and to check for errors about a tenth of a second later. A server that is still starting, or still loading the project, misses that check. The plugin adds a SessionStart hook (a command Claude Code runs each time a session opens) that starts the shared server and has it load the project straight away, so the first edit gets its errors too.
- It shuts down when idle. A server stops 10 minutes after its last session leaves, and the daemon stops 10 minutes after that.