# Saving evidence

Logs rotate. Under load, a 1 GB trace file can be gone in minutes - and with it the 57 lines that explain the outage.
**Save as Evidence** keeps exactly those lines, with the records around them, in a durable **evidence package** that
stays after the log is rotated, deleted or TKTail restarts. Secrets in them (Bearer tokens, passwords, keys) are
replaced before anything is written. You can verify a package any time, and hand a copy to a colleague or a vendor.

The workflow: **find** (search) → **analyze** (aggregate, read the records) → **preserve** (save as evidence) →
**verify** → **share**.

## Why not just copy the log?

- **Only what matters.** TKTail keeps the records your search found and the context you ask for - kilobytes instead of
  a gigabyte. It goes straight to each result's place in the file and reads the blocks around it; it does not read or
  copy the whole log. Measured on a 1 GB trace: 57 results with 20 records on each side became a package of
  142 KB in 0.35 seconds; TKTail read 47 MB (4.7 %) of the file ([How fast](https://tktail.dev/help/saving-evidence/#how-fast)).
- **Before it is gone.** A package is written while the file still holds the records. Once saved, the package does not
  depend on the log any more.
- **Redacted.** Secrets are removed while the package is written - nothing to clean by hand before you share it.
- **Checkable.** Every file in a package has a SHA-256 in its manifest; the package's own SHA-256 is kept beside it.

A package compared with the output of a script, and what a custom helper would have to implement to match it:
[Find the cause, preserve the proof](https://tktail.dev/ai/investigation-workflow/#evidence) on the TKTail website.

## Save the results of a search

1. Search as usual (Ctrl+Shift+F, ADVANCED SEARCH, Find in All Open Files).
2. In **Search Results**, click **Save as Evidence** on the toolbar - or right-click the results: **Save Selected as
   Evidence...** keeps only the rows you selected, **Save All as Evidence...** every result of the search.
3. Choose the context and click **Save Evidence**:

| Option | What it keeps |
|---|---|
| **Records before / after** | That many records on each side of every result (default 20 / 20). A record is a whole log entry: an error with its stack trace is one record, not five lines. |
| **Seconds before / after** | Every record within that many seconds of each result, by the record's own time. A record without a date and time cannot be placed in time: the package says so. |
| **Also keep these sources for the same time** | Other open logs and event logs (an IIS log, the Application event log) - their records of the same time window. Only what you tick; TKTail never keeps "everything open". Without seconds, the window is the results' time span plus 15 seconds on each side. |
| **Include parsed records** | Besides the original text, `records.jsonl`: every record parsed - its time, fields and whether it was a result. |
| **Note** | Why this evidence matters. Shown in the library and written into the package. |

*Screenshot: Save as Evidence for 9 results of a TimeoutException search: 20 records before and after each, the API access log kept for the same time, parsed records included, a note for the vendor case; the dialog says redaction is on and where the package is saved*

The dialog says that **redaction is on** and which rules run. Saving happens in the background; the **Evidence** tab of
the bottom panel shows the package when it is written and verified, and the status bar says how many hits, how big
and how many secrets were replaced.

**A capture is not evidence until it is saved.** While it runs, the library lists it as *Capturing*. It becomes a
package only when TKTail has written it **and verified it**. If it fails - the Evidence Store is full, the files are gone,
a limit is reached - nothing is kept, the status bar and **Output** say why, and the library keeps the capture listed as
*Failed - not saved* (with the reason and time) until you **Dismiss** it, also after TKTail restarts. A failed capture is
never shown as a package; save again to retry - a new capture with a new package id.

Overlapping context is kept once: 57 errors close together become a few ranges, not 57 copies of the same records.

**How many results.** A package keeps up to **5,000 results** - as many as a search stores (a search finds and counts
every match, and stores the first 5,000 for paging). When a search found more, the package keeps the 5,000 it stored and
its limitations say *"Search #17 is truncated - 10000 found, 5000 stored"*; narrow the search (a shorter time range, one
more condition) and save each part, or save several searches.

## Save a whole file

Sometimes a vendor really wants the whole log. Right-click the file's tab: **Save Whole File as Evidence...**. TKTail
reads the file it has open - up to its end at that moment - in the background, at most 64 MB per second so a busy
server's disk is not hammered, redacts it line by line and compresses it as it writes. Nothing is copied first. The
package records the SHA-256 of the file as it was read. A file larger than the full-file limit (Settings) is refused
before anything is written.

## The Evidence Library

**View > Tool Views > Evidence** (or the **Evidence** tab of the bottom panel) lists every package, newest first: when
it was made, its note, sources, time range, size, hits, how many secrets were replaced, who asked for it (you, an AI
client) and its status. Captures still running are listed on top. The details beside the list show the package's
README - what it holds, where each piece came from, the redaction and the hashes.

*Screenshot: The Evidence tab of the bottom panel: two packages with their notes, sources and time ranges; beside them the selected package's README - created by TKTail, requested by the user, the search, 20 records of context, 9 hits, its sources; the status bar says the package was verified VALID*

| Action | What it does |
|---|---|
| **Open Evidence** (Enter) | Opens the kept text of each log as a tab (a copy - the package never changes). |
| **Verify** | Reads the package and checks it: its SHA-256, every file's SHA-256, the manifest. **VALID**, **MODIFIED**, **INCOMPLETE** or **UNSUPPORTED** (made by a newer TKTail). |
| **Reveal in Explorer** | The package file in its folder. |
| **Create Shareable Copy...** | A copy for someone else, in a folder you choose - see below. |
| **Link to Incident...** | Connects the package with an alert's incident. |
| **Open the Original File** | The log itself at the first range - only while it is still the same file. |
| **Delete...** (Delete key) | Deletes the package after you confirm. |
| **Dismiss** (a *Failed - not saved* line) | Removes the line of a capture that ended without a package - nothing was saved, so nothing is deleted. |

A note, a link to an incident or a deletion request never changes the package itself: they are kept in the library's
catalog. A package is immutable once written. Failed and cancelled captures are listed separately from the packages
(the newest 50, for up to 30 days) - they are never packages.

## Redaction

Before anything is written, every line is checked for secrets, and each one found is replaced by a marker such as
`[REDACTED:bearer-token]`. The marker never says how long the secret was. TKTail always applies its built-in rules:

- `Authorization:` headers (Bearer, Basic and other schemes - also `authorization : bearer ...`, JSON, URL-encoded),
- JWT-like tokens (`eyJ...`),
- `password=`, `pwd=`, `secret=`, `token=`, `api_key=` and similar values - in connection strings, URLs, JSON and XML,
- passwords in URLs (`https://user:password@host`),
- storage account keys and SAS signatures,
- well-known API key formats,
- session cookies,
- private key blocks (`-----BEGIN ... PRIVATE KEY-----` to its end).

**Your own rules** live in `redaction-rules.json` in the data folder (Settings > Files & Storage shows the folder):

```json
{
  "kind": "tktail.redactionRules", "schemaVersion": 1,
  "rules": [
    { "id": "acme.customer-id", "name": "ACME customer numbers", "pattern": "\\bCUST-(?<secret>\\d{6,})\\b", "matchCase": true },
    { "id": "iis-session", "name": "IIS session ids", "pattern": "\\bsid=(?<secret>[0-9a-f]{16})",
      "scope": "format", "scopeValue": "builtin:iis", "replacement": "fixed", "text": "<sid>" }
  ]
}
```

A rule is a regular expression (TKTail's search dialect, with its safety limits). A capture named `secret` is what is
replaced; without one, the whole match. `scope` is `global` (default), `format` (a format id such as `builtin:iis`) or
`source` (a path, or a wildcard such as `log.*.txt`); `enabled: false` switches a rule off.

Safety comes first:

- A rule that does not work (an invalid pattern, an unreadable file) **stops the save** - TKTail never saves a package
  without the rules you defined.
- A line a rule cannot check (it would take too long) is withheld as a whole: `[REDACTED:unchecked-line]`.
- The package's manifest lists which rules ran and how many replacements each made - never what was replaced.
- There is no "unredacted" package, and AI clients have no way to ask for one.

## Rotating logs: pin, then save

A **pinned search** (Search Results > **Pin Search**) is never closed to make room and comes back after a restart -
but it keeps the search and the *positions* of its results, not the records themselves. If the log rotates away, a
pinned search can no longer show them. To keep the records, **save them as evidence** while the file still holds them.

What a pin keeps across a restart, exactly: the search's definition, each result's position in its file (byte offset,
line, record) and the file's identity, and the one-line preview the result showed - redacted like a package. Not the
records themselves, not their context, no package: those exist only once you save evidence.

- If the log was **renamed** by its rotation (`log.txt` → `log.0.txt`), TKTail finds the same file again in its folder
  by its identity and saves from it.
- If the file was **deleted** before you saved, nothing can be preserved - the save fails and says so. TKTail never
  claims to have kept what it could not read.
- An AI client can pin a search and preserve its evidence in one step; the search then reports its protection:
  *preserved* (a verified package exists), *preservation pending* (still capturing - not preserved yet), *preservation
  failed* (the capture ended without a package - its reason is given; save again), *source still available* or
  *source disappeared*. A pin alone is not evidence: only a saved package keeps the records.
- While a capture runs, its search is never closed to make room for newer searches.

## Sharing

**Create Shareable Copy...** writes a new package for someone else: the same redacted files, but without your local
paths, file identities and the identity of your TKTail. Its manifest names the package it came from and that package's
SHA-256. The copy is made from the saved package - the original logs are not read again.

What the recipient needs: any unzip tool and any SHA-256 tool. The `README.txt` inside explains the package:

```
PowerShell:   Get-FileHash -Algorithm SHA256 sources\source-001\original.txt
Linux/macOS:  sha256sum sources/source-001/original.txt
```

Each value must equal the one in `manifest.json` (and in README.txt). The package's own SHA-256 is in
`<package>.zip.sha256` beside it.

What the hashes prove: the files are unchanged since TKTail wrote the manifest. They do not prove who made the package,
and a redacted file's hash is not the hash of the original log. TKTail packages are **verifiable investigation
evidence** - not a legal chain of custody.

## What a package holds

```
manifest.json                       what it holds, where every piece came from, the redaction, the hashes
README.txt                          the same for people
sources/source-001/original.txt     a log's kept ranges, one after another (line ends as in the log)
sources/source-001/records.jsonl    its records, parsed (optional)
sources/source-002/events.jsonl     an event log's events in the window
sources/source-003/metrics.jsonl    a Metric Set's samples in the window
sources/source-004/<file name>      a whole file (Save Whole File as Evidence)
```

For each log, the manifest maps every range back to its byte offsets in the original file, records the file's identity,
its format and encoding, its size when it was saved and - when TKTail knew it exactly - the line of every result.
Where nothing was redacted, `original.txt` holds the log's own bytes (the manifest says `exactSourceBytes`).

## Disk limits

Packages are kept until you delete them - never removed automatically, never to make room. Settings > Alerts &
Incidents > **Evidence packages** sets:

| Setting | Default |
|---|---|
| Evidence Store up to | 2048 MB |
| One evidence package up to | 256 MB |
| One full-file evidence package up to | 4000 MB |
| Free disk space kept | 1024 MB |
| Warn when the Evidence Store is | 80 % full |

Before a package is written, TKTail checks its largest possible size against these limits and the free disk space. If
it does not fit, nothing is written and the status bar says which limit and by how much.

## Deleting

**Delete...** in the library (or the Delete key on a selected package) deletes the package and its `.sha256` file after
you confirm - the confirmation's default button is Cancel. Shareable copies you made elsewhere stay. An AI client
cannot delete evidence: it can only **ask** - the package is then marked *AI asks to delete* in the library, its
confirmation says the request came from an AI client, and you **Delete** (confirm) or **Keep** (reject) it. Nothing is
ever deleted automatically, not even to make room.

## With an AI assistant

An assistant connected through MCP can do all of this for you - and is the main reason the feature exists. Without
TKTail, an assistant that must keep evidence has one tool: the shell - copy the whole 1 GB log somewhere, secrets and
all, with nothing recording where the copy came from. Through TKTail it asks for exactly the records it found: TKTail
reads only their ranges, redacts them, records where every byte came from (the file's identity, the offsets, the
search), hashes everything and keeps the package until you delete it. The assistant gets a package ID and a summary -
not your log.

Two switches in **Settings > AI Access (MCP)**, both off until you turn them on: **Allow AI access** (reading), then
**Allow AI to save evidence and pin searches**. Without the second one an assistant can read and search, but saving or
pinning is refused with a message that names the switch - it should ask you. Deleting is never the assistant's: it can
only ask, and you decide in the Evidence Library.

A request is answered at once with the capture's state. **`capturing` means not saved yet**: the assistant must confirm
the end with `tktail_get_evidence` (it waits for it) before it tells you the evidence is saved - `saved` (verified) or
`failed` / `cancelled` with a failure code (`package_write_failed`, `package_verify_failed`, `evidence_limit_exceeded`,
`evidence_quota_exceeded`, `source_unavailable`, `capture_failed`, `cancelled`) and the reason. `tktail_list_evidence`
lists recent failed captures beside the packages, so a failure is found even when nobody remembers its package id.

See [AI assistance](https://tktail.dev/help/ai-assistance/#preserving-evidence) for the requests that work well, and the
[MCP tool reference](https://tktail.dev/help/mcp-tools/) for the tools: `tktail_save_evidence`, `tktail_list_evidence`,
`tktail_get_evidence`, `tktail_verify_evidence`, `tktail_delete_evidence`, `tktail_pin_search`. Everything an assistant
receives from a package is redacted - what it reads from your open logs directly (searches, records) is the log as it
is: AI access means reading what is open in TKTail.

## How fast

A production-like case, repeated on synthetic data (`benchmarks/evidence` in the source; the figures from its result
file): a 1,000,000,074-byte trace log, 57 `TimeoutException` results, 20 records before and after each. Saving them took
0.35 seconds; the package is 142 KB (2,337 records, 58 secrets redacted) and
verified VALID. TKTail read 47 MB (4.7 %) of the file - the blocks around the 57 results - never the whole log. The search
that found them read the whole file once, in 1.7 seconds. Measured on an Intel Core i9-14900F PC (32 logical processors), the file in the Windows file cache after the search; another disk and CPU give
other numbers.

Where the packages are: [Where TKTail stores data](https://tktail.dev/help/data-and-privacy/).

---

The HTML page: https://tktail.dev/help/saving-evidence/
