lab

A command-line tool for searching and analyzing the history of AI coding-agent sessions. It can search session events and inspect details such as tools used, providers, messages, and raw events.

In plain words
What is it for?
Use it to search session history by text or regular expression, filter results by agent provider, event type, or tool, return JSON, and inspect raw provider events.
Why use it?
It removes the need to manually open many past sessions when looking for a particular action, message, tool call, or usage pattern.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/lanegrid/agtrace/lab
Clone the repo
git clone --depth 1 https://github.com/lanegrid/agtrace
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 556 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00556
Opus 5 $0.00000 $0.00278
Sonnet 5 $0.00000 $0.00111
Haiku 4.5 $0.00000 $0.00056

Measured 2d ago against content hash 1aa101e88764, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

lab scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/commands/lab.md · 98 lines

How it starts

The opening of the file, as written. The whole thing — 98 lines — stays where its author put it; the contents beside it link to each section on GitHub.

agtrace lab

Advanced history search and analysis for AI coding agent sessions.

Overview

The lab command provides powerful tools for searching and analyzing session history at scale:

  • Search across thousands of sessions
  • Inspect raw provider events
  • Analyze tool usage patterns

Commands

lab grep

Search session history by pattern.

agtrace lab grep <PATTERN> [OPTIONS]

Arguments:

  • PATTERN - Text or regex pattern to search for in session events

Options:

  • --json - Output matching events in JSON format
  • --raw - Show raw provider events (before normalization)
  • --limit N - Limit results to N matches
  • --provider <PROVIDER> - Filter by provider (claude_code, codex, gemini)
  • --type <TYPE> - Filter by event type (ToolCall, ToolResult, User, Message, etc.)
  • --tool <TOOL> - Filter by tool name (only for ToolCall events)

Examples:

Search for tool calls:

agtrace lab grep "write_file" --json

Find MCP usage (raw events):

agtrace lab grep "mcp" --raw --limit 1

Search for specific tool usage:

agtrace lab grep "Read" --type ToolCall --limit 5

Use Cases

Analyze Tool Usage Patterns

Find all instances of a specific tool across sessions:

agtrace lab grep "read_file" --json | jq '.[] | {session: .session_id, tool: .tool_name}'

Debug Schema Changes

Inspect raw provider events to understand schema changes:

agtrace lab grep "content_block" --raw --limit 5

Find Specific Agent Behaviors

Search for specific assistant outputs or reasoning:

agtrace lab grep "refactor" --json

Extract Data for Analysis

Export matching events for external analysis:

agtrace lab grep "error" --json > errors.json
python analyze_errors.py errors.json

Performance

lab grep is optimized for searching large log directories:

  • Searches are parallelized across sessions
  • Raw log files are scanned directly (no intermediate database)
  • Matches are streamed incrementally

Read the full file on GitHub · 98 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 98 lines · 0 tokens per session scan A 1aa101e88764

Subscribe to this mod's changes

lab is a command published in the GitHub repository lanegrid/agtrace (59 stars, last pushed 1mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 556 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.