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:

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 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

For help on any subcommand:

Terminal window
aichat <subcommand> --help