Skip to content

Interactive sessions ignore [[hooks]] and [[permission.rules]] from config.toml; headless (-p) sessions enforce them (0.28.1, Windows) #2070

Open

Description

@seasonmsg

Version: kimi-code 0.28.1 (native Windows install, ~/.kimi-code/bin/kimi)
OS: Windows 11 (Git Bash environment)
Config: ~/.kimi-code/config.toml — 45 [[permission.rules]] + 2 [[hooks]] (PreToolUse, UserPromptSubmit). kimi doctor config reports the file valid.

Summary

In interactive sessions, neither [[hooks]] nor [[permission.rules]] from config.toml are enforced — PreToolUse/UserPromptSubmit hooks never run, and deny rules never block. In headless sessions (kimi -p), the exact same config file works: hooks fire and deny rules block. Two independent interactive sessions reproduced this; multiple headless sessions confirmed enforcement.

Steps to reproduce

  1. Register in ~/.kimi-code/config.toml:
    • a [[hooks]] PreToolUse hook (matcher Bash|Read|Write|Edit|...) that appends a heartbeat file on every invocation;
    • a [[hooks]] UserPromptSubmit hook that writes a marker file and prints a line;
    • a [[permission.rules]] entry decision="deny", pattern="Edit(**/protected-dir/**)".
  2. Open an interactive session in the project directory.
  3. Make tool calls (Bash/Read/Edit), including an Edit on a file under protected-dir/.
  4. Observe: heartbeat file never updates; no marker file appears; the Edit on the protected path succeeds.
  5. Repeat in kimi -p headless session: heartbeat updates, marker appears, same Edit is denied with the rule's reason string.

Evidence (available on request; session ids below)

  • Interactive session A (session_68457ee1-..., 2026-07-22 14:37Z): 10+ tool calls, heartbeat untouched; Edit on protected file succeeded (immediately reverted); no UserPromptSubmit marker.
  • Interactive session B (session_713e5185-..., 14:29–14:35Z): Write of a project file at 14:35Z did not update the hook heartbeat (last beat 14:31:47Z from a headless session).
  • Headless session (session_31ac3ae7-..., 14:31Z): UserPromptSubmit hook fired (marker written); Edit on the same protected file denied by permission rule ("denied by permission rule. Reason: ..." in wire log).
  • The hook script itself is healthy: run manually with a JSON payload it exits 0 and writes the heartbeat.
  • No hook/permission errors in ~/.kimi-code/logs/kimi-code.log.

Expected vs actual

Expected (per docs: hooks and permission rules "take effect on every startup" / "loaded when a session starts"): identical enforcement in interactive and headless sessions.
Actual: enforcement only in headless (-p) sessions; interactive sessions silently run with no hooks and no permission rules.

Impact

Configs that rely on hooks/permission rules as a safety barrier (secret-leak prevention, protected paths) are silently inactive in the primary interactive use case — a fail-open condition with no user-facing warning.

Notes

  • Auto-update offered 0.29.0 (rollout-held); if this is already fixed in 0.29.0, a changelog pointer would be appreciated.
  • Debug ZIP / wire.jsonl from all referenced sessions can be provided via /feedback follow-up.

Activity

  1. seasonmsg commented on Jul 22, 2026

    @seasonmsg
    Author

    Follow-up: still reproduced on 0.29.0 (interactive), same machine / same config

    Upgraded to 0.29.0 via auto-update and re-ran the probes in a fresh interactive session (2026-07-22 ~15:42Z). Not fixed:

    • kimi --version → 0.29.0; ~/.kimi-code/config.toml unchanged and valid (45 [[permission.rules]] + 2 [[hooks]] still present).
    • PreToolUse heartbeat: file timestamp unchanged (last beat 2026-07-22 14:42Z, from a manual hook run) after 20+ tool calls in the interactive session.
    • UserPromptSubmit hook: no marker / no prompt injection on the session's first user message.
    • Deny-rule probe: an Edit on the protected path succeeded in the interactive session (immediately reverted; git status verified clean). The identical rule denies the same Edit in headless (-p) sessions.

    Conclusion: as of 0.29.0, hooks and permission rules are still enforced only in headless sessions; interactive sessions remain fail-open. Debug ZIP / wire.jsonl from this 0.29.0 session available on request.

  2. he-yufeng commented on Jul 22, 2026

    @he-yufeng
    Contributor

    Tried to pin this down from source on current main (188c0fc), and the default engine does not seem to have a spot where interactive and headless diverge on this:

    • Both the TUI and kimi -p (default v1 engine) build sessions through createSessionWithOverrides in packages/agent-core/src/rpc/core-impl.ts, which spreads config.hooks and config.permission?.rules into every session (lines 372-373; the resume path at 523 does the same). UserPromptSubmit is triggered from agent/turn/index.ts, PreToolUse from agent/permission/policies/pre-tool-call-hook.ts.
    • The v1 config schema accepts exactly the [[hooks]] and [[permission.rules]] shapes from your file, and the rule path matcher already normalizes Windows separators (tools/support/path-glob-match.ts adds slash-form variants and canonicalizes against cwd before globbing).

    Two questions that would narrow it down a lot:

    1. Is KIMI_CODE_EXPERIMENTAL_FLAG set in the shell where your headless probes enforced the config? That flag routes kimi -p to the agent-core-v2 engine, which loads the same sections through a different config service. If the enforcing headless runs were v2 and the TUI is v1, the split is between engines rather than between interactive and headless.
    2. For the deny rule: does a bare decision="deny", pattern="Edit" (tool name only, no path glob) block in an interactive session? If that also fails, the rule list never reaches the interactive session at all. If it blocks, the gap is in path matching, and the exact file_path the Edit tool receives on your Windows setup is the next thing to compare against the pattern.
  3. seasonmsg commented on Jul 23, 2026

    @seasonmsg
    Author

    Follow-up #2: hooks partially initialize mid-session; enforcement still broken (0.29.0)

    New evidence from the same interactive session that reproduced the bug on 0.29.0:

    • At session start: hooks dead — heartbeat file untouched by 20+ tool calls, no UserPromptSubmit injection, deny-rule Edit probe succeeded (all as previously reported).
    • ~1.5h into the session, after a permission-mode change (to "auto" and later back), hooks started firing: the PreToolUse heartbeat now updates on every tool call, and UserPromptSubmit injection appeared on subsequent user messages. The mode toggle is the suspected trigger (correlation, not proven causation; a controlled experiment in a fresh window is planned).
    • Despite hooks now executing, enforcement remains dead: the same deny-rule Edit probe succeeded again, and a Bash command embedding a fake secret pattern — which our PreToolUse hook is designed to block — executed unblocked.

    So on 0.29.0: hook scripts can execute (apparently after some lazy initialization), but neither permission.rules decisions nor hook block decisions take effect in interactive sessions. Headless (-p) sessions enforce both. This points at the decision/enforcement path of interactive sessions rather than at hook loading itself.

  4. he-yufeng commented on Jul 23, 2026

    @he-yufeng
    Contributor

    Follow-up #2 narrows it a lot. Two things from the v1 policy chain that sharpen the split:

    1. Enforcement in v1 is mode-independent by construction. The decision chain runs PreToolCallHookPermissionPolicy first (packages/agent-core/src/agent/permission/policies/index.ts:31, hook block lands as deny), then UserConfiguredDenyPermissionPolicy (line 39, reading agent.permission.data().rules), and only later AutoModeApprovePermissionPolicy (line 41) and GitCwdWriteApprovePermissionPolicy (line 66, which silently approves Write/Edit inside the cwd of a git work tree when nothing above matched). So an Edit probe that executes with no prompt is consistent with one reading: the session's permission.rules list was empty at that moment, and the git-cwd write-approve policy took it. Not "rules failed to match", but "rules never made it into the session".

    2. In v1 there is no hooks reload on permission-mode change. agent.hooks is fixed at session construction from the session's hooks option (session/index.ts -> agent/index.ts:190), and nothing re-populates it when you flip modes. If PreToolUse firing only started after your toggle, whatever populated the hook engine mid-session is not in the v1 wiring. That makes me suspect the interactive session on your build is not the in-process v1 path I traced (TUI -> node-sdk harness -> core-impl), but something with lazily-initialized services.

    Two probes that would separate the remaining cases cleanly:

    • Does the Edit probe show an approval prompt at all, or does it execute with zero interaction? Zero interaction + executed = the git-cwd auto-approve fired (rules absent), which you could confirm by trying the same probe on a path outside the git work tree (that one should fall to the fallback ask).
    • What exact output does your blocking hook emit? If it blocks via exit code 2 but the engine reads a JSON decision field (or vice versa), the hook fires and its block never lands. That would explain "heartbeat updates, no enforcement" for the hook half, independently of the rules half.
  5. seasonmsg commented on Jul 23, 2026

    @seasonmsg
    Author

    New evidence from a fresh interactive session on the same build (0.29.0), run as a controlled experiment against the lazy-initialization hypothesis:

    • Hooks were alive from the very first message — UserPromptSubmit injection present on message docs: fix typo in zh readme #1, PreToolUse heartbeat fresh after the first tool calls. No permission-mode toggle was needed. The lazy-init hypothesis (hooks load only after a mode switch) is therefore falsified; the earlier correlation was coincidental or the trigger is something else (e.g. a persisted mode change, or an async init race).
    • Enforcement is split into three layers, not two: (1) hook execution = alive; (2) hook block decisions = alive — our PreToolUse hook blocked both a Bash command and a Read call referencing a sensitive path (the kimi-code config TOML under the user home) with exit 2, and the blocks took effect; (3) permission.rules deny decisions = still dead — the same deny-rule Edit probe on a protected file succeeded again (reverted and verified clean).
    • In the previous session the hook block path was observed dead (a fake-secret curl ran unblocked) while in this session it is alive — both states on the same version, trigger unknown. We also checked whether default_permission_mode = "auto" explains the difference: all historical config backups (including one predating our gate setup) already had auto, and both the previously-dead session and the now-alive session ran with the same default — so the permission-mode value is not the trigger. An initialization timing race is our leading candidate.

    So on 0.29.0 interactive sessions: hook scripts execute and their exit-2 blocks can take effect, but permission.rules decisions never do. This narrows the root cause to the permission-rule evaluation path alone; hook loading/enforcement is flaky but functional.

  6. seasonmsg commented on Jul 23, 2026

    @seasonmsg
    Author

    Follow-up #4: answers to the narrowing questions (0.29.0, interactive, Windows + Git Bash)

    Thanks for the source trace — it reframed the bug for us. Answers in order:

    Q1 (KIMI_CODE_EXPERIMENTAL_FLAG): Not set anywhere we can find. Checked: current shell env, Windows User and Machine environment stores, and a full-text search of the workspace — the only occurrences are a docs listing of runtime switches and the unpacked CLI source's read-sites; nothing sets it. The enforcing headless runs were plain kimi -p from the same shell environment, so both sides should be the v1 engine. If there is another place the flag could leak in from, happy to check.

    Q2 (bare decision="deny", pattern="Edit"): Not testable from a live session — config is only read at session construction, so this needs a fresh interactive window with a temporarily modified config. That experiment is now queued with a restore protocol (snapshot config → add bare tool-name deny → open fresh TUI window → Edit probe on an in-worktree path → restore → git-diff verify). Prediction under your "rules never made it into the session" reading: it won't block. Will report back.

    Probe A (approval prompt vs zero interaction): Zero interaction, re-confirmed today in a fresh interactive window: the Edit probe on an in-worktree deny-listed path executes silently. One caveat that weakens this probe's discriminating power here: this setup runs default_permission_mode = "auto" (present in every config backup we have, including ones predating the gate setup), so AutoModeApprovePermissionPolicy would approve silently whether or not the git-cwd policy is what fired. The queued experiment therefore runs the out-of-worktree probe under manual mode so "git-cwd auto-approve vs rules-absent" actually discriminates.

    Probe B (hook block output): Our PreToolUse gate blocks via process.exit(2) with the reason on stderr (console.error('[T1-gate] BLOCKED: ...')), no stdout JSON. The confusing part: exit-2 blocks do land in some interactive sessions — same build, same config. In one interactive window, Read and Bash grep calls on our config file were interrupted with [T1-gate] BLOCKED and never executed; in other interactive windows the same hook demonstrably runs (heartbeat file keeps updating, UserPromptSubmit injection arrives) yet its block doesn't land (a curl carrying a fake secret to example.com returned 200, unblocked). So for the hook half we see both states across interactive sessions on identical config — flaky, not consistently wired-wrong. That seems hard to explain with a pure output-format mismatch.

    Current composite picture (all 0.29.0, same machine, same config — 45 [[permission.rules]] + 4 [[hooks]]):

    • Hook execution layer: flaky across interactive sessions — dead in some, alive from message docs: fix typo in zh readme #1 in others; no permission-mode toggle involved either way.
    • Hook-block (exit 2) enforcement: lands in some interactive sessions, not in others.
    • permission.rules deny enforcement: never observed to fire in any interactive session (path-glob denies consistently bypassed, zero-prompt execution); always enforced in headless.
    • Headless (kimi -p): all three layers consistently work.

    If v1 has no reload path and no interactive/headless divergence in createSessionWithOverrides, the cross-session flakiness points outside the traced path — session-construction timing, a race in service init, or the Windows TUI harness specifically. If there's anything you'd like captured from a "dead" session next time one occurs (debug flags, verbose logs, specific files), tell us what and we'll collect it.

  7. seasonmsg commented on Jul 25, 2026

    @seasonmsg
    Author

    Follow-up #5 — controlled experiment results (promised in follow-up #4)

    We ran the two probes designed around your reading of the v1 approve chain (PreToolCallHook → UserConfiguredDeny → AutoModeApprove → GitCwdWriteApprove), on 0.29.0, native Windows install:

    E1 — bare deny rule, no path glob

    • Added [[permission.rules]] / decision = "deny" / pattern = "Edit" (bare tool name, zero path matching involved) to ~/.kimi-code/config.toml, then opened a fresh interactive window.
    • Result: two Edit probes on an in-workspace file (temp/bus/events.jsonl, reversible add-X-then-revert) passed with zero prompt. A bare tool-name deny cannot miss on glob/path normalization — so the rules never reached the interactive session at all.

    E2 — out-of-tree Edit in manual mode

    • Config restored, permission mode switched to manual, then an Edit on a file outside the workspace ($TEMP/zrms-e2-probe.txt).
    • Result: a confirmation prompt appeared.

    Conclusion

    • E1 not blocking + E2 prompting = the permission rules are dropped during interactive session construction (injection chain failure), and GitCwdWriteApprove is the approver actually in position — which fully explains the zero-prompt in-workspace writes we reported earlier.
    • This matches your reading exactly: the chain exists, but UserConfiguredDeny has nothing to evaluate in interactive sessions because the rules were never loaded there.
    • Headless (-p) sessions continue to enforce the same rules correctly, so the loss is specific to interactive session construction.

    Config was restored after the probes (verified byte-identical to the pre-experiment snapshot). Happy to run additional probes or capture wire logs if that helps pin down where the rules get dropped.

  8. seasonmsg commented on Jul 25, 2026

    @seasonmsg
    Author

    Correction to follow-up #5 (E2 condition): the E2 probe actually ran in auto (full-autonomy) permission mode, not manual as written there — the experiment window's wire log shows a single permission.set_mode: auto at session start and no later mode switch. The "manual" wording was a reporting error on our side.

    The correction makes the result stronger, not weaker: even with auto approve active, the out-of-workspace Edit still triggered a confirmation prompt. So the silent approval we see inside the workspace is path-specific (GitCwdWriteApprove), not a global auto-approve artifact — which is exactly the distinction E2 was designed to test.

    E1 result is unchanged: a bare deny Edit rule did not block in the interactive session, so user-configured rules are never loaded there.

  9. seasonmsg commented on Aug 2, 2026

    @seasonmsg
    Author

    Root cause found (two independent mechanisms). The main one is in agent-core-v2, and it is upstream-reproducible.

    After weeks of probes (including E1: bare deny "Edit" with no path glob also not blocking, rules never reaching the session), we finally pinned it down on 0.31.1 with source + binary + live reproduction triple evidence:

    Mechanism B (the persistent "interactive = rules dead" failure): v2 never ingests config rules into the Agent

    Our interactive windows are all kimi web sessions (kap-server = agent-core-v2; the only kimi process on the machine is kimi.exe web --no-open --port 59000). In v2, config permission.rules are never loaded into the Agent's rule model:

    • packages/agent-core-v2/src/agent/permissionRules/configSection.ts registers the permission section (so doctor / getConfig can see it), but the section has no consumer in production code.
    • permissionRulesService.ts addRules() is the only entry point for rules into the Agent's rule model — and it has zero production callers (only tests call it).
    • session/agentLifecycle/agentLifecycleService.ts bindBootstrap (~line 188-201) injects defaultPermissionMode but never reads the permission section nor calls addRules.
    • permissionRulesOps.ts even carries a comment "hosts re-supply them on resume" — no host ever does.
    • permissionPolicyService.ts chain is intact but evaluates an empty rule model → GitCwdWriteApprovePolicy approves in-workspace writes silently (matches our E2 probe: out-of-workspace Edit prompts; in-workspace writes sail through with zero interaction).
    • Hooks take a different, properly wired path (externalHooksRunnerService.ts), which is why hooks work in the same sessions where rules are dead.

    Binary check: the embedded v2 bindBootstrap in our installed kimi.exe matches 0.31.1 source line-for-line — not a packaging divergence; the bug is in source. 0.29.0 is affected identically.

    This explains everything we reported: interactive windows have hooks alive but rules always dead; kimi -p (v1) enforces the same rules correctly; bare tool-name deny (E1) cannot block because the rule model is empty; and why you (he-yufeng) found no divergence in the v1 path — the v1 code is fine, the v2 ingestion was never wired.

    Suggested fix (6 lines)

    In bindBootstrap, after injecting the mode, ingest config rules into the agent's rule model (idempotent guard; transient op so resume re-supply keeps working; covers main agent + subagents and web/SDK/ACP hosts):

    const rules = this.config.get<PermissionRule[]>(PERMISSION_RULES_SECTION);
    if (rules?.length && !wire.getModel(PermissionRulesConfiguredModel)?.length) {
      handle.accessor.get(IAgentPermissionRulesService).addRules(rules);
    }

    Also worth noting: v1-v2-parity.test.ts lacks a "config permission.rules reach the v2 Agent" assertion — which is exactly why "doctor shows the config" could coexist with "rules never enforce" (visible ≠ wired). A parity test on rule ingestion would lock this.

    Mechanism A (the original 2026-07-22 "both hooks and rules dead" episodes): torn reads of config.toml

    Separate, environment-side issue, proven by wire evidence: our own maintenance scripts rewrote ~/.kimi-code/config.toml non-atomically, and kimi-code reads the file at session construction without a stability guard — sessions created during a rewrite window loaded a truncated-but-valid TOML prefix (hooks/rules, at the end of the file, lost first). The failing session's own Read of config.toml in its wire log shows a 55-line truncated prefix with zero [[hooks]]/[[permission.rules]]. We have fixed our side (all config writes are now tmp+rename atomic). A product-side hardening suggestion: make config load verify file stability (mtime/size check with retry) and fail loudly (or keep the previous config) when the governance sections vanish between reads, instead of silently accepting a truncated prefix.

    Happy to provide the full evidence pack (wire zips, repro scripts, patch files) or turn the two patches into PRs if you prefer.

  10. JAAvila-Of commented on Aug 25, 2026

    @JAAvila-Of

    Still reproduced on 0.36.0 and 0.38.0 (Windows) — and it also affects plugin-provided hooks, not just [[hooks]] in config.toml

    Adding two things this thread does not cover yet: confirmation on much newer builds, and a second, independent hook-registration channel showing the same failure.

    My ~/.kimi-code/config.toml contains zero [[hooks]] entries. All five hooks come from an installed plugin's kimi.plugin.json:

    "hooks": [
      { "event": "SessionStart",      "matcher": "startup|resume", "command": "bash ./scripts/session-start.sh",       "timeout": 20 },
      { "event": "UserPromptSubmit",                               "command": "bash ./scripts/user-prompt-submit.sh",  "timeout": 10 },
      { "event": "PostCompact",       "matcher": "manual|auto",    "command": "bash ./scripts/post-compact.sh",        "timeout": 10 },
      { "event": "SubagentStop",                                   "command": "bash ./scripts/subagent-stop.sh",       "timeout": 10 },
      { "event": "SessionEnd",        "matcher": "exit",           "command": "bash ./scripts/session-end.sh",         "timeout": 10 }
    ]

    Plugin is enabled: true in ~/.kimi-code/plugins/installed.json. Since the config-file path is not involved at all here, a fix scoped to config loading/reload (e.g. #2822) would not cover this case.

    Method

    I appended a trace line to each hook script — one at the top (proving invocation), one right after the script reads stdin (capturing the payload). Both are append-only writes to a single log file, so a hook that runs leaves a record even if everything after it fails.

    Result — five interleaved runs, same machine, same workspace, same plugin

    # time (UTC) version mode session prompt sent hook trace
    1 21:13:47 0.36.0 kimi -p session_80d84d78… yes fired
    2 21:27:10 0.36.0 interactive session_a85677c7… yes (lastPrompt:"hola") none
    3 21:37:52 0.38.0 interactive session_4b874ddb… yes (lastPrompt:"hola") none
    4 21:38:55 0.38.0 kimi -p session_84e5a55b… yes fired
    5 21:42:13 0.38.0 interactive session_c8969448… yes (lastPrompt:"hola") none

    3/3 interactive negative, 2/2 headless positive, across two versions. Run #4 sits 63 s after run #3 and 198 s before run #5, so environment drift, PATH, workspace trust, and plugin state are all ruled out — the mode of execution is the only variable.

    The interactive runs did start fully: run #2's session log shows llm request turnStep=0.1 0.4 s after session creation. The hook was simply never invoked. Workspace trust was granted 6 s before that session was created, so trust is not gating this.

    What a working invocation looks like (run #4, 0.38.0)

    21:38:55Z ENTER:session-start  argv0=./scripts/session-start.sh
                                   pwd=<HOME>/.kimi-code/plugins/managed/engram
                                   KIMI_PLUGIN_ROOT=<HOME>\.kimi-code\plugins\managed\engram
                                   KIMI_CODE_HOME=<HOME>/.kimi-code
    
    21:38:55Z PAYLOAD:session-start
    {"hook_event_name":"SessionStart","session_id":"session_84e5a55b-…",
     "cwd":"H:\tmp-kimi-hook-probe","client_type":"kimi_code_cli",
     "source":"startup","model":"kimi-code/k3","profile":"agent"}
    
    21:38:56Z PAYLOAD:user-prompt-submit
    {"hook_event_name":"UserPromptSubmit","session_id":"session_84e5a55b-…",
     "cwd":"H:\tmp-kimi-hook-probe","client_type":"kimi_code_cli",
     "prompt":[{"type":"text","text":"…"}],"is_steer":false}
    

    The interactive runs produced no corresponding lines at all.

    Incidental finding that may help triage

    state.json records cwd with escaped backslashes in headless runs ("H:\tmp-kimi-hook-probe") and with forward slashes in interactive runs ("H:/tmp-kimi-hook-probe"), consistently across all five sessions. If those two paths are produced by different code paths, that may be a cheap marker for where the sessions diverge before hook wiring.

    On the intermittency reported earlier in this thread

    Earlier follow-ups here describe interactive sessions where hooks were alive (0.29.0), which is why I ran the interactive arm three times rather than once. All three were negative on 0.36.0/0.38.0. I am not claiming the race hypothesis is wrong — only that on these builds the interactive side was consistently dead across three attempts, while headless never failed.

    Environment

    • Windows 11 Enterprise, build 26200
    • kimi-code 0.36.0, then 0.38.0 (native single-binary install)
    • Hook interpreter: Git Bash 5.2.37 (bash.exe resolves ahead of the WSL launcher on PATH); jq, curl, git all resolve when bash is spawned from PowerShell
    • Hook scripts are LF-terminated (CRLF was ruled out explicitly)

    Raw trace logs and the per-session kimi-code.log files for all five sessions are available if useful.

    Note unrelated to this bug

    All runs returned APIStatusError 500 "The server had an error while processing your request" with retries up to turnStep 0.10. The cause was an expired subscription. A 500 for that condition is misleading — 402/403 with a clear message would have saved a fair amount of debugging. Happy to open that separately if it is not already tracked.

  11. Einherjare commented on Sep 11, 2026

    @Einherjare

    Configured [[permission.rules]] are still never loaded in 0.42.0: a deny rule blocks nothing, kimi -p included

    Still reproducible on 0.42.0 and on main at 72dbb9bb (11 Sep).
    Two updates to this thread: headless kimi -p is affected now too, and for a deny rule the failure is fail-open, so a rule meant as a guard blocks nothing.

    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) that returns one scripted Bash tool call, so the result does not depend on what a model decides.
    • Clean environment (env -i) apart from HOME, KIMI_CODE_HOME, PATH, KIMI_CODE_NO_AUTO_UPDATE=1 and KIMI_DISABLE_TELEMETRY=1.

    Steps to reproduce

    1. Add this to ~/.kimi-code/config.toml, next to your provider and model:

      [[permission.rules]]
      decision = "deny"
      pattern = "Bash"
      reason = "repro: Bash must be refused"

      It is a bare tool name, so path or glob matching (Permission-rule globs use path semantics for command-like subjects, so * never crosses / #2728) cannot be why it misses.

    2. mkdir -p ~/project && cd ~/project

    3. kimi -p 'Use the Bash tool to run exactly: echo REPRO-BASH-RAN > ran.txt; echo REPRO-BASH-RAN' --output-format stream-json

    4. ls ~/project/ran.txt

    The shorthand table form behaves the same: [permission] with deny = [{ pattern = "Bash" }].

    Expected

    The rule refuses the Bash call and ran.txt is not created.
    The docs say these rules "are automatically loaded when a session starts" (docs/en/configuration/config-files.md:508).
    In the policy chain user-configured-deny runs before auto-mode-approve, so a deny should hold in print mode's auto permission mode as well.

    Actual

    The command runs: the tool result is REPRO-BASH-RAN, ran.txt exists, the exit code is 0, and nothing is reported about the rule.
    Control: replacing the rule with [tools] disabled = ["Bash"] refuses the same scripted call with Tool "Bash" is disabled by the active tool policy.
    So the tool loop works, and only the rules are missing.
    I verified print mode.
    The source below is engine-level, so the same applies to every session the agent-core-v2 engine creates, the interactive TUI included.

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

    • packages/agent-core-v2/src/agent/permissionRules/configSection.ts:80-94: permissionFromToml folds rules and the deny / allow / ask shorthand into one rules array, and :145 registers the section.
      The only production read of the section is isDangerousCommandGuardEnabled (:65-69).
    • packages/agent-core-v2/src/agent/permissionRules/permissionRules.ts:29: addRules(rules: readonly PermissionRule[]): void is the only way rules enter the agent's rule state (implementation at permissionRulesService.ts:38-43).
      It has no caller outside test/.
      In the published dist/main.mjs, addRules occurs exactly once, in its own definition.
    • packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts:267-281: bindBootstrap applies default_permission_mode from config but never reads the permission section.
    • packages/agent-core-v2/src/agent/permissionPolicy/permissionPolicyService.ts:39-54: user-configured-deny is second in the chain (:41), ahead of auto-mode-approve (:45).
      It evaluates rulesService.rules (policies/user-configured-rule.ts:48), which stays empty.
    • On main at 72dbb9bb, bindBootstrap still has no addRules call.

    This matches the root cause posted in this thread on 2 Aug and the description in #2970, which was closed on 1 Sep without being merged.
    #2337 is still open.

    Workaround

    • Whole tools: [tools] disabled = [...] in config.toml is enforced (verified above).
      It cannot express a path or command argument, and it applies to the whole process.
    • Paths or commands: a PreToolUse hook that exits with code 2 does block, but a hook that crashes or times out lets the call through.
      For anything that must never be read, use OS file permissions.

    Version

    0.42.0 (npm latest on 11 Sep 2026), and still present on main at 72dbb9bb.
    Related: #2100, #3435, #2964; fix PRs #2337 (open) and #2970 (closed, not merged).

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