Skip to content

TUI ignores --agent-file at launch; startup session binds default agent (works in -p print mode) #2767

Open

Description

@mohidmakhdoomi

What version of Kimi Code is running?

0.38.0

Which open platform/subscription were you using?

Kimi Code (kimi.com/code)

Which model were you using?

K3-256k thinking

What platform is your computer?

Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 unknown

What issue are you seeing?

Launching the interactive TUI with --agent-file <path> silently ignores the flag: the startup session binds the built-in default agent instead of the agent defined in the file. The same flag works correctly in non-interactive print mode (kimi -p), so the agent file itself parses fine — the defect is specific to the interactive TUI startup path.

Evidence from the session wire log (~/.kimi-code/sessions/<wd>/<session>/agents/main/wire.jsonl):

  • profile.bind records profileName: "agent" (the default) with the stock ~20.9 KB system prompt; the agent file content appears nowhere in the log.
  • --yolo passed on the same command line DOES take effect (a second permission.set_mode: "yolo" event is recorded right after the config default), so this is not a general "TUI drops all launch flags" issue — it is specific to --agent-file.
  • No warning is emitted to the session log or the global diagnostic log (~/.kimi-code/logs/kimi-code.log) — the flag is dropped silently.

Print-mode control test on the same version and file binds correctly, with both syntaxes:

kimi -p "Reply with exactly: ok" --agent-file=test.md   # → profileName: "codev-builder"
kimi --agent-file test.md -p "Reply with exactly: ok"   # → profileName: "codev-builder"

What steps can reproduce the bug?

  1. Create an agent file, e.g. test.md:

    ---
    name: codev-builder
    description: Codev builder role
    ---
    # Custom instructions
    ...
  2. Launch the TUI: kimi --yolo --agent-file test.md

  3. Send any prompt.

  4. Inspect the session wire log:

    grep -o "\"profileName\":\"[^\"]*\"" \
      ~/.kimi-code/sessions/<wd>/<session>/agents/main/wire.jsonl

Reproduced across two separate TUI launches; both startup sessions bound the default agent.

What is the expected behavior?

profile.bind shows profileName: "codev-builder" and the agent file content is inlined into the system prompt, per the docs: "--agent-file registers a single agent file at the highest priority for this launch only and selects it ... in the TUI the flags bind only the startup session."

Additional information

Possibly related reports with the same "interactive TUI fails to apply agent profile configuration; -p print mode works" shape:

Contribution

  • I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)

