Diff Index (diff_index)
diff_index is Kompile's searchable, filterable, sortable index of historical file edits and unified diffs made by coding agents across sessions — plus version-controlled draft revisions, applies, and reverts (kompile-draft).
Unlike grep (which only sees current files on disk) or file_activity (which only tracks path-level change notifications), diff_index queries the actual oldString, newString, and unifiedDiff payloads mined from coding-agent transcripts and draft commits — including edits to untracked files that Git never saw.
What diff_index is (and is not)
diff_index is transcript- and draft-derived edit history, not Git history or a filesystem undo log:
- It covers untracked files whenever an agent edit or draft recorded them.
- Confirmed error results are excluded where extractors can correlate tool outcomes, though an invocation record alone is not proof that a disk write survived later manual edits.
- Deleted or unavailable provider transcripts cannot be recovered once removed from disk.
Choosing between diff_index, /diffs, and sibling tools
| Need | Best Tool | Why |
|---|---|---|
Search historical old/new text or unified diffs across sessions, agents, or drafts | diff_index (action=search, action=get) | Structured edit payloads with path globs, agent/source/session/time filters, and sorting |
| Glance at the latest edits in this active chat session | /diffs [count] | Reads the tail of the current session's live tool-call journal directly (instant, zero index scan; default 20, range 1–100) |
| Search current file contents on disk | grep / grep_batch | Live workspace text/regex search |
| See if another parallel agent just touched a file you read | file_activity | Live path-level read/write notifications |
| Search raw conversation prose or non-edit tool calls | transcript_search / tool_call_catalog | Full transcript text or general tool-call catalog |
| Stage, rebase, apply, or revert uncommitted edits | draft / draft_batch | JGit-backed .kompile/drafts.git commits (automatically mirrored into diff_index) |
What gets indexed & where it lives
Storage scopes
In local CLI / MCP mode (default), diff_index is strictly project-scoped unless you opt into global cross-project lookup:
| Scope | Parameter | Storage Path |
|---|---|---|
| Project (default) | scope="project" | <project>/.kompile/agent-state/diff-index/ |
| Global (cross-project) | scope="global" | ~/.kompile/agent-state/diff-index/ |
DiffIndexService keeps only lightweight entry metadata in memory and hydrates full oldString/newString/unifiedDiff payloads on demand through a bounded LRU content cache (up to 64 entries / 8 MiB), so large edit histories stay fast and memory-safe.
Mined sources & edit tools
DiffIndexService automatically extracts file-edit tool calls across major coding-agent transcripts and Kompile's own draft store:
- Transcript sources: Claude Code (including durable
<session>/subagents/*.jsonlworker transcripts and legacy task outputs, retaining worker provenance without double-counting duplicate tool IDs), Codex, OpenCode, Qwen, Cline, Cursor, Continue, Aider, Gemini, Pi, and Kompile structured journals. - Mined edit tools:
edit,write,edit_batch,edit_patch,patch,apply_patch,apply_diff,edit_file,write_file,write_to_file,replace_in_file,insert_code_block,create_file,str_replace_editor,file_editor,notebookedit(plus extractable shell file writes). Multi-file calls (edit_batch,edit_patch, and pathless multi-file patches) are expanded and deduplicated per individual edit. - Draft revisions, applies & reverts (
DraftDiffIndexFeed): Everydraftcreate,revise,rebase,apply, andrevertwrites deterministic entries (source="kompile-draft",toolName="draft",diffType="draft" | "draft-apply" | "draft-revert") carryingmodel,draftId, andcommitIdinto both the project and global diff indexes.
MCP tool reference (diff_index)
diff_index is a read-only tool in the code MCP tool group (permissionKey="read").
Actions
| Action | Required params | What it returns |
|---|---|---|
search | (all optional) | Filtered, sorted, paged list of edit entries (metadata + matching snippets by default; pass include_content=true for full payloads) |
get | id | Full DiffIndexEntry for one entry (oldString, newString, unifiedDiff, agent, source, sessionId, transcriptId, model, draftId, commitId, timestamp, line counts) |
session | session_id | Paged edits belonging to a single parent session or worker transcriptId |
sessions | — | Per-session aggregate counts across indexed transcripts |
projects | — | Indexed project directories with entry counts |
agents | — | Indexed coding agents with entry counts |
stats | — | Total entries, indexing status (indexing: true/false), and scope metadata |
refresh | — | Requests a rescan of growing local transcripts (in remote mode, use POST /api/diff-index/reindex) |
Parameters
| Parameter | Type | Applies to | Description |
|---|---|---|---|
action | string | All (required) | search, get, projects, agents, sessions, session, stats, or refresh |
scope | string | All (local mode) | project (default — current project directory) or global (cross-project user index) |
query | string | search, session | Case-insensitive substring matched across file path, old text, new text, and unified diff |
file_path | string | search, session | File path substring or glob pattern (e.g. src/**/*.java, JitGraphBackendCommon.cu) |
project | string | search | Project directory path or project-name substring |
agent | string | search, session | Exact coding-agent name (e.g. claude-code, codex, opencode) |
source | string | search, session | Exact transcript source name, or kompile-draft for draft revisions/applies/reverts |
session_id | string | session (required), search | Parent session ID or worker transcriptId |
since | string | search, session | Inclusive ISO-8601 timestamp/date lower bound (explicit offsets supported, e.g. 2026-10-25T16:30:00+09:00) |
until | string | search, session | Inclusive ISO-8601 timestamp/date upper bound |
sort_by | string | search, session | timestamp (default), file_path, project, agent, source, lines_added, lines_removed, or total_changes |
sort_dir | string | search, session | desc (default) or asc |
limit | integer | search, session | Page size from 1 to 100 (default 20) — page size only, not a total history cap |
offset | integer | search, session | Zero-based entry offset (default 0); pass returned metadata.next_offset to continue paging |
include_content | boolean | search, session | Include full oldString, newString, and unifiedDiff inline (default false; 600-char matching snippets are still shown) |
id | string | get (required) | Diff entry ID to fetch in full |
Practical workflows (ask in chat or run /diffs)
You never need to write query JSON by hand — ask your agent in plain English and it calls diff_index with the exact filters and paging automatically:
1. Trace every edit to a file across a time window
Ask in chat: "Use
diff_indexto show every edit made toAgenticChatLoop.javabetween Dec 1 and Dec 4, oldest first."
The agent searches file_path="src/**/AgenticChatLoop.java" with since/until bounds and sort_by="timestamp", sort_dir="asc", automatically paging with next_offset whenever has_more is true.
2. Find who removed or changed a specific symbol
Ask in chat: "Search
diff_indexforCliToolGatewayInterceptor, newest first, and show me the full unified diff for the commit where it was modified."
The agent searches matching snippets first (keeping context small), then pulls only the target entry's full before/after diff via diff_index (action="get").
3. Inspect draft revisions, applies, and reverts
Ask in chat: "List recent draft revisions, applies, and reverts from
diff_index(source=kompile-draft)."
Returned entries show diffType (draft, draft-apply, or draft-revert), model, draftId, and commitId.
4. Find the largest edits in a session
Ask in chat: "Show the 25 largest file edits from session
<session-id>sorted by total changed lines."
The agent queries diff_index (action="session", sort_by="total_changes", sort_dir="desc") across either a parent chat session or a specific worker transcriptId.
Pagination, refresh, and timestamp semantics
- Paging beyond 100 results:
limit(1–100) is a page size, not a history cap. Followmetadata.next_offsetwhilehas_more=true. Offset pages are not frozen snapshots — when investigating an active session, pass explicitsince/untilbounds to prevent shifting pages. - Background vs. explicit refresh: Local mode throttles automatic background rescans (30-second cooldown after each scan). Call
diff_index(action="refresh")when you need edits from a session that is actively growing, then polldiff_index(action="stats")untilindexingisfalsebefore paging. - Timestamps & legacy sources: Claude, Codex, and Kompile structured journals preserve per-call invocation timestamps and call IDs. Legacy extractors that lack per-call timestamps fall back to session file modification time (never reindex time).
- Reindexing stability: Re-reading growing sessions deduplicates individual edits and upgrades matching legacy entries in place while retaining their IDs; distinct repeated edits remain distinct.
Interactive /diffs & Server REST API
Quick session view in chat (/diffs)
Inside kompile chat and the Web Harness, /diffs [count] (default 20, range 1–100) prints recent edit tool calls for the current session newest-first directly from the session's live tool-call journal — without building or querying the cross-session diff index.
/diffs # Newest 20 edit calls in this session
/diffs 50 # Newest 50 edit calls in this sessionServer REST API (kompile-app-main :8080)
When running the distributed admin server (kompile-app-main on :8080, or when diff_index is configured with a remote server --url), the same DiffIndexService is exposed via /api/diff-index:
| Method | Endpoint | Purpose |
|---|---|---|
GET | /api/diff-index/search | Query by agent, projectDirectory, filePath, contentQuery, source, since, until, sessionId, sortBy, sortDir, limit, offset |
GET | /api/diff-index/entries/{id} | Retrieve one full DiffIndexEntry |
GET | /api/diff-index/projects | List indexed projects |
GET | /api/diff-index/agents | List indexed agents |
GET | /api/diff-index/sessions | List indexed sessions with aggregates |
GET | /api/diff-index/sessions/{sessionId} | List all diff entries in one session |
GET | /api/diff-index/stats | Index totals and active indexing status |
POST | /api/diff-index/reindex | Trigger an asynchronous server-side reindex |
Related guides
- Coding Tools Overview — How all coding tools fit together
- Draft Workflow (
draft&draft_batch) — How draft revisions, applies, and reverts feeddiff_index(source=kompile-draft) - File Context, Notes & Activity — Live per-file context dossiers and multi-agent read/write notifications
- Automatic Test Milestone Recording — Pairing historical edits with observed test milestones
- Auditing & Provenance — How
diff_indexfits into Kompile's compaction-safe audit trail - CLI Transcript Storage — Low-level storage, deduplication, and retention invariants