Skip to content
cloudspannerecosystemPublic

About

Spanner Code Graph empowers coding agents with enterprise codebase context.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

spannercg

One shared code graph for your whole team, served from Google Cloud Spanner. The platform team indexes each repo once and publishes its graph to a shared Spanner instance. Every engineer's AI agent then reads that same graph: no local indexing, no per-repo setup. Ask how something works and get the exact source, the call paths, and the blast radius in one call, for repos you cloned and repos you never did. Local deployment on a single machine is also supported via Spanner Omni.

SpannerCG dashboard showing every repo on the shared instance, with one repo's details expanded

Table of contents

The two roles

SpannerCG serves one shared code graph to a whole team. Which commands you run depends on which side of that graph you're on:

Platform team: runs the graph Individual engineer: uses the graph
Goal Onboard repos and keep their graphs fresh on the shared instance. Get accurate answers in your agent about any onboarded repo.
One-time setup spannercg setup provisions or verifies the instance. Install the SpannerCG plugin (or run spannercg connect) to connect to your team's instance.
Per repo census, then index to publish; sync to keep fresh. Nothing. Open the repo; your agent attaches automatically.
Indexing Yes, with a SCIP artifact for compiler-verified references. Never. Reads the published graph.
What's committed A small spannercg.json: the repo ID and exclude patterns, never cloud coordinates. Nothing. You clone what the platform team set up.
Main commands setup, census, index, sync, repos, status --dashboard, drop-repo connect, then repos to browse. Your agent does the rest.

Get started

Every step is one command plus what you should see. SpannerCG runs on Node.js 22.16 or later.

Install as an agent plugin (recommended for engineers)

If your platform team already runs a shared SpannerCG instance, install SpannerCG directly as a plugin in Antigravity, Claude Code, or Codex:

  • Antigravity:

    agy plugin install https://github.com/cloudspannerecosystem/spannercg/plugin
  • Claude Code:

    claude plugin marketplace add cloudspannerecosystem/spannercg
    claude plugin install spannercg@spannercg
  • Codex:

    codex plugin marketplace add cloudspannerecosystem/spannercg
    codex plugin add spannercg@spannercg

After installing, open your agent and ask it to "Set up SpannerCG" (or invoke /spannercg-setup in Antigravity or /spannercg:spannercg-setup in Claude Code) to verify Google Cloud credentials and connect to your team's Spanner instance. You can also run npx -y @google-cloud/spannercg connect once in your terminal (recommended in sandboxed environments like Codex). SpannerCG hot-reloads ~/.config/spannercg/config.json automatically — no restart required.

For Claude Code tool permissions and team-wide automatic repo setup, see Use SpannerCG with your AI agent.

Using other coding agents, or onboarding repos as the platform team? Use the CLI installation below instead.

Install the CLI (platform team and other coding agents)

Platform teams onboarding repositories (setup, census, index, sync) — as well as engineers using other coding agents — should install the CLI globally:

  1. Check your Node.js version:

    node --version

    If the version is below 22.16, install Node.js LTS:

    nvm install --lts && nvm use --lts

    With Homebrew, run brew install node (or brew upgrade node) instead.

  2. Install the CLI:

    npm i -g @google-cloud/spannercg
  3. Confirm that it resolves:

    spannercg --version

Connect as an individual engineer

