| name | codex-thread-history-search |
|---|---|
| description | Search earlier turns in Codex Desktop tasks with read-only history access and tool-side filtering. Use when recovering prior decisions, commands, procedures, or context from the current or another Codex task without loading whole histories into the model context. |
Recover relevant evidence from persisted Codex task history while keeping model-context use proportional to the answer.
- Treat the operation as read-only. Do not resume, fork, message, archive, or otherwise mutate a task.
- Prefer documented Codex thread APIs over rollout JSONL, SQLite state, session files, or equivalent harness storage.
- Do not use this workflow for ordinary repository search, web research, or facts already present in the visible conversation.
- Do not silently inspect internal storage. Use that fallback only after explaining the proposed source and scope and receiving explicit user permission.
- Use an explicit task URL or thread ID when supplied.
- Otherwise use host-provided current-task metadata when available.
- If necessary, call
list_threadswith a small limit or discriminating query and match the working directory, title, recency, and status. Do not guess when multiple tasks remain plausible.
Use this fixed escalation order. Stop at the first level that can answer the question; do not compare every possible route in advance.
- Use a native occurrence-search capability when the harness exposes one. Retrieve only the matching turn detail needed to answer.
- Otherwise page through documented thread history and filter inside the tool execution environment.
- Otherwise use a documented full-session read or export facility and filter its result in the tool process before emitting excerpts.
- If no documented route is usable, report the limitation and ask permission to search the harness's persisted rollout, session files, database, or equivalent storage in read-only mode.
Discover available capabilities from the current tool registry and their descriptions rather than assuming one permanent wrapper name. If a previously available handler is missing, rediscover it once; a desktop-app restart may restore a missing handler.
- For one recent page, a direct
read_threadcall is acceptable. - For older or uncertain history, call
read_threadfromfunctions.execand filter inside the JavaScript isolate. Nested tool results do not enter model context unless emitted withtext(...). - Request at most 10 turns per page, set
includeOutputs: false, and followpage.nextCursortoward older turns. - Search case-insensitively with a compact set of terms and meaningful variants, including translated terminology, command names, paths, and error fragments when relevant.
- Emit only matching excerpts with enough surrounding text to identify the decision or procedure. Never emit every fetched page merely to inspect it.
- Stop when the evidence is sufficient, history is exhausted, or a reasonable page bound is reached. Say when the search was bounded or inconclusive.
A typical deep-search orchestration has this shape:
let cursor;
for (let pageIndex = 0; pageIndex < pageLimit; pageIndex++) {
const raw = await tools.codex_app__read_thread({
threadId,
cursor,
turnLimit: 10,
includeOutputs: false,
});
const page = typeof raw === "string" ? JSON.parse(raw) : raw;
const serialized = JSON.stringify(page.turns ?? []);
const excerpts = findRelevantExcerpts(serialized, terms);
for (const excerpt of excerpts) text(excerpt);
if (excerpts.length && evidenceIsSufficient(excerpts)) break;
cursor = page.page?.nextCursor;
if (!cursor) break;
}The helper names are illustrative. Implement small local matching and excerpt logic in the isolate; do not create repository files for an ordinary history search.
When documented APIs cannot answer the question:
- Identify the likely storage source and state whether it is documented or an unstable implementation detail.
- Tell the user what will be searched and whether the requested scope may include tool outputs or other sensitive records, then obtain explicit permission.
- Prefer documented session files over internal databases. Use read-only commands, streaming parsers, or immutable/read-only database access; never resume or rewrite the session.
- It is acceptable to scan a complete persisted record in the tool process. Emit only compact matches and necessary neighboring text into model context.
- If access still fails, report the verified limitation and provide clearly labeled hypotheses about the cause and the next plausible route.
Start from summaries and messages. If the answer specifically depends on an exact command output or truncated tool result, re-read only the matching page with includeOutputs: true and a conservative maxOutputCharsPerItem. Keep the first-pass terms or turn identity so the second pass does not broaden into a full-history dump.
- Distinguish a verbatim recovered instruction from a present-day synthesis.
- Preserve exact commands, paths, version numbers, and stopping conditions when they matter.
- Mention the source task or approximate turn position when useful, without exposing opaque internal metadata unnecessarily.
- If later evidence supersedes earlier advice, present the latest verified procedure and briefly note the supersession.