CostWise
Local-First Repository Intelligence

Coding agents should behave like experienced engineers.

An experienced engineer does not re-read the same files every turn, rediscover the same symbols, or carry a 5,000-line log in memory. CostWise gives your AI coding agent the same instincts — from a local index, not from file dumps.

$curl -fsSL https://raw.githubusercontent.com/okyashgajjar/costwise-mcp/main/install.sh | bash
Works withClaude CodeCursorCodexOpenCodeAntigravity
costwise --serve
logs
_
Savings RateActive
Index Sync8ms
Egress Data0 KB
100%
Local-firstNo data ever leaves your machine
See it in action

Without CostWise vs with

Same task. Same model. The left side reads files. The right side uses the index.

WithoutNaive file reads — no index
OpenCode without CostWise — many tool calls, high token count Watch video
WithIndex-backed tool calls
OpenCode with CostWise — minimal tool calls, low token count Watch video
The problem

Why long sessions get expensive

The expensive part is not the model's output. It is everything around it.

Repositories get re-explored

Ask your coding agent "where is X defined" and it reads the file. Ask again five minutes later — it reads the same file again. Each read puts thousands of tokens into the context window.

2-5x redundant file reads per session

Context grows without being useful

A typical session starts small. Then the model dumps a file to answer a question. Then a test output. Then a build log. None of these leave — they accumulate in the resident context window.

Accumulated context persists across turns, driving up costs

The prompt cache makes it worse

Every turn pays to read the entire resident context. Any change or idle gap forces a full rewrite. In one measured call, $2.84 of a $2.95 charge was the cache write — the output was under 4K tokens.

Cache writes dominate API cost vs actual output
How CostWise fixes it

One lever: shrink the context window

A server cannot control how the client caches. It can only control how many tokens ever enter the window.

Answer from a local index

Navigation questions — "where is this defined", "who calls this" — are answered from a Tree-sitter SQLite index in a few tokens instead of by dumping source files.

Remember facts instead of repeating

The remember tool persists a durable fact per repository. The recall tool retrieves it later. Facts are written down once instead of re-derived every turn.

Stash large output instead of pasting

Stash_context parks a large blob out of context behind a ~20 token handle. Recall pulls back only the matching slice, within a token budget. Lossless.

Session-awareness skill

A 275-token guidance delivered to every MCP client teaches the model the lean workflow automatically. Also installable as a native Claude Code skill.

Why teams use it

Built for cost, speed, and privacy

Four properties that hold no matter how large the repository gets.

100% Local-First

All indexing, SQLite queries, and AST parsing run locally. No telemetry, no code egress.

MCP Compatible

Plugs into Claude Code, Cursor, Codex, OpenCode, Antigravity, and any stdio MCP client.

Incremental Sync

A file watchdog re-indexes only changed files on save, so the index stays fresh without full rebuilds.

Context Control

Returns compressed scopes, budgeted summaries, and out-of-context stashes instead of bloated files.

Context control

Stash the monster, recall the slice

Three tools form one loop that keeps the window small without ever losing information.

1

stash_context

A 5,000-line log goes to disk and returns a ~20 token handle instead of flooding the window.

2

recall

Pull back only the lines that match your query, trimmed to a token budget.

3

remember

Keep the durable conclusion as a fact so it is never re-derived next turn.

The costwise-session skill teaches your editor to do this automatically, delivered to every MCP client through the protocol's instructions field.

The toolset

Eleven tools, one goal

Retrieval answers questions in a few tokens. Context-control keeps large content and durable facts out of the window entirely.

search_coderetrieval

Semantic AST search that returns relevant scopes, not whole files.

find_symbolretrieval

Resolve a definition to a location in a single index lookup.

read_symbolretrieval

Return a symbol's implementation body by name, from the indexed line range.

find_referencesretrieval

Every usage of a symbol, precomputed for impact analysis.

find_callersretrieval

Who calls this function, from stored call edges.

get_repository_summarymaintain

Token-budgeted repo map with drill-down. Stays small on any repo.

index_repositorymaintain

Manual re-index. Usually unnecessary; the watchdog handles it.

remembercontext

Persist a durable fact per repository so it is never repeated inline.

stash_contextcontext

Park a large blob out of context; get back a tiny handle. Lossless.

recallcontext

Pull back only the slice a query needs, from a stash or from facts.

session_briefcontext

Compact summary of past sessions — facts, stashes, reindex events.

System layout

Architecture

Hover or click components in the flow diagram to inspect each module.

MCP Server Transport

Handles Model Context Protocol messages over local stdio, registers the ten tools, and advertises the costwise-session guidance through the protocol instructions field so every client receives it automatically.

Relevant repository paths
  • internal/mcpserver/server.go
  • internal/mcpserver/tools.go
  • internal/skill/
Static analysis

How retrieval works

CostWise indexes code structurally with Tree-sitter. Explore it live in the AST simulator.

import * as fs from 'fs';
import * as path from 'path';
 
interface ServerSetting {
command: string;
args: string[];
}
 
export function loadConfig(configPath: string): ServerSetting {
const raw = fs.readFileSync(path.resolve(configPath), 'utf-8');
return JSON.parse(raw) as ServerSetting;
}
Click Index File to underline declarations and references
Local watchdog idle
Parsing speed--
Tokens after compression--
Context reduction--

Extracted AST nodes

No nodes yet. Index the file to extract them.
Module maps

Codebase inspector

Browse the actual CostWise codebase to verify its structure.

Repository Modules
📦

internal/retriever

Semantic Search Engines

Implements the core 9 indexing algorithms (treesitter, grep, fts, auto, naive) for semantic code retrieval.

Files Count11 source files
Access BoundaryLocal Stdio only
Compiled AST Symbols
structtype Retriever interface
funcfunc (t *TreeSitter) Retrieve()
funcfunc (a *AutoRouter) Route()
Setup

Editor configurator

Select your IDE to generate a setup profile.

Config Location:~/.claude.json
settings.json
{
  "mcpServers": {
    "costwise": {
      "command": "costwise",
      "args": ["serve"]
    }
  }
}
Comparisons

CostWise vs alternatives

How it compares to dependency graphs and plain text search.

CodeGraph

Scoped AST lookups instead of heavy code-graph pointer files.

Serena

Restores offline parsing without cloud data egress.

Graphify

Optimized symbol arrays instead of complex spatial coordinates.

ripgrep

Retrieves logical scopes rather than noisy text lines.

Questions

Frequently asked

Indexing, token optimization, and IDE integration.

How does it save prompt tokens?

It returns structural declarations and scopes from a local index instead of whole files, and lets the model park large output out of context, trimming input significantly.

Does my code leave my machine?

No. All parsing and SQLite index writes happen locally. There are no API keys and no cloud indexing.

How is this different from grep or ripgrep?

grep returns lines. CostWise understands structure — it knows where a function body starts and ends, who calls it, and what it references. From a pre-built index, in microseconds.

Does it work with any LLM provider?

It works with any editor that supports MCP tools — Claude Code, Cursor, OpenCode, Codex CLI, and any stdio-based MCP client.

Save context. Write code.

Install the local-first repository intelligence server and keep your AI coding sessions fast, private, and token-efficient.

$curl -fsSL https://raw.githubusercontent.com/okyashgajjar/costwise-mcp/main/install.sh | bash