# Doctor and the index

`tkt doctor` finds what is wrong in a store and points at `tkt index rebuild` where needed.

## `tkt doctor`

Checks every file of the store and never stops at the first problem (`tkt lint` judges one ticket). Exit 0 clean, 1 info, 2 warning, 3 error, 4 could not run (no store; stdout stays empty even with `--json`); `--strict` makes warnings 3, info never escalates. A broken file is a finding (`ERR_FILE_PARSE`, 3), reported once. `--fix-index` rebuilds the index ([The index](#maint-index)); the codes: [the doctor table](/en/docs/reference/doctor.md#ref-doctor).

### Details

- Run it after every merge ([After a merge](/en/docs/guides/team/git.md#maint-merge-damage)). A broken file is never also a dangling ref or drift; `--fix-index` rebuilds a drifted, missing or unreadable index.
- Times: the store keeps every event as a UTC timestamp, to the second (`2026-11-10T12:00:00+00:00`): `createdAt`, `updatedAt`, `closedAt`, a doc's or gotcha's `timestamp`, a decision's `decidedAt`, a release's `shippedAt`. Days stay days: `targetDate`, a decision's `date`, `--shipped-at`. An old local-offset time stays readable and becomes UTC the next time the item changes; `--fix-times` converts them all in one run to the same moment in UTC, leaves the days and prints what it changed. It never runs by itself.
- Mentions naming nothing: `DANGLING_MENTION` (`doc://`, `gotcha://`), `DANGLING_DECISION` (`decision://D9` or bare `D9`), with a did-you-mean as in the bundle.
- Anchoring (`info`, never in the exit code): docs and gotchas that build on no decision; the list: `tkt review --unanchored`.
- Report lines, never findings: `counter: store` or `counter: git: <path>` ([parallel worktrees](/en/docs/guides/team/worktrees.md#team-worktrees)); in git `merge drivers: installed` / `not installed` / `<view> not covered`, hint `tkt git install` ([merge drivers](/en/docs/guides/team/git.md#team-git)).

- `tkt doctor` groups the findings per file (severity, code, field, message, `hint:`), then the counts; a clean store prints `✓ store is healthy`. `--json`: `{ok, counts, findings[], index, counter, mergeDrivers}`; `ok` only on exit 0.
- Anchoring lines: one `EDGE_COVERAGE` per edge declared for coverage (`coverage: decisions without affects 31 of 353 (9 %)`, open items only); `UNANCHORED` (critical gotchas counted apart), `ORPHANED` (no `appliesTo` and nothing refers to it), `UNTOUCHED_UNANCHORED` (unanchored and unchanged for `untouchedDays`, 90). `tkt review --unanchored [--older 90d]` `--json`: `{unanchored[], olderDays}`, each `ref, kind, title, buildsOn, stress, orphan, changedAt, days`; the age is the `timestamp`, else the last git commit.

## The index

The SQLite index `.aitodo/index.db` is derived from the Markdown files: the file always wins; it is gitignored and safe to delete. Every CLI write keeps it in sync, and `search`, `graph`, `tree` reconcile on read (hand edits, `git checkout`, deleted files), so a rebuild is rarely needed.

- `tkt index rebuild`: a full rebuild in one transaction, only after bulk external changes or corruption; a file it cannot index (`ERR_FILE_PARSE`, or `ERR_INDEX_REBUILD` for a duplicate prefix or ULID) leaves the old index, exit 1. It is also the full re-check: after a write outside tkt (an editor, a merge, a new `tkt`) line 1 is `WARN N open review(s)` with `→ tkt review`; `--quiet` prints only that line, and only when one is open (the `tkt git install` hook runs it).
- `tkt index status`: the counts, the last rebuild, the path; it does not reconcile.

### Details

- The first write into a store without `index.db` builds it. An index failure never fails the write: the `.md` is saved and stderr says `index not updated (…)`.
- `tkt doctor`: `ERR_INDEX_DRIFT` (info: a stale row, a row without file, a file without row), `ERR_INDEX_CORRUPT`. `--fix-index` rebuilds, also a missing index (without it doctor never creates `index.db`); a failed rebuild is an `ERR_INDEX_REBUILD` error and the old index stays.

- `tkt index status` fields: `ticket_count`, `group_count`, `last_rebuild_at` (`null` until a full rebuild), `db_path`.
- `tkt index rebuild --json` (and `POST /v1/index:rebuild`): the counts and `openReviews`, the `tkt review --json` items.

## Commands on this page

- [`tkt doctor`](/en/docs/reference/commands/maintenance.md#tkt-doctor): Check the whole store's integrity; exit 0 clean · 1 info · 2 warning · 3 error · 4 could not run (no workspace)
- [`tkt index rebuild`](/en/docs/reference/commands/maintenance.md#tkt-index-rebuild): Rebuild the SQLite index from scratch (full scan of Markdown store) and re-check every review: an edit outside tkt, a git merge or a new tkt version may have changed what an item builds on (`tkt review`)
- [`tkt index status`](/en/docs/reference/commands/maintenance.md#tkt-index-status): Show index health (row counts, db path)

## Related

- Reference: [Doctor findings](/en/docs/reference/doctor.md): The tkt doctor findings by severity, each with its code and meaning (Checking the store).
- Guide: [Git: merge drivers and after a merge](/en/docs/guides/team/git.md): The merge drivers prevent merge damage in the store; when it happened anyway, here is the repair.
- Guide: [Parallel work](/en/docs/guides/team/worktrees.md): What can run in parallel, and how two agents work in two worktrees on one store.
- Error code · 422: [`ERR_FILE_PARSE`](/en/docs/reference/errors.md#ERR_FILE_PARSE): A store file cannot be parsed; fix the file
- Doctor · info: [`EDGE_COVERAGE`](/en/docs/reference/doctor.md#doctor-EDGE_COVERAGE): One line per edge declared for coverage that some open items state nowhere (coverage: decisions without affects 31 of 353 (9 %))
- Doctor · info: [`UNANCHORED`](/en/docs/reference/doctor.md#doctor-UNANCHORED): Docs and gotchas that build on no decision (critical gotchas counted separately): tkt review --unanchored
- Doctor · info: [`ORPHANED`](/en/docs/reference/doctor.md#doctor-ORPHANED): Docs, gotchas and groups nothing refers to: tkt review --unanchored
- Doctor · info: [`UNTOUCHED_UNANCHORED`](/en/docs/reference/doctor.md#doctor-UNTOUCHED_UNANCHORED): Unanchored items untouched for untouchedDays or more: tkt review --unanchored --older \<N\>d
- Config key: [`untouchedDays`](/en/docs/reference/config.md#untouchedDays): Days after which an unanchored doc or gotcha counts as untouched in tkt doctor and tkt review --unanchored
- Error code · 422: [`ERR_INDEX_DRIFT`](/en/docs/reference/errors.md#ERR_INDEX_DRIFT): An index row disagrees with its file (doctor only)
- Error code · 422: [`ERR_INDEX_CORRUPT`](/en/docs/reference/errors.md#ERR_INDEX_CORRUPT): index.db cannot be opened or queried (doctor only)
- Error code · 500: [`ERR_INDEX_REBUILD`](/en/docs/reference/errors.md#ERR_INDEX_REBUILD): The index cannot be rebuilt
