Skip to content

Expose the conversation's session ID in headless mode (--no-interactive) #9066

Description

@okajun35

Kiro Product

CLI

Feature Description

Problem / background

I want to resume, verify, and audit conversations that were run with
kiro-cli chat --no-interactive (headless). To do that I need to know which session a
given run corresponds to, but there is no way to obtain that session ID in headless mode.

Concrete needs:

  • Resume: continue a previous headless run. Resuming requires the session ID.
  • Traceability / audit: review and trace conversations executed in CI or automation
    later on, by linking a run to its session.
  • External tool integration: when embedding headless as a conversation engine, manage
    each run's session from the caller side.

Constraints confirmed in kiro-cli 2.5.1:

  1. On --no-interactive, the session ID is not printed to stdout in a machine-readable
    form. Interactive mode has /session-id and an on-exit resume hint, but neither is
    emitted in headless mode.
  2. --resume-id <a brand-new ID> does not create a new session (only existing IDs can be
    resumed).
  3. As a workaround, you can run --list-sessions right after a turn (newest first; the
    ~10s lag from 2.2.2 is gone in 2.5.1) to grab the real ID. But (a) it is printed to
    stderr, and (b) if multiple conversations are started concurrently in the same
    directory, they all grab the same "latest" ID and get mixed up.

Since passing a real ID to --resume-id resumes correctly regardless of cwd (confirmed),
any reliable, immediate way to obtain a run's session ID would satisfy all of the above —
including multi-turn conversations under parallelism.

Desired behavior

Any one of the following would be sufficient:

  • --print-session-id: print the session ID used for the run to stdout.
  • --output-format json (applied to chat, not just --list-models): emit the response
    body, session ID, credits used, etc. as JSON.
    { "sessionId": "e0b90fad-...", "content": "...", "credits": 0.11 }
  • Allow --resume-id <arbitrary ID> to create a new session under the given ID. If the
    caller can mint the ID, retrieval is unnecessary and parallel use is solved naturally.

Interactive mode already implements /session-id, so emitting the same value in headless
mode is likely low-cost.

Use Case

Example 1: Resume and audit a headless conversation (basic)

# First run: start a headless conversation and capture the session ID
SID=$(kiro-cli chat --no-interactive --print-session-id "Propose a project structure" | extract_id)

# Later / another job: resume the same conversation
kiro-cli chat --no-interactive --resume-id "$SID" "Implement the previous proposal"

With an immediately available session ID, conversations run in CI/CD or batch jobs can be
tracked and resumed per session, and reviewed afterward (validation / audit).

Example 2: AI agent orchestration

An orchestration tool invokes kiro-cli as a conversation engine and runs a multi-turn
flow (plan → implement → review → fix) while preserving context. It also runs parallel
reviews (multiple reviewers started concurrently).

  • Each step is a separate process, so the session ID must be returned immediately per call.
  • Especially when starting multiple conversations in parallel in the same directory,
    --list-sessions "latest" cannot disambiguate them, so each call needs to reliably get
    its own session ID.

Additional Context

  • Test environment: kiro-cli 2.5.1 (Linux / WSL2).
  • Passing a real ID to --resume-id resumes regardless of cwd (confirmed).
  • --list-sessions lists newest first and is near-instant, but it prints to stderr and
    cannot disambiguate concurrent new conversations.
  • ACP mode (kiro-cli acp) exposes explicit session/new / session/load with session
    IDs, but having an equivalent ID-retrieval mechanism in the lightweight headless CLI
    would make automation integration much easier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions