Skip to content

Getting started

Requirements

  • Python 3.11 or newer, on Windows, macOS or Linux.
  • Internet access the first time, to download Pyodide (about 10 MB). After that everything runs offline.
  • No separate Deno install: the deno wheel from PyPI is installed automatically.

1. Install

pip install codemode-mcp
pip install "codemode-mcp[all]"   # OpenAI + Anthropic SDKs, tiktoken for exact token counts
uv tool install codemode-mcp        # or run without installing: uvx codemode-mcp ...

Optional extras:

Extra Adds
openai openai SDK, for codemode-mcp chat / benchmark and run_openai() with any OpenAI-compatible API
anthropic anthropic SDK, for --provider anthropic and run_anthropic()
tokens tiktoken, for exact token counts (otherwise about 4 characters per token)
all All of the above

2. Prepare the sandbox

codemode-mcp setup
# Preparing sandbox (first run downloads Pyodide, ~10 MB)...
# Python 3.14.2 ready

3. Tell it about your MCP servers

If you already use MCP servers in a client, import them:

codemode-mcp init --from claude      # or: cursor | vscode | windsurf | path/to/config.json

Or write mcp.json yourself. It uses the same format as Claude Desktop:

mcp.json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"}
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/projects"]
    }
  }
}

${GITHUB_TOKEN} is read from your environment, so secrets never have to be written into the file.

4. Check what you'll save

codemode-mcp stats -c mcp.json

The output looks like this (shown for the bundled 306-tool example, examples/mcp.big.json):

Servers: 2   Tools: 306   Strategy: search   Tokenizer: tiktoken:o200k_base
Tool-definition tokens per LLM request, classic MCP :    78,933
Tool-definition tokens per LLM request, Code Mode   :     1,697
Saved per request (definitions only)                :     97.9%

5. Try a script yourself

This runs exactly what an LLM would send:

codemode-mcp search -c mcp.json "list issues"
codemode-mcp run -c mcp.json "issues = await github.list_issues(owner='me', repo='app', state='open')
[i['title'] for i in issues][:5]"

6. Connect your LLM

codemode-mcp init --from claude --install
Restart the client. It now sees run_code (and search_tools) instead of all your tools. See Use with MCP clients.

export OPENAI_API_KEY=...
codemode-mcp chat -c mcp.json -m gpt-4.1-mini -v

from codemode_mcp import CodeMode
from codemode_mcp.agent import run_openai

async with CodeMode.from_config("mcp.json") as cm:
    result = await run_openai(cm, "Summarise my open issues", model="gpt-4.1-mini")
    print(result.text, cm.usage())
See Python library & LLMs.

7. Watch the savings

codemode-mcp usage        # terminal summary
codemode-mcp dashboard    # web dashboard at http://127.0.0.1:8765

Next: How it works.