Your platform team has onboarded the repos. Your whole setup is one command.

  1. Sign in to Google Cloud, then connect this machine. Get the project, instance, and registry database names from your platform team, who also grants you the roles/spanner.databaseReader role on the instance:

    gcloud auth application-default login
    spannercg connect

    The output is similar to the following. Your answers follow the │ marks:

    ┌  Connect this machine to your team's remote codebase knowledge
    │
    ◆  Google Cloud project id
    │  acme-prod
    │
    ◆  Spanner instance id
    │  spanner-code-knowledge
    │
    ◆  Registry database name
    │  spannercg-reg
    │
    ◇  Checking Google Cloud credentials…
    ◇  Checking access to the remote codebase knowledge…
    │
    ●  Connected — 12 repositories are served from this instance.
    ●  Saved to ~/.config/spannercg/config.json. Repos that commit a "repoId" now attach automatically.
    │
    ◆  Add the spannercg server to your coding agents now?
    │  Yes
    │
    └  Done — open any onboarded repo in your agent and just ask.
    
  2. Open an onboarded repo in your coding agent's workspace (Claude Code, Cursor, and others), and ask:

    "How does a payment request reach the database?"

    The answer quotes the relevant source, the call paths between the symbols, and what depends on them. In a repo that isn't onboarded, the agent falls back to its built-in tools.

  3. Ask about repos you haven't cloned. List what the instance serves:

    spannercg repos

    The output is similar to the following:

    Repos on instance spanner-code-knowledge:
    
      acme/payments-service · 6787b7c5 · java, python
      acme/checkout-web · 9f8e7d6c · typescript
      acme/inventory · 55aa01b2 · go
    

    Name any of them in your question:

    "In acme/inventory, how does a stock reservation get released when an order is cancelled?"

    You get the same kind of answer, for a repo you never checked out. If your agent uses its generic tools instead, say "use spannercg" once.

Note: That's the whole engineer setup. For agent configuration details, questions across repos, code search in the dashboard, and troubleshooting, see the detailed guide: Use SpannerCG with your AI agent.

Onboard repos as the platform team

  1. Provision the shared instance once. SpannerCG runs on a Spanner Enterprise edition instance that autoscales between 1 and 3 nodes:

    gcloud auth application-default login
    spannercg setup

    The output is similar to the following. Your answers follow the │ marks:

    ┌  spannercg setup
    │
    ◆  What do you want to do?
    │  Provision or manage the shared instance
    │
    ◇  Checking gcloud credentials…
    ●  Signed in as you@acme.com
    │
    ◆  GCP project
    │  acme-prod
    │
    ◆  Spanner instance
    │  Create "spanner-code-knowledge"   (Enterprise · autoscales 1–3 nodes · recommended)
    │
    ◆  Region config
    │  regional-us-central1
    │
    ◆  Create "spanner-code-knowledge" in acme-prod (regional-us-central1)?
    │  Yes
    │
    ◇  Creating "spanner-code-knowledge"…
    ●  Created "spanner-code-knowledge" ✓
    │
    ◆  Configuration complete — Saved to ~/.config/spannercg/config.json
    │
    └  Ready. Onboard a repo:  cd <repo> && spannercg census  then  spannercg index --scip <artifact>
    
  2. Scope the corpus before you index. census classifies the repo's files and excludes the test fixtures that would degrade answer accuracy:

    cd your-project
    spannercg census

    The output is similar to the following:

    Backend: instance spanner-code-knowledge   (machine config from setup)
    Census — ~/code/payments-service
      1,482 indexable files · 1,210 code · 214 fixtures · 58 generated
    
      language        files            SCIP
      java              861  ████████░░░░  → scip-java
      python            621  █████░░░░░░░  → scip-python
    
    Recommended excludes (written to spannercg.json)
      **/__fixtures__/           −214   test fixtures — snippet/data files that poison name resolution
    
    To be indexed — 1,268 files across these directories (top 3)
      src                                    1,102
      scripts                                  108
      tools                                     58
    
    ✓ Added 1 exclude pattern to spannercg.json
    
  3. Build the graph and publish it. Use SCIP indexes from your CI build; they make symbol references compiler-exact. Pass one --scip per compiler toolchain:

    spannercg index --scip ci-artifacts/scip-java.scip --scip ci-artifacts/scip-python.scip

    The output is similar to the following:

    ℹ Backend: instance spanner-code-knowledge · project acme-prod   (machine config from setup)
    ◆  Publish this repo's codebase knowledge as "acme/payments-service" (database cg-acme-payments-service)?
    │  Yes
    │
    ●  Bound — repoId written to spannercg.json (commit it; corpus settings kept, no cloud coordinates stored)
    ℹ Corpus: excludes from spannercg.json (**/__fixtures__/)
    ┌  Building codebase knowledge
    │
    ◆  Indexed 1,268 files
    │
    ●  18,450 symbols, 61,204 relationships in 24s
    │
    ◆  Remote codebase knowledge: updated 1,268 files (0 unchanged) in 41s
    │
    ◆  Symbol catalog: recorded 1,268 files (0 unchanged) in 6s
    │
    └  Done
    

    Note: spannercg index also works without --scip; symbol references then resolve by best-effort name matching until you add an artifact. To produce the artifacts, see SCIP build recipes.

  4. Commit the repo ID that index wrote. The committed ID is how engineers get access: when they ask questions in a clone, their coding agent reads it to find the repo's knowledge on the shared instance. The file carries only the repo's name and your corpus settings, never a project, instance, or database name:

    git add spannercg.json && git commit -m "spannercg: onboard to shared graph"

    Repeat census and index for each repo. They all share the one instance, and engineers reach any of them by name.

  5. Keep it fresh. After changes merge, sync transfers only the changed files:

    spannercg sync

    The output is similar to the following:

    ┌  Syncing codebase knowledge
    │
    ◆  Synced 3 changed files
    │
    ●  3 modified — 41 symbols updated in 1.2s
    │
    └  Done
    
  6. See the instance. List what's indexed:

    spannercg repos

    The output is similar to the following:

    Repos on instance spanner-code-knowledge:
    
      acme/payments-service · 6787b7c5 · java, python
      acme/checkout-web · 9f8e7d6c · typescript
      acme/inventory · 55aa01b2 · go
    

    To watch it live instead, start the dashboard:

    spannercg status --dashboard

    The output is SpannerCG status dashboard is live at http://127.0.0.1:7317/. The page refreshes itself:

    SpannerCG status dashboard
  7. Remove a repo when its graph is no longer needed:

    spannercg drop-repo acme/payments-service

    The command shows what it will delete and asks you to type the repo ID to confirm. Pass --yes in scripts. The output is similar to the following:

    ┌  Deleting the remote codebase knowledge for "acme/payments-service"
    │
    ◇  This deletes ────────────────────────────────────────────────╮
    │                                                               │
    │  graph database   cg-acme-payments-service                    │
    │  registry rows    1,268 files · 18,450 defs · 61,204 refs     │
    │  last indexed     6787b7c5fb4b                                │
    │  local spannercg.json keeps its repoId and excludes —         │
    │  a re-index reuses them                                       │
    │                                                               │
    │  Attached readers lose access until the repo is re-indexed.   │
    │                                                               │
    ├───────────────────────────────────────────────────────────────╯
    │
    ●  registry: repo record removed
    │
    ●  graph: database cg-acme-payments-service dropped
    │
    ◆  Kept your corpus settings (1 exclude pattern) — a re-index will use them.
    │
    └  Re-index anytime:  spannercg index
    

