Skip to content

Feature Request: expose runtime identity (pid + session id) for external observers #2116

@yeelam-gordon

Description

@yeelam-gordon

What feature would you like to see?

Today, third-party IDE plugins and agent session-management tools cannot tell whether a given Kimi session is currently being served by a running kimi-cli process. That's the blocker.

The information they need is the simple (session_id → live PID?) mapping. Without it, integrations can't:

  • show session X is live, attach versus session X is idle, resume indicators
  • route an IDE action (open file, run task, fetch context) to the right kimi process when several are running on different sessions
  • detect orphaned sessions to surface crash-recovery prompts
  • enumerate "all kimi sessions live on this machine right now"
  • aggregate per-session resource use (per-PID CPU / memory mapped back to a session id) for billing or audit

Today this is unanswerable from kimi-cli's outside surface:

  • The OS process title is a static Kimi Code for every interactive process.
  • A fresh session created without --session / --resume does not carry its session id in argv.
  • No PID / lockfile / status file is written under the session directory for the interactive session.

Neighbouring CLIs already solve this:

  • Copilot CLI writes a lockfile-with-PID under its share directory.
  • Claude Code auto-injects --resume <session-id> into argv so even ps aux recovers the mapping.

Kimi is the missing piece in the multi-agent CLI ecosystem.

Proposed solution

Write a small JSON sidecar at <session_dir>/runtime.json whenever _run() establishes an interactive session, containing:

{schema_version, pid, session_id, work_dir, hostname, started_at, kimi_version}

  • Atomic write via the existing utils.io.atomic_json_write helper.
  • Schema-versioned so external readers can ignore unrecognised future versions.
  • UTF-8 throughout, so non-ASCII paths and session ids round-trip.
  • Cleared only on cross-session Reload (/new / /fork / /undo — same PID switching to a different session id). All other exit paths leave the file as-is; consumers verify PID liveness, so a stale claim becomes "session not currently reachable" rather than a false positive.

Consumers scan <session_dir>s under ~/.kimi/sessions/, read the file, verify the recorded PID is alive — and now they have the (session_id → live PID?) answer they need.

Additional information

Implementation in PR #2082.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions