Skip to content

Agent Access

Agents (Claude Code sub-agents, Codex CLI, or any script) can use aichat programmatically to search session history and recover prior context without human interaction.

The key to agent access is the --json flag on aichat search. Instead of launching the interactive TUI, it outputs one JSON object per line (JSONL) that agents can parse with jq:

Terminal window
# Search and get structured output
aichat search "MCP server" --json
# Filter with jq
aichat search "auth" --json | jq '.session_id'
# Limit results
aichat search "refactor" --json -n 5

Each line contains these fields:

FieldDescription
session_idUnique session identifier
agentclaude or codex
projectProject directory name
branchGit branch at time of session
cwdWorking directory
linesNumber of lines in session
createdSession creation timestamp
modifiedLast modification timestamp
first_msgFirst user message (preview)
last_msgLast message (preview)
file_pathFull path to the JSONL session file
derivation_typenull, trimmed, or continued
is_sidechainWhether this is a sub-agent session
snippetMatching text snippet

For Claude Code users, the aichat plugin provides a session-searcher sub-agent that handles the entire search-and-summarize workflow. It runs as a sub-agent (using the Task tool) so search results do not pollute your main context.

Use your session-searcher sub-agent to find
sessions where we discussed the auth design.

The sub-agent:

  1. Runs aichat search --json with appropriate queries
  2. Parses results with jq
  3. Reads up to 3 session files for detail
  4. Returns a concise markdown summary with key findings and session references

For CLI agents without sub-agent support (e.g., Codex CLI), the session-search skill provides the same workflow as a direct skill invocation:

Terminal window
# The agent follows the skill instructions to:
# 1. Run aichat search --json -n 10 "query"
# 2. Parse results with jq
# 3. Read session files for detail
# 4. Return a focused summary

The full list of aichat subcommands:

Most of them share one lookup. info, export, copy, move, query, clone, rollover, lineage, smart-trim, trim, and resume all accept a full session id, a partial id (prefix, middle, or suffix fragment), a session name (set with /rename), a rollout filename fragment (e.g. 2026-03-25T14-50), or a session file path — across both agents, with the agent auto-detected. See Resolve for the exact match precedence.

An ambiguous query fails with the list of matching sessions rather than silently picking one. --agent restricts which agent home is searched; a session file path searches no home at all, so there --agent instead requires the file to belong to that agent. delete and menu keep their legacy id-or-path lookup, so the bare aichat <id> shortcut (which routes to menu) does too.

port accepts the same query forms, but resolves them slightly differently: it has no --agent, it searches both homes for every non-path query (a file path is classified from its content instead), and it calls a query ambiguous whenever each agent yields a match, even when one of them matched on a stronger tier.

CommandDescription
aichatAction menu for latest session(s)
aichat resume [id]Resume with strategy options
aichat rollover [id]Rollover to fresh session
aichat trim [id]Trim session content
aichat smart-trim [id]AI-guided trim of session content
aichat clone [id]Clone a session file
aichat menu [id]Interactive action menu
aichat lineage [id]Show parent lineage chain
aichat query [id]Query a session with AI
aichat port <session>Port a session to the other agent

For help on any subcommand:

Terminal window
aichat <subcommand> --help