Code search

How the agent finds existing code, traces callers and catches errors after an edit, and what each part needs on the Mac.

The agent searches a project three ways before it changes code: by exact text, by structure through a language server, and by meaning. Search by meaning finds code that does the same job under another name, so an existing helper is reused. The language server finds every caller of a function about to change, and reports type errors right after each edit.

Search by meaning

Search by meaning is built in and on by default. Nothing is set up by hand.

  • The first use downloads an embedding model of about 91 MB and builds an index of the project in the background. The agent uses the other two searches until the index is ready.
  • The model runs on the Mac. Source code and queries are never uploaded.
  • The index is saved in the project’s .kcode folder and shared by the project’s sessions. A new session brings it up to date when it opens.
  • Each git worktree has an index of its own.

Language servers

kcode starts a language server the first time the agent works in that language. The server itself must be installed on the Mac.

Language Default command
Rust rust-analyzer
TypeScript and JavaScript typescript-language-server --stdio
Go gopls
Python pyright-langserver --stdio
C and C++ clangd
Bash bash-language-server start
Swift sourcekit-lsp
Kotlin kotlin-lsp --stdio
Java jdtls

lsp_client.servers in ~/.kcode/config.toml changes a command or adds a language. A missing server matters only when its language is used.

Errors after an edit

After the agent edits a file, kcode sends the file to its language server and adds the fresh errors to the result of the edit. The agent sees a wrong type, a missing import or a changed signature before it builds on the edit. This is on by default (lsp_client.diagnostics_enabled).

Checking the setup

/doctor in a session, or kcode doctor in a terminal, checks that each language server the project needs can be found, and says what to install when one is missing. The check runs on the Mac and calls no provider.

Product video