Skip to content

fix: make claude's own cron and wake-up tools ask crew first - #30270

Open
shubhamkurkure wants to merge 1 commit into
kirodotdev:mainfrom
shubhamkurkure:fix/claude-ask-before-native-schedulers
Open

shubhamkurkure wants to merge 1 commit into
kirodotdev:mainfrom
shubhamkurkure:fix/claude-ask-before-native-schedulers

Conversation

@shubhamkurkure

@shubhamkurkure shubhamkurkure commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On the Claude backend, Claude Code's own CronCreate, CronDelete and ScheduleWakeup calls ask Crew for approval before they run, in default and auto mode.

With agent.acp_backend = claude, in an ordinary chat in default mode, Claude can call CronCreate, CronDelete and ScheduleWakeup and they run with no session/request_permission. Crew's approval path never sees them: no hooks.on_tool_call, no deny rules, no SEL decision row. Crew sends no disallowedTools for them and its settings seed has no ask rules for them, and Crew's cron service has no record of the jobs Claude creates.

Why it matters

The Claude provider spec promises "By default, Claude asks and Crew decides". These three tools break that promise: an agent can schedule work that runs later, unattended, without the person ever approving it. A cron created with durable: true is written to <work dir>/.claude/scheduled_tasks.json, outlives the session, and can later fire inside another Claude Code session in that project, where Crew has no record of it at all.

Not a goal

  • Making Crew's cron service the only scheduler, or importing Claude's jobs into it. Claude's cron and wake-up tools still work once approved.
  • Removing the tools with disallowedTools or CLAUDE_CODE_DISABLE_CRON. That is a capability removal, not a gate.
  • The Agent (Task) tool launch. Native sub-agents are counted at the parent by design (harness-parity H16).
  • CronList. It only reads Claude's own job list, so asking adds a prompt and no protection.
  • Closing the existing gap where a session gets no seed and no exclusion (the same gap the deny rules already have).

What changed (motivation → approach → change)

  • Symptom: CronCreate, CronDelete and ScheduleWakeup run in default and auto with no permission request.
  • Root cause: these are tools Claude Code runs without calling canUseTool unless a rule says to ask, and nothing Crew sends carries such a rule.
  • Approach: a permissions.ask rule makes Claude Code send the call through canUseTool, which claude-agent-acp turns into session/request_permission, so Crew's normal approval path decides. With the rule, all three ask in default and in auto, on session/new and on session/load: live runs measured CronCreate, and a stub-API oracle measured CronDelete and ScheduleWakeup (see Manual verification). A reject stopped CronCreate and ScheduleWakeup in both modes, and CronDelete in default. This is smaller than disallowedTools, which would remove the tools outright.
  • Change: _render_claude_settings_payload (src/kiro_crew/acp/client_claude_seed.py) now adds _CLAUDE_SCHEDULER_ASK_RULES (CronCreate, CronDelete, ScheduleWakeup) to permissions.ask on every payload. The same payload is the seed file Crew writes and the inline options.settings the exclusion path sends when a project owns its settings.local.json, so one edit covers both. Side Chat's own read ask rules are appended after them as before.
  • The rules are added after the ask rules fix(acp): enforce a spec's toolsSettings allowlists on claude #30108 (now merged) writes for a spec's toolsSettings shell and write allowlists, so those keep their place and order, and a rule already in the list is not repeated.
  • Every log line for a session that runs without Crew's seed (a symlinked .claude, a declined share or refused exclusion, a replaced or unrecorded seed) now names the ask rules for Claude's own cron and wake-up tools among what it loses. The lost-items phrase is one shared constant, _CLAUDE_NO_SEED_LOSSES.
  • Seed ownership is unaffected: ownership, adoption and sharing compare whole payload bytes or digests, so a seed an older build left behind is adopted by its recorded digest and re-seeded with the new rules, exactly as a change to the deny rules is. A live sibling seed from an older build differs in its permissions and is not shared.
  • Spec: docs/system-specs/modules/claude-code-provider.md states the scheduler ask rules under "By default, Claude asks and Crew decides", the durable-cron fact, and lists the new key where the seed's and the inline settings' keys are listed.

Backwards compatibility

Compatible: every settings payload gains one permissions.ask list, which Claude Code already accepts; nothing that parses or compares the seed reads a fixed key set. The visible effect is that these three calls now show Crew's normal approval for a Claude tool call, as Bash already does.

Removes nothing: no key, path, record or function is removed or renamed, and the tools stay available once a call is approved.

Tests

  • test/test_claude_scheduler_ask_rules.py (new): the rule list names exactly CronCreate, CronDelete and ScheduleWakeup and not CronList; an ordinary chat's seed on disk carries them; a seed whose spec gives disabledTools and whose model cache is warm carries them beside the deny and model keys; a chat that requested auto keeps defaultMode: auto and still carries them; the exclusion path carries them inline and records them as shipped; a Side Chat on the exclusion path keeps both rule sets; an orphan seed an older build wrote is adopted and upgraded; a live older seed without the rules is not shared; a session that gets no seed (a project file it cannot leave out, or a .claude Crew may not write through) logs that it runs without these ask rules.
  • The exclusion-path test also pins that a project ask rule repeating CronCreate appears once. That dedup comes from the exclusion path's existing merge in _exclude_foreign_local_settings, not from the new block, and the test's docstring says so.
  • The deny-and-model test fails when the new block is gated on if not deny_rules: or on a cold model cache, and it is the only test that does.
  • test/test_acp_session_mcp_client_seam.py: test_the_project_tiers_ask_rules_ride_inline and test_a_side_read_only_session_keeps_the_exclusions_restrictions pinned the exact inline ask list; it now starts with Crew's scheduler rules. test_a_crew_authored_session_is_not_pinned asserted the seed had no permissions key as a stand-in for "no defaultMode"; it now asserts no defaultMode directly.
  • test/test_acp_session_mcp.py: test_no_permission_mode_leaves_the_adapter_default gets the same direct defaultMode assertion.
  • test/test_acp_claude_mode_pin_seam.py (from fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308, now merged): test_a_crew_authored_session_is_pinned_off_an_approving_mode and test_a_user_auto_start_with_crews_array_is_not_pinned asserted the unrequested seed had no permissions key; they now assert no defaultMode directly, the same change.
  • test/test_claude_spec_tool_settings.py (from fix(acp): enforce a spec's toolsSettings allowlists on claude #30108): the seeded ask list for a shell or write allowlist now ends with the scheduler rules, and a spec with no allowlist now seeds only the scheduler rules (test_the_seed_asks_only_about_schedulers_without_an_allowlist). New: test_a_left_out_project_file_keeps_every_ask_rule_once pins that when a project's own file is left out, the inline settings carry the shell and write rules, then the scheduler rules, then the project's own rule, each once, so neither merge drops the other's rules.
  • These existing tests are changed because the change IS the fix: every payload now has a permissions key and an ask list.
  • Determinism, after the rebase onto c970398: the 63 related test files (the touched ones, every test file that references the changed seed functions or settings.local.json, every seed or session-settings test file refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484 and feat: show the claude-agent-acp surfaces the dashboard drops #37512 changed, and every importer of the two seed test helpers) passed 3621 tests at -n 4 --dist loadgroup with KIROCREW_CC_PIN_INHERITED_MODE unset and again with it set to 1, and the test_acp_* and test_claude_* sweep passed 9972 tests (19 skipped). The new test file passed 20 runs at -n0 and 10 runs at -n 4 --dist loadgroup beside test_claude_spec_tool_settings.py, test_acp_seed_provenance.py and test_cc_permission_mode_seed.py, and the 310 tests of the five touched test files passed in a shuffled order (seed 12269).

Proof: PROVEN test/test_acp_session_mcp_client_seam.py::TestClientSeam::test_the_project_tiers_ask_rules_ride_inline, test/test_acp_session_mcp_client_seam.py::TestClientSeam::test_a_side_read_only_session_keeps_the_exclusions_restrictions, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_the_rules_name_the_scheduling_tools_and_not_cron_list, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_an_ordinary_chat_seed_asks_before_scheduling, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_a_seed_with_deny_rules_and_a_model_still_asks (head 3560211)

Gate proof: tree a672b6a56c4c; ran 24; skipped none

Manual verification

Live runs drove Crew's real AcpClient from this branch against claude-agent-acp 0.100.0 (Node 24.20.0) with Claude Code 2.1.318, a scratch CLAUDE_CONFIG_DIR carrying only the model-access keys, a scratch KIROCREW_HOME and agent spec, and one prompt per run asking Claude to CronCreate a session-only one-shot echo hi for January 1st and then call CronList. CronCreate permission requests were answered with Crew's own reject_tool.

  • Default mode, this branch: the seed carried permissions.ask: ["CronCreate", "CronDelete", "ScheduleWakeup"]; one session/request_permission titled CronCreate arrived; after the reject the tool call ended failed ("User refused permission to run tool") and CronList returned "No scheduled jobs."
  • Auto mode, this branch (permissions.defaultMode: auto in the scratch user tier; session/new reported currentModeId: auto): the same single CronCreate request arrived, the reject stopped it, and CronList returned "No scheduled jobs."
  • Control, parent commit, default mode: the seed had no permissions; no permission request was sent; CronCreate created job 83c95a3a (session-only) and CronList listed it. It died with the adapter when the run stopped.
  • No run wrote .claude/scheduled_tasks.json, and no adapter process was left running.

Stub-API oracle runs (no model call) cover CronDelete and ScheduleWakeup in auto and on session/load. They drove claude-agent-acp 0.100.0 with its bundled Claude Code 2.1.316 over ACP, with a stub Messages API bound to 127.0.0.1 that answered each turn with a scripted tool call, and scratch HOME and CLAUDE_CONFIG_DIR. Script per session: CronCreate (rejected), CronCreate (allowed), CronDelete of that job (allowed), ScheduleWakeup (rejected), CronList.

  • With the rules, on the seed path and on the exclusion path, in default and in auto (user-tier defaultMode: auto with currentModeId: auto, and after session/set_mode to auto), and again on session/load in a fresh adapter process: one session/request_permission each for CronCreate (twice), CronDelete and ScheduleWakeup, and none for CronList. The rejected calls ended failed and CronList then showed no jobs.
  • Controls without the rules, in default, in auto and on session/load: no permission request was sent.
  • A separate design probe in default mode rejected a CronDelete of a real job, and CronList still listed the job afterwards.

Trade-offs and questions for a maintainer

  • ScheduleWakeup is how Claude Code's /loop re-arms, and a whole-tool rule cannot tell a re-arm from a new loop. A /loop the person started now asks on every re-arm, including turns nobody watches, where an unanswered card times out as a reject and the loop stops. Is that the intended cost?
  • RemoteTrigger (claude.ai remote routines: create, update, run) is not in the list. It needs a claude.ai login, and no run here showed whether it runs without asking, so it is left out rather than guessed at. Should it be added here or in a follow-up?
  • The adapter still offers "Yes, and don't ask again" on these requests. If Crew answers with it, Claude Code may persist an allow rule, but ask rules are checked before allow rules, so the next call asks again.
  • fix(acp): enforce a spec's toolsSettings allowlists on claude #30108 now sends a spec's shell and write ask rules in _claude_session_meta options.settings (the flag tier) whenever a spec sets an allowlist. The three scheduler rules could join that list on every claude session. That would cover the no-seed paths (a symlinked .claude, a declined project file, a failed seed write) at the cost of putting options.settings on every session. Should that be done here or in a follow-up?
  • Under a user-tier defaultMode: dontAsk, an ask becomes a deny, so these three calls are now denied outright instead of running.

Related Issues

Part of #30172

Still open in #30172 after this PR: the policy for the sub-agent launch (the Agent tool), Workflow, SendMessage and TaskStop; Crew's cron service still has no record of Claude's crons and wake-ups and cannot list or cancel them; and the comment at src/kiro_crew/agent_sdk/backends_routing.py (lines 185-190) still says no session/request_permission frame carrying parentToolUseId has been recorded, which this PR does not change.

Sibling sweep

Swept: git grep -n "_render_claude_settings_payload()|options["settings"] =" -- src/
Sibling: src/kiro_crew/acp/client_claude_session.py:609 -- not affected -- the exclusion path ships the rendered payload inline, so it carries the rules; the #30108 allowlist ask rules (line 625) and the ask rules for bridged Crew-owned Connections (line 637) merge into that list without dropping entries and add nothing when the session has neither (see the maintainer question above); Side Chat (line 690) builds on the inline settings and runs only read built-ins; the auto-memory switch (line 702) copies the settings and only adds env

Pattern harvest

Not generalizable: the defect is specific to which Claude Code built-in tools skip canUseTool by default; the fix is a data list beside the deny rules, not a code shape a rule could catch.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-ask-before-native-schedulers branch from 861af89 to 099ed85 Compare November 5, 2026 19:11
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-ask-before-native-schedulers branch from 099ed85 to ff12db7 Compare November 6, 2026 08:13
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 6, 2026
@shubhamkurkure

Copy link
Copy Markdown
Contributor Author

Hi @bolichen97 and @chenmingwei23, when you have a moment, would you mind reviewing this PR? It covers part of #30172: on the Claude backend, Claude Code's own CronCreate, CronDelete and ScheduleWakeup calls now ask Crew for approval before they run, in default and auto mode. The parts of #30172 it leaves open are listed in the comment I posted on the issue today. It merges cleanly with current main.

Please let me know if you would like anything changed. Thank you for your time!

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 15, 2026
On the claude backend, CronCreate, CronDelete and ScheduleWakeup ran
in default and auto mode with no session/request_permission, so Crew's
approval path never saw work Claude scheduled for later, and Crew's
cron service has no record of it. Every settings payload Crew renders
now carries a permissions.ask rule for each, merged with any ask rules
already there, so the seed and the exclusion path's inline settings
both send these calls to Crew's gate. CronList only reads and stays
unprompted. The log lines for a session that runs without Crew's seed
now name these rules among what it loses.

Part of kirodotdev#30172
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-ask-before-native-schedulers branch from ff12db7 to 3560211 Compare November 15, 2026 11:36
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

The PR adds permissions.ask rules for CronCreate, CronDelete and ScheduleWakeup to every Claude settings payload. That one payload is both the seed file and the inline settings on the exclusion path, so one edit covers both. I checked every reader of the payload: the exclusion merge (adds project rules once, drops none), the session envelope's allowlist and Connection ask merges and the Side Chat merge (all keep existing entries), the shipped-restrictions record, sibling-seed sharing (compares permissions, so an older build's live seed isn't shared), and digest-based adoption of an orphan seed from an older build (re-seeded with the new rules). Nothing in src/ treats a missing permissions key as a signal. No test that still asserts no permissions key on a Claude seed is left. The new tests would fail without the change and cover the seed, deny-plus-model, auto, exclusion, Side Chat, upgrade, no-share and no-seed log paths. The change only tightens the trust boundary, sending calls that ran unasked through Crew's approval. The trade-offs (/loop re-arm prompts, dontAsk now denies, the no-seed gap) are disclosed and consistent with the goal.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 3560211b2a · 358 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 15, 2026

This branch has not been deployed

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

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants