--- outline: deep --- # External Agent Calls ChatLab can act as the local chat-data tool layer for external agents such as Codex, Claude Code, and HermesAgent. The agent handles conversation, planning, and synthesis; ChatLab handles controlled local reads, search, statistics, and organization of local chat records. This mode does not require opening the ChatLab web UI, and it does not require starting the ChatLab desktop interface first. External agents call the lightweight `chatlab` CLI on demand, run controlled local queries, searches, and statistics, then receive privacy-processed text. ## When to use it - You already use an external agent such as Codex, Claude Code, or HermesAgent, and want to reuse its subscription, tokens, model capabilities, and workflow. - You want the agent to analyze ChatLab records on demand, but you do not want to hand it the raw database or a full chat export. - You want ChatLab to handle desensitization, blacklist filtering, cleaning, merging, and truncation before sending analysis-ready text and traceable single-message ids to the agent. The `chatlab` CLI ships a set of query commands optimized for AI agents while staying human-readable. All query commands are read-only and apply your ChatLab privacy preprocessing (desensitization, blacklist) by default. Install with `npm i chatlab-cli -g` (Node.js ≥ 20) and import chat records in ChatLab first. ## Command overview ```bash chatlab sessions list # List imported sessions chatlab sessions show # Session details chatlab members list # Session members chatlab members history # Member name history chatlab messages list # List messages in a time window chatlab messages search # Keyword search (multi-word, context, paging) chatlab messages context --id # Messages around a specific id chatlab messages between # Conversation between two members chatlab stats overview # Session overview chatlab stats activity # Member activity ranking chatlab stats time --by day # Time distribution (hour/weekday/day/month) chatlab stats keywords # High-frequency words (privacy-filtered) chatlab stats response # Reply speed ranking chatlab topics list # AI segment summaries chatlab topics show --id # Original messages of one segment chatlab sql "