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:

Session-taking commands share one lookup. They accept a full or partial ID, a session name, a rollout filename fragment, or a session file path across both agents. See Resolve for the exact precedence.

In a terminal, ambiguous actions show a numbered Rich table. Enter q, press Ctrl-C, or send end-of-input to cancel without changing anything. Non-terminal and machine-readable modes print the ambiguity and exit nonzero without prompting. --agent restricts the searched agent home. The bare aichat <session> shortcut routes through the same lookup as menu.

port uses the same resolver and picker. It has no --agent, so it searches both configured homes. A direct file path is classified from its content.

The following commands use the shared Rich picker for ambiguous interactive queries:

  • aichat <session> and aichat menu <session>
  • trim, smart-trim, export, info, copy, move, and query
  • clone, rollover, lineage, and resume
  • delete, find-original, and find-derived
  • the agent-specific export-claude and export-codex commands
  • port

trim-in-place uses the picker for human-readable output, but its --json mode never prompts and always emits one JSON result or error object. The --json modes for info and lineage also fail deterministically instead of prompting.

move-account applies the same match tiers across all eligible source homes. Its picker includes the source home so equal names in different accounts remain distinguishable.

Every picker sorts candidates newest first. Selecting a number continues with that session. Entering q, pressing Ctrl-C, or sending end-of-input cancels before the command changes anything. Piped and other non-terminal input lists the candidates and exits nonzero.

CommandDescription
aichatAction menu for latest session(s)
aichat <session>Action-menu shortcut by name, ID, filename, or path
aichat resume [session]Resume with strategy options
aichat rollover [session]Rollover to fresh session
aichat trim [session]Trim session content
aichat trim-in-place <session>Trim a Claude session in place
aichat smart-trim [session]AI-guided trim of session content
aichat clone [session]Clone a session file
aichat menu <session>Interactive action menu
aichat lineage [session]Show parent lineage chain
aichat query [session]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