HTTP API
The worker exposes a local HTTP API at http://localhost:3848. It’s the lowest-level surface — the CLI and MCP server both sit on top of it. Localhost-only by default, no auth required.
Conventions
- Base URL:
http://127.0.0.1:3848(configurable viaworkerPort) - Content type:
application/jsonfor all requests and responses - Auth: none. Bind to
127.0.0.1only — if you expose to a network, add a reverse proxy with auth in front. - CORS: not set by default. Do not call this API directly from an untrusted browser context.
Health
Sanity check. Returns the worker status and a savings overview snapshot.
{
"ok": true,
"dbPath": "~/.contextpilot/contextpilot.db",
"savings": {
"estimatedTokensSaved": 340210,
"estimatedCostSavedUsd": 4.20
}
}Hooks
Ingest one hook event. Body matches the hook event schema.
{
"kind": "tool_use",
"agent": "claude",
"projectRoot": "/home/me/repo",
"sessionId": "sess_abc",
"toolName": "edit_file",
"input": { "filePath": "src/auth.ts", "diff": "..." },
"timestamp": 1716422400000
}{
"ok": true,
"ok": true
}Ingest many events at once. Use when your hook fires more than ~10 events/second.
{ "events": [ /* HookEvent[] */ ] }Memories
Max rows to return. Default 50. Cap 500.
{
"memories": [
{
"id": "mem_e7f3a1",
"type": "file_edit",
"title": "Added Stripe webhook validation",
"content": "...",
"files": ["src/api/payments/webhook.ts"],
"confidence": 0.94,
"reuseCount": 4,
"estimatedTokens": 3200,
"estimatedTokensSaved": 12800,
"estimatedCostUsd": 0.0096,
"estimatedCostSavedUsd": 0.0384,
"archived": false,
"createdAt": 1716422400000
}
]
}Fetch one full memory by ID.
New title. Optional.
New content. Optional.
Manually override the confidence score. Useful for pinning critical memories.
Set true to archive, false to unarchive.
Archives the memory.
Create a manual memory. Same as MCP contextpilot_remember.
{
"projectRoot": "/home/me/repo",
"title": "Auth uses JWT exp claim",
"content": "We standardized on exp, not iat.",
"files": ["src/auth/middleware.ts"]
}Search
Full-text search across memory title and content. Uses SQLite FTS5 under the hood — fast, ranked, supports prefix queries.
The query string. Supports FTS5 syntax: quoted phrases, + for required terms, - for excluded.
Default 8. Cap 50.
curl 'http://127.0.0.1:3848/api/search?q=stripe+webhook&limit=3'Sessions
Default 50. Cap 500.
{
"sessions": [
{
"id": "sess_abc",
"projectId": "proj_xyz",
"agent": "claude",
"model": "claude-sonnet-4-6",
"startedAt": 1716422400000,
"endedAt": 1716423200000,
"estimatedTokens": 45200,
"estimatedCostUsd": 0.34
}
]
}Projects
List every project ctxpilot has captured events for.
{
"projects": [
{ "id": "proj_xyz", "name": "my-app", "rootPath": "/home/me/repo", "lastSeenAt": 1716422400000 }
]
}Events
Recent ingest events. Used by contextpilot events.
Default 50. Cap 500.
{
"events": [
{
"id": "evt_5f2",
"sessionId": "sess_abc",
"agent": "claude",
"eventKind": "tool_use",
"toolName": "edit_file",
"status": "stored",
"memoryId": "mem_e7f3a1",
"processedMs": 4,
"createdAt": 1716422401200
}
]
}Analytics
All-time savings rollup. Same data shown by contextpilot status.
{
"estimatedTokensSpent": 1248321,
"estimatedTokensSaved": 340210,
"estimatedCostSpentUsd": 12.40,
"estimatedCostSavedUsd": 4.20,
"repeatedReads": 847,
"memoriesCreated": 847,
"memoriesReused": 213,
"projectedMonthlySavingsUsd": 16.80
}How many savings traces to return. Default 10.
Returns the top-reused memories with proof and recommendation strings — what powers contextpilot savings.
Findings of repeated reads used by CLI waste reports.
{
"findings": [
{
"filePath": "src/auth/middleware.ts",
"reads": 47,
"estimatedTokensWasted": 141000,
"estimatedCostWastedUsd": 0.42,
"recommendation": "Read 47×. Pin a memory to save ~141K tokens/month."
}
]
}Operational metrics for the hook pipeline — events per minute, dedup rate, error rate, avg processing time. Useful when debugging ingest performance.
Errors
Beta errors return a small JSON body:
{
"error": "not_found"
}The error format will become stricter before the public package launch.
Rate limiting
The worker doesn’t rate-limit by default (it’s your machine). Internally it caps to ~10,000 events/sec to keep SQLite happy. If you saturate that, batch with POST /api/hooks/batch.