Activity

  1. mohidmakhdoomi commented on Aug 22, 2026

    @mohidmakhdoomi
    Author

    @liruifengv this bug is fixed in #2770, I opened it Aug 10, before the approved-bug-fix-only policy landed in #3089 (Aug 19), so there's no /approve here yet. Requesting one so the PR is on-policy.

    Source is 249 added / 20 deleted across three packages:

    • apps/kimi-code/src/cli/run-shell.ts +5 — forwards the flag
    • packages/node-sdk/src/sdk-rpc-client-v2.ts +208/-17 — the actual fix
    • packages/node-sdk/src/types.ts +26/-3 — new agentFiles harness option, hence the SDK minor
    • packages/agent-core-v2/src/program/program.ts +10

    Plus 347 lines of tests and one docs line each in en/zh. --agent <name> is fixed alongside --agent-file.

  2. mohidmakhdoomi commented on Sep 9, 2026

    @mohidmakhdoomi
    Author

    Hi @liruifengv any chance this will be fixed?

  3. Einherjare commented on Sep 11, 2026

    @Einherjare

    Still reproduces on 0.42.0: the TUI's startup session ignores --agent-file and gets the default agent with every tool, Bash included

    Reproduced on 0.42.0, and still present on main at 72dbb9bb (11 Sep).
    With a read-only agent file, the TUI's first session gets the full default tool list, including Bash, Write and Edit, so the restriction the file declares silently disappears.
    The same file binds correctly in print mode.

    Environment

    • @moonshot-ai/kimi-code 0.42.0 from npm; kimi --version prints 0.42.0; the release tag @moonshot-ai/[email protected] points at 6954d2c8.
    • Linux 7.0.0-30-generic x86_64, Node.js v22.22.3.
    • Subscription: Kimi Code, but not involved here: the run used a local OpenAI-compatible stub provider (type = "kimi", model name k3), so the result does not depend on the model.
    • Clean environment (env -i) apart from HOME, KIMI_CODE_HOME, PATH, TERM, KIMI_CODE_NO_AUTO_UPDATE=1 and KIMI_DISABLE_TELEMETRY=1.

    Steps to reproduce

    1. Save this as ~/project/readonly.md:

      ---
      name: readonly-probe
      description: Read-only probe agent for this bug report
      tools:
        - Read
        - Grep
        - Glob
      ---
      You are a read-only agent. Answer briefly.
    2. Print mode, as the control: cd ~/project && kimi -p "Reply with: ok" --agent-file readonly.md

    3. TUI: cd ~/project && kimi --agent-file readonly.md, send hello, then /exit.

    4. For each of the two sessions, read the main agent's wire log:

      w=~/.kimi-code/sessions/<wd>/<session>/agents/main/wire.jsonl
      grep -o '"profileName":"[^"]*"' "$w" | sort -u
      grep '"llm.tools_snapshot"' "$w" | tail -1 | grep -o '"name":"[^"]*"' | sort -u

    Expected

    The TUI session binds the same agent as print mode: profileName readonly-probe, with tools Glob, Grep and Read.
    The docs say --agent and --agent-file select the agent for a new session "in both print mode (kimi -p) and the interactive TUI" (docs/en/reference/kimi-command.md:101), and "in the TUI the flags bind only the startup session" (:108).

    Actual

    Session profile.bind profileName Tools offered to the model
    Print mode readonly-probe Glob, Grep, Read
    TUI, first session agent the full default list of 25, including Bash, Write and Edit

    No warning is shown or logged.
    /new also starts with the default agent, which kimi-command.md:108 documents as intended, so the defect is the startup session only.

    Evidence from the source (at 6954d2c8, the 0.42.0 tag)

    • apps/kimi-code/src/tui/kimi-tui.ts:886-895 puts agentProfile and agentFiles into the startup createSessionOptions, and :2290-2299 passes them for the first lazily created session, so the TUI does hand the selection over.
    • packages/node-sdk/src/sdk-rpc-client-v2.ts:1324-1364: doCreateSession(input: CreateSessionOptions) reads id, workDir, additionalDirs, model, thinking, permission and metadata.
      It never reads input.agentProfile or input.agentFiles (declared in packages/node-sdk/src/types.ts:232-237), and it calls ISessionManager.create without a mainAgentBinding.
    • sdk-rpc-client-v2.ts:1672-1689: materializeMainAgent always binds profile: DEFAULT_AGENT_PROFILE_NAME.
    • Print mode takes a different path: apps/kimi-code/src/cli/v2/run-v2-print.ts:472-479 passes mainAgentBinding: { profile: agentProfileName ?? 'agent', model } to sessions.create, which is why it works.
    • On main at 72dbb9bb, sdk-rpc-client-v2.ts still binds DEFAULT_AGENT_PROFILE_NAME and still does not reference agentProfile or agentFiles.

    The open PRs #2770 (this issue), #2832 (#2765) and #3441 (#3417) each address this dropped binding in createSession.

    Workaround

    • Tool restriction: [tools] disabled = [...] in config.toml is enforced in the TUI, after /new as well.
      It applies to the whole process, so give the restricted TUI its own KIMI_CODE_HOME with its own config.toml.
    • Prompt: per docs/en/customization/agents.md:158, $KIMI_CODE_HOME/SYSTEM.md replaces the default main-agent prompt in every launch mode, the TUI included.
    • Or use print mode, where --agent-file binds correctly.

    Version

    0.42.0 (npm latest on 11 Sep 2026), and still present on main at 72dbb9bb.
    Related: #2765, #3417; fix PRs #2770, #2832, #3441 (all open).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions