Skip to content

--agent custom agent's disallowedTools policy is ignored in the interactive TUI (works in print mode) #3417

Open

Description

@JoeSio

What version of Kimi Code is running?

0.39.1

Which open platform/subscription were you using?

kimi code

Which model were you using?

k3

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What issue are you seeing?

A custom agent file's `disallowedTools` policy is applied in print mode but silently ignored in the interactive TUI.

 With `~/.kimi-code/agents/dev.md` declaring `disallowedTools: [Read, Write, Edit]`, `kimi --agent dev` starts a TUI session without error, but the main

agent's tool list still contains Read/Write/Edit and the agent successfully executes Read on the first prompt.

 Verified via the session wire log (`agents/main/wire.jsonl` → `llm.tools_snapshot`):
 - TUI session started with `--agent dev`: 63 tools, Read/Write/Edit present
 - Print session started with `kimi --agent dev -p`: 60 tools, Read/Write/Edit absent
 - Print session without `--agent`: 63 tools (control)

What steps can reproduce the bug?

  1. Create ~/.kimi-code/agents/dev.md:
 ---
 name: dev
 description: Default agent with Read/Write/Edit disabled
 disallowedTools:
   - Read
   - Write
   - Edit
 ---

 ${base_prompt}

 2. Run `kimi --agent dev` (interactive TUI) and prompt: read @AGENTS.md
    → the agent calls the Read tool and succeeds (unexpected).
 3. Compare with `kimi --agent dev -p "Reply with exactly: ok"`, then inspect the
    new session's wire.jsonl: Read/Write/Edit are absent from llm.tools_snapshot.

What is the expected behavior?

Per https://www.kimi.com/code/docs/en/kimi-code-cli/customization/agents.html, --agent works in both print mode and the interactive TUI, and an agent's
tools/disallowedTools "shape the tools shown to the model and are enforced again before execution". The TUI startup session should bind the qwen profile
and exclude Read/Write/Edit from the main agent's tool set, exactly as print mode does. An unknown agent name should fail at startup on both paths.

Additional information

No response

Contribution

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

Activity

  1. added
    bug
    on Sep 1, 2026
  2. 535628443 commented on Sep 8, 2026

    @535628443

    I'd like to contribute a bug fix for this issue. I reproduced the dropped profile binding with a regression test on a checkout based on 6de0cec and have a local fix ready.

    The CLI already forwards --agent to the TUI. The loss occurs in SDKRpcClientV2.createSession: it does not forward agentProfile to the engine, and its model/permission initialization binds the default agent profile. Separately, lazy TUI session creation postpones validation of an unknown agent name until the first input.

    The proposed fix passes the selected profile, model, and thinking settings through the engine's existing mainAgentBinding, avoids subsequently rebinding it to the default profile, and creates the startup session immediately when an agent was explicitly selected. Ordinary startup retains lazy session creation. This contribution is scoped to named agents selected with --agent; it does not implement the separate explicit agent-file loading path.

    Validation on macOS with Node 24.19.0 / pnpm 10.33.0:

    • 181 tests passed across the SDK wiring, SDK prompt events, TUI startup, CLI run-shell, and print-mode test files.
    • Regression coverage checks disallowedTools and tools against the actual model request, rejects a simulated Read tool call, preserves the selected policy on resume, and reports unknown names during startup.
    • SDK and CLI package typechecks passed; pnpm lint passed with 0 errors (existing repository warnings remain).
    • A CLI patch changeset is included locally. No Windows-specific execution has been performed.

    Per CONTRIBUTING.md, could a maintainer approve a bug-fix PR for this scope with an /approve comment? No PR has been opened; I will wait for approval before opening one.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions