You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk hook opencode returns empty {} for kubectl/oc/npm despite working rewrites in rtk rewrite (1.0.1) #4638
**Summary:**rtk hook opencode -- returns {} (no rewrite) for kubectl, oc, and npm commands, even though rtk rewrite correctly produces a rewrite for the same input. git and aws are unaffected — both rewrite correctly through hook opencode.
Repro::
`$ rtk hook opencode -- kubectl get pods
{}
$ rtk rewrite kubectl get pods; echo "exit: $?"
rtk kubectl get pods
exit: 3
$ rtk hook opencode -- npm run build
{}
$ rtk rewrite npm run build; echo "exit: $?"
rtk npm run build
exit: 0
Impact:: OpenCode’s permission system never sees the rtk-prefixed form for these three command types, so any rtk -only allow rules are silently inert — only bare-command permission rules take effect, regardless of what’s configured.
Config: : none of kubectl, oc, npm were in exclude_commands at time of testing (confirmed via cat ~/.config/rtk/config.toml).
Untested:: gcloud, az, oci weren’t checked against hook opencode at time of filing — gcloud is still in exclude_commands on this box, az/oci config wasn’t present to test. Scope of affected commands beyond the five checked (git, aws, kubectl, oc, npm) is unconfirmed.
OpenCode plugin's hook path fails to rewrite kubectl/oc/npm (returns {}) while rtk rewrite works correctly for the same commands, silently defeating rtk-prefixed permission rules.
📁 Relevant files
src/hook/opencode.rs
src/rewrite/mod.rs
src/commands/kubectl.rs
src/commands/npm.rs
Suggested Actions
Diff hook opencode vs rewrite code paths to find why kubectl/oc/npm diverge from git/aws
Ask reporter to test gcloud/az/oci and share full config.toml to narrow affected-command scope
Check if kubectl/oc/npm share a command-dispatch branch that opencode's hook handler skips
Hi! I'd like to investigate and work on this issue. I will reproduce the behavior across kubectl, oc, npm (and check other cloud/CLI wrappers) in rtk hook opencode vs rtk rewrite, inspect the dispatch/permission logic, and add regression tests for the fix. Could you assign this to me?
Hi @sungod808, @KuSh! I investigated and reproduced the exact symptom on develop (7a73af1b).
1. Root Cause & Reproduction
There is no dispatch difference between kubectl/oc/npm and git/aws in src/discover/rules.rs — with no permission config files present, rtk hook opencode -- <cmd> rewrites all five commands ({"command":"rtk ..."}).
The behavior reported here comes from the interaction of two separate permission evaluators:
Why rtk rewrite returned exit: 3 for kubectl vs exit: 0 for npm: rtk rewrite (src/hooks/rewrite_cmd.rs:91) evaluates Claude Code rules (Host::Claude, reading .claude/settings.json), where 0 is AllowRewrite and 3 is AskRewrite (which includes PermissionVerdict::Default when no Claude rule matches). Having Bash(npm:*) allowed in .claude/settings.json yields exit: 0 for npm and exit: 3 for kubectl, independent of OpenCode.
Why rtk hook opencode returned {} for kubectl/oc/npm while rewriting git/aws:
In src/hooks/hook_cmd.rs:1313–1331, opencode_rewrite_answer evaluates before = permissions_opencode::check_command(&raw_cmd) and after = permissions_opencode::check_command(&rewritten), returning {} whenever before != after.
When opencode.json contains rtk-prefixed allow rules (e.g. "rtk *": "allow" or "rtk kubectl *": "allow") alongside bare "git *": "allow" and "aws *": "allow" (without bare rules for kubectl/oc/npm):
kubectl get pods$\rightarrow$before = Default (no rule matched the bare command), after = Allow (matched the rtk allow rule). Because Default != Allow, hook_cmd.rs:1330 suppresses the rewrite and outputs {}.
Minimal opencode.json + .claude/settings.json that reproduces all outputs from the issue description verbatim:
As noted in #4422, OpenCode's built-in default action when no rule matches is allow, whereas permissions_opencode represents "no matching rule" as PermissionVerdict::Default (which is unequal to PermissionVerdict::Allow in before != after).
Would you like a PR that allows the rewrite in opencode_rewrite_answer when (before, after) transitions between Default and Allow (specifically when before == Default && after == Allow, or by aligning Default with OpenCode's built-in Allow when no ask/deny rule matched), while keeping all existing Ask/Deny and #4195 protections intact? I'd be happy to take this on if you can assign it to me!
Thanks @feliperm17, the reproduction matches what I see. The rtk rewrite exit codes come from Claude Code's rules, so they don't depend on OpenCode. The {} comes from Default versus Allow in opencode_answer, which I noted in #4422: OpenCode 1.18.34 puts * → allow ahead of the user's rules, and rtk reads "no rule matched" as a verdict of its own.
Two things bear on where a fix should go:
fix(hooks): load a host's permission rules once, OpenCode included #4458 is open and restructures that code path (HostRules, decide_for_host). A patch against opencode_answer on develop would conflict with it, and its differential shows rtk hook opencode answers unchanged, so it doesn't close this one.
If you'd like to work on this, #4521 is the direction I'd point to, built on #4458 once it lands. It needs a 2.x install, a plugin change that forwards the payload on stdin, and a forwarded-rules source in the loader. The 1.x case (Default treated as Allow when every rule source is readable) could be a small follow-up on top of #4458. Either one is fine by me. I'm offering the pointers, not asking anyone to take them on.
@sungod808, could you share your opencode.json (the permission.bash block) and opencode --version? That tells us whether you're on the 1.x or the 2.x case.
Thanks for the pointers, @KuSh! That makes total sense.
I'd like to take on the 1.x follow-up (Default treated as Allow when every rule source is readable) built on top of #4458. I'll fetch #4458 locally (HostRules / decide_for_host) to prepare and test the change so it's ready to open cleanly once #4458 lands on develop.
3. Hi! I'd like to investigate and work on this issue. I will reproduce the behavior across kubectl, oc, npm (and check other cloud/CLI wrappers) in rtk hook opencode vs rtk rewrite, inspect the dispatch/permission logic, and add regression tests for the fix. Could you assign this to me?
Thanks for the deep dive — this matches our reproduction exactly. We hit the same symptom (kubectl/oc/npm/gcloud silently returning {} from rtk hook opencode while git/aws rewrite fine) across five separate boxes, all on RTK 1.0.1, with the same shape of config you reproduced: "rtk *": "allow" plus bare allow rules for git and aws but none for kubectl/oc/npm/gcloud. Good to have the actual Default-vs-Allow mechanism confirmed — we’d been treating the rtk-prefixed permission twins as functionally inert while this was open.
The Default→Allow fix sounds right to us — treating “no ask/deny rule matched” the same as explicit Allow when deciding whether to emit the rewrite seems like the correct behavior given OpenCode’s own default-allow semantics, and keeping Ask/Deny and the #4195 protections untouched is the important constraint. Please go ahead with the PR if you’re able to take it on — happy to test it against our setup once it’s up.
Thanks @sungod808, @KuSh! I've opened #4926 stacked on top of #4458 implementing the 1.x follow-up (Default mapped to Allow in HostRules::verdict when all selected OpenCode rule sources are readable, failing closed to Unjudgeable/{} if a selected config or agent file cannot be read or parsed).
@sungod808 feel free to pull the branch from #4926 if you'd like to test it against your 5 boxes!
Activity
rtk-wshm-sync-bot commentedon Oct 18, 2026
🔍 Automated Triage
bughighSummary
OpenCode plugin's hook path fails to rewrite kubectl/oc/npm (returns {}) while
rtk rewriteworks correctly for the same commands, silently defeating rtk-prefixed permission rules.📁 Relevant files
src/hook/opencode.rssrc/rewrite/mod.rssrc/commands/kubectl.rssrc/commands/npm.rsSuggested Actions
hook opencodevsrewritecode paths to find why kubectl/oc/npm diverge from git/awsrtk hook check --agent opencodejudges differently from the plugin #4518 (hook check judging differently from plugin) for related opencode hook logic gapsTriaged automatically by wshm · This is an automated analysis, not a human review.
feliperm17 commentedon Oct 28, 2026
Hi! I'd like to investigate and work on this issue. I will reproduce the behavior across
kubectl,oc,npm(and check other cloud/CLI wrappers) inrtk hook opencodevsrtk rewrite, inspect the dispatch/permission logic, and add regression tests for the fix. Could you assign this to me?feliperm17 commentedon Oct 28, 2026
Hi @sungod808, @KuSh! I investigated and reproduced the exact symptom on
develop(7a73af1b).1. Root Cause & Reproduction
There is no dispatch difference between
kubectl/oc/npmandgit/awsinsrc/discover/rules.rs— with no permission config files present,rtk hook opencode -- <cmd>rewrites all five commands ({"command":"rtk ..."}).The behavior reported here comes from the interaction of two separate permission evaluators:
Why
rtk rewritereturnedexit: 3forkubectlvsexit: 0fornpm:rtk rewrite(src/hooks/rewrite_cmd.rs:91) evaluates Claude Code rules (Host::Claude, reading.claude/settings.json), where0isAllowRewriteand3isAskRewrite(which includesPermissionVerdict::Defaultwhen no Claude rule matches). HavingBash(npm:*)allowed in.claude/settings.jsonyieldsexit: 0fornpmandexit: 3forkubectl, independent of OpenCode.Why
rtk hook opencodereturned{}forkubectl/oc/npmwhile rewritinggit/aws:In
src/hooks/hook_cmd.rs:1313–1331,opencode_rewrite_answerevaluatesbefore = permissions_opencode::check_command(&raw_cmd)andafter = permissions_opencode::check_command(&rewritten), returning{}wheneverbefore != after.When
opencode.jsoncontainsrtk-prefixed allow rules (e.g."rtk *": "allow"or"rtk kubectl *": "allow") alongside bare"git *": "allow"and"aws *": "allow"(without bare rules forkubectl/oc/npm):git statusbefore = Allow,after = Allow(before == after{"command":"rtk git status"}).kubectl get podsbefore = Default(no rule matched the bare command),after = Allow(matched thertkallow rule). BecauseDefault != Allow,hook_cmd.rs:1330suppresses the rewrite and outputs{}.Minimal
opencode.json+.claude/settings.jsonthat reproduces all outputs from the issue description verbatim:opencode.json:{"permission":{"bash":{"rtk *":"allow","git *":"allow","aws *":"allow"}}}.claude/settings.json:{"permissions":{"allow":["Bash(npm:*)"]}}2. Proposed Fix / Question
As noted in #4422, OpenCode's built-in default action when no rule matches is
allow, whereaspermissions_opencoderepresents "no matching rule" asPermissionVerdict::Default(which is unequal toPermissionVerdict::Allowinbefore != after).Would you like a PR that allows the rewrite in
opencode_rewrite_answerwhen(before, after)transitions betweenDefaultandAllow(specifically whenbefore == Default && after == Allow, or by aligningDefaultwith OpenCode's built-inAllowwhen noask/denyrule matched), while keeping all existingAsk/Denyand#4195protections intact? I'd be happy to take this on if you can assign it to me!KuSh commentedon Oct 29, 2026
Thanks @feliperm17, the reproduction matches what I see. The
rtk rewriteexit codes come from Claude Code's rules, so they don't depend on OpenCode. The{}comes fromDefaultversusAllowinopencode_answer, which I noted in #4422: OpenCode 1.18.34 puts*→ allow ahead of the user's rules, and rtk reads "no rule matched" as a verdict of its own.Two things bear on where a fix should go:
HostRules,decide_for_host). A patch againstopencode_answeron develop would conflict with it, and its differential showsrtk hook opencodeanswers unchanged, so it doesn't close this one.ctx.agent.get) #4521 removes the gap.ctx.agent.get({ agentID }).data.permissionscomes back already resolved with OpenCode's defaults first, soDefaultnever reaches the comparison.If you'd like to work on this, #4521 is the direction I'd point to, built on #4458 once it lands. It needs a 2.x install, a plugin change that forwards the payload on stdin, and a forwarded-rules source in the loader. The 1.x case (
Defaulttreated asAllowwhen every rule source is readable) could be a small follow-up on top of #4458. Either one is fine by me. I'm offering the pointers, not asking anyone to take them on.@sungod808, could you share your
opencode.json(thepermission.bashblock) andopencode --version? That tells us whether you're on the 1.x or the 2.x case.feliperm17 commentedon Oct 29, 2026
Thanks for the pointers, @KuSh! That makes total sense.
I'd like to take on the 1.x follow-up (
Defaulttreated asAllowwhen every rule source is readable) built on top of #4458. I'll fetch #4458 locally (HostRules/decide_for_host) to prepare and test the change so it's ready to open cleanly once #4458 lands ondevelop.sungod808 commentedon Oct 30, 2026
Thanks for the deep dive — this matches our reproduction exactly. We hit the same symptom (kubectl/oc/npm/gcloud silently returning {} from rtk hook opencode while git/aws rewrite fine) across five separate boxes, all on RTK 1.0.1, with the same shape of config you reproduced: "rtk *": "allow" plus bare allow rules for git and aws but none for kubectl/oc/npm/gcloud. Good to have the actual Default-vs-Allow mechanism confirmed — we’d been treating the rtk-prefixed permission twins as functionally inert while this was open.
The Default→Allow fix sounds right to us — treating “no ask/deny rule matched” the same as explicit Allow when deciding whether to emit the rewrite seems like the correct behavior given OpenCode’s own default-allow semantics, and keeping Ask/Deny and the #4195 protections untouched is the important constraint. Please go ahead with the PR if you’re able to take it on — happy to test it against our setup once it’s up.
feliperm17 commentedon Nov 1, 2026
Thanks @sungod808, @KuSh! I've opened #4926 stacked on top of #4458 implementing the 1.x follow-up (
Defaultmapped toAllowinHostRules::verdictwhen all selected OpenCode rule sources are readable, failing closed toUnjudgeable/{}if a selected config or agent file cannot be read or parsed).@sungod808 feel free to pull the branch from #4926 if you'd like to test it against your 5 boxes!