Note: These six steps cover one repo's happy path. For syncing from CI, dropping and re-adding repos, monitoring, and troubleshooting, see the detailed guide: Manage repos on the shared instance.

Configure your agents

spannercg connect offers this step at the end. To run it separately:

spannercg install

The installer lists the detected agents — Claude Code, Cursor, Codex CLI, opencode, Hermes Agent, Gemini CLI, Antigravity, and Kiro — and marks each one configured. Restart your agent session afterward; agents read MCP configuration at session start.

To confirm that it works, ask your agent a "how does X work?" question and check that it calls spannercg_explore. One call should answer it.

To remove the server from every agent it was installed into:

spannercg uninstall

Project graphs and your machine configuration are left untouched. To remove the CLI itself, run npm uninstall -g @google-cloud/spannercg.

Run locally with Spanner Omni instead of Cloud Spanner

To run SpannerCG entirely on your own machine without a Google Cloud project, gcloud, or ADC credentials, use Spanner Omni in Docker (see the Spanner Omni setup guide and editions and licensing overview). Spanner Omni mode is intended for local single-machine experimentation and development; for shared team or enterprise production deployments, use Google Cloud Spanner:

  1. Start the local Spanner Omni container with --network host, --cpus=4, and a named Docker volume (-v spannercg-omni:/spanner) so your catalog and graph databases persist across container restarts:

    docker run -d --name spannercg-omni --network host --cpus=4 -v spannercg-omni:/spanner \
      us-docker.pkg.dev/spanner-omni/images/spanner-omni:2026.r4-lts.1 start-single-server

    Platform & resource notes:

    • Linux x86_64: Run the docker run command above directly. Spanner Omni's start-single-server mode binds its internal and gRPC API services strictly to loopback (127.0.0.1:15000), so --network host is required (-p 15000:15000 bridge forwarding cannot reach loopback inside the container).
    • macOS: See the Spanner Omni setup documentation. If you run the container under Docker Desktop, host networking (opt-in, Docker Desktop 4.34+: Settings -> Resources -> Network -> Enable host networking) is required.
    • CPU & memory sizing: The example above uses --cpus=4 (Spanner Omni recommends 4 GB of RAM per vCPU, or 16 GB at --cpus=4; use --cpus=2 on memory-constrained workstations). For edition and licensing details, see the Spanner Omni editions overview.
  2. Configure this machine for local Spanner Omni (or run spannercg setup interactively and choose Use local Spanner Omni):

    # Default local Spanner Omni gRPC port (localhost:15000)
    spannercg setup --backend omni
    
    # Or specify a custom local loopback port (for example, localhost:15001)
    spannercg setup --backend omni --endpoint localhost:15001

    setup verifies that the target endpoint is healthy (SERVING), bootstraps the local codegraph-registry catalog database, saves { "backend": "omni", "endpoint": "localhost:15000", "registryDatabase": "codegraph-registry" } (or your custom --endpoint) to ~/.config/spannercg/config.json, and offers to wire MCP into your local coding agents. To switch an already-configured machine to a different local port later, pass --reconfigure (for example, spannercg setup --backend omni --endpoint localhost:15001 --reconfigure).

  3. Index and manage repositories locally on your machine:

    cd your-project
    spannercg census
    spannercg index --store-source

    From then on, spannercg sync, spannercg repos, spannercg status --dashboard, spannercg drop-repo, and spannercg_explore in your coding agent all work against omni @ localhost:15000.

    • Note on drop-repo with Spanner Omni: Because Spanner Omni executes DropDatabase lazily in the background, spannercg drop-repo verifies that the wiped database is clean and retains an empty database shell (graph: verified clean (<db> — empty database shell kept for re-index on Omni)) so an immediate spannercg index on the same repo can re-index cleanly without racing a background drop.
    • Note for SpannerCG contributors: Running the *-omni.test.ts integration suites against a local container (SPANNERCG_OMNI_ENDPOINT=127.0.0.1:15000) creates and drops only run-scoped temporary databases (cg-*) in afterAll, leaving your local codegraph-registry and indexed repos untouched.

Documentation

The quick start above covers the main path. The guides cover the rest:

Language support

Every supported language gets the same treatment: full structural extraction and cross-file resolution into one graph, with no per-language setup.

TypeScript · JavaScript · ArkTS · Python · Go · Rust · Java · C# · VB.NET · PHP · Ruby · C · C++ · CUDA · Objective-C · Metal · Swift · Kotlin · Scala · Dart · Lua · Luau · R · Nix · Erlang · CFML · COBOL · Solidity · Terraform/OpenTofu · Svelte · Vue · Astro · Liquid · Pascal/Delphi

Compiler-verified accuracy through --scip is available for TypeScript/JavaScript, Python, Java, Kotlin, C#, Go, Rust, Ruby, and C/C++. Every other language indexes with best-effort reference resolution.

Multi-language repos index into one graph across all their languages. Pass a separate SCIP artifact per language, such as spannercg index --scip scip-java.scip --scip scip-python.scip, so each language gets compiler-verified accuracy.

License

Licensed under the MIT License.

SpannerCG is based on and derived from CodeGraph by Colby Mchenry, originally released under the MIT License. Both copyright notices are preserved in LICENSE.

Security & Terms

Eligibility for the Google Open Source Software Vulnerability Rewards Program is determined by the Google Open Source Software Vulnerability Reward Program Rules.

Use of Google Cloud Spanner is subject to the Google Cloud Terms of Service.

About

Spanner Code Graph empowers coding agents with enterprise codebase context.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages