-
-
Notifications
You must be signed in to change notification settings - Fork 4
Index Management
CKB automatically keeps your SCIP index up-to-date using several mechanisms. This page explains how index refresh works and how to monitor it.
CKB offers multiple ways to keep your index fresh:
| Method | Latency | Best For |
|---|---|---|
Manual (ckb index) |
Immediate | On-demand updates |
| Daemon file watcher | ~7s | Always-on development |
| MCP watch mode | ~10s | IDE sessions |
| Webhooks | Immediate | CI/CD integration |
The daemon handles branch switches automatically. No git hooks needed.
When using the daemon, branch switches are detected within seconds:
- You run
git checkout feature-branch - Git updates
.git/HEAD - Daemon detects the change (polling
.git/HEADevery 2s) - After 5s debounce, reindex triggers automatically
- Total latency: ~7 seconds worst case
For MCP-only users (no daemon), watch mode provides similar functionality:
# Default 10s polling interval
ckb mcp --watch
# Faster polling (5s minimum)
ckb mcp --watch --watch-interval 5sCKB tracks what triggered each index refresh. You can see this in the getStatus MCP response:
{
"lastRefresh": {
"at": "2024-12-25T10:00:00Z",
"trigger": "head-changed",
"triggerInfo": "branch or commit changed",
"durationMs": 1200
}
}| Trigger | Description | Source |
|---|---|---|
head-changed |
Branch switch or new commit | Daemon/MCP watching .git/HEAD
|
index-changed |
Staged files modified | Daemon watching .git/index
|
manual |
CLI ckb index command |
User action |
scheduled |
Daemon scheduler | Cron-like schedule |
webhook |
External webhook trigger | CI/CD or external system |
stale |
Generic staleness detection | Polling detected changes |
The daemon provides the most responsive index refresh:
# Start daemon
ckb daemon start
# Check what it's watching
ckb daemon statusThe daemon uses polling (not fsnotify) for simplicity and cross-platform compatibility:
-
.git/HEAD- Detects branch switches and new commits (content comparison) -
.git/index- Detects staged file changes (modification time)
Polling intervals:
- File check: every 2 seconds
- Debounce: 5 seconds (batches rapid changes)
{
"daemon": {
"watch": {
"enabled": true,
"debounceMs": 5000,
"ignorePatterns": ["*.log", "node_modules/**", ".git/objects/**"]
}
}
}See Daemon-Mode for complete daemon configuration.
For users running CKB via MCP without the daemon:
# Enable watch mode with default 10s interval
ckb mcp --watch
# Custom interval (5s to 5m)
ckb mcp --watch --watch-interval 15sMCP watch mode uses polling only (no file watchers). It periodically checks CheckFreshness() which compares:
- Current HEAD commit vs indexed commit
- Current repo state ID vs indexed state ID
- Uncommitted changes
When staleness is detected, it triggers a reindex automatically.
ckb statusShows:
- Current index state
- Commits behind HEAD
- Index age
- Last refresh info (if available)
The getStatus tool returns comprehensive freshness info:
{
"repoState": {
"commit": "abc123",
"branch": "feature/auth",
"dirty": false
},
"lastRefresh": {
"at": "2024-12-25T10:00:00Z",
"trigger": "head-changed",
"triggerInfo": "branch or commit changed",
"durationMs": 1200
}
}The reindex MCP tool triggers index refresh without leaving your AI session:
// Check if reindex is needed
{ "tool": "reindex", "params": { "scope": "incremental" } }
// Force full reindex
{ "tool": "reindex", "params": { "scope": "full" } }Scope options:
-
incremental— Only changed files (Go only, default) -
full— Reindex everything
Response types:
-
skipped— Index is fresh, no action needed -
action_required— Index is stale, manualckb indexneeded -
started— Async reindex started -
completed— Reindex completed successfully
meta, _ := index.LoadMeta(ckbDir)
freshness := meta.CheckFreshness(repoRoot)
if !freshness.Fresh {
fmt.Printf("Stale: %s (%d commits behind)\n",
freshness.Reason, freshness.CommitsBehind)
}Force an immediate reindex:
# Standard reindex
ckb index
# Force full reindex (ignores incremental)
ckb index --forceFor CI/CD pipelines, use webhooks to trigger refresh:
# Trigger refresh via daemon API
curl -X POST http://localhost:9120/api/v1/refresh
# Full reindex
curl -X POST http://localhost:9120/api/v1/refresh -d '{"full":true}'See CI-CD-Integration for complete CI/CD setup.
-
Check if daemon is running:
ckb daemon status -
Check last refresh: Use
getStatusMCP tool -
Force refresh:
ckb index
- Verify daemon is watching the repo:
ckb daemon status - Check logs:
~/.ckb/daemon.log - Ensure
.git/HEADexists and is readable
- Check watch is enabled: should see "Watch mode enabled" in stderr
- Reduce interval:
--watch-interval 5s - Check for lock contention: another process may be indexing
Why polling instead of fsnotify?
CKB uses polling for file watching because:
- Cross-platform consistency (fsnotify has platform-specific edge cases)
- Simpler implementation and debugging
- 2s poll interval is imperceptible for most workflows
- Avoids inotify watcher limits on Linux
The 7s worst-case latency (2s poll + 5s debounce) is acceptable for the "instant reindex on branch switch" use case.
- Daemon-Mode - Complete daemon configuration
- Incremental-Indexing - How incremental updates work
- CI-CD-Integration - CI/CD webhook setup
- Configuration - All configuration options