MoonshotAI / MoonshotAI/kimi-code

Provide a stable pid↔session runtime record for local tooling (e.g. run/<pid>.json)

Open
#2,848 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

Summary

Kimi Code rewrites its process title at runtime (observed on 0.34.0: /proc/<pid>/cmdline collapses to kimi/kimi-code plus padding within seconds of start), which destroys the --session <sid> argv evidence. No other stable pid↔session binding exists: there is no session-id env var on the process, the wire-log fd is transient (open around writes only), and neither session_index.jsonl nor state.json records the hosting pid.

Local session-management tooling therefore cannot tell which process holds which session, and any stop/takeover decision becomes a guess.

What exists today

The SessionStart/SessionEnd hooks can serve as a user-side bridge: the payload carries session_id, and the hook process can recover the hosting kimi pid from its ancestry (kimi → sh -c → hook). But this requires every user to hand-configure [[hooks]] rules, and the parentage walk is indirect.

Ask

At session materialization, write a small runtime record keyed by pid — e.g. ~/.kimi-code/run/<pid>.json containing the sessionId (and ideally the process start time) — and remove it on session end. This mirrors what Claude Code provides via ~/.claude/sessions/<pid>.json.

Lighter alternatives that would also unblock local tooling:

  • keep the original argv (skip the process-title rewrite), or
  • set a session-id env var on the process, or
  • record the hosting pid in session_index.jsonl entries.

Context

Verified on Kimi Code 0.34.0 (Linux): title-rewrite forms (kimi on a TTY, kimi-code otherwise), transient wire-log fd, and hook payload/timing (SessionStart fires at a TUI's first prompt, immediately for --prompt; SessionEnd on clean exit). I maintain csctl, a tmux-based local workbench for agent CLI sessions, which would consume this record for safe liveness/takeover decisions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing session materialization and the SessionStart/SessionEnd lifecycle, then inspect how session_index.jsonl, state.json, and the process-title rewrite are handled. Compare the proposed pid-keyed runtime record with the listed alternatives and define cleanup behavior on session end. Done means local tooling can reliably map a live process to its session without user-configured hooks.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, typescript
Domain
cli, devtools, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.