Repository navigation
Description
Summary
rtk cannot read opencode.jsonc. It parses the file with a strict JSON parser, which rejects comments, so the whole file fails to load and rtk sees zero permission rules from it.
The consequence is that a single // comment line silently disables every permission rule in that file for rtk's rewrite path. The user still has rules configured; rtk just cannot see them, and it says nothing at the point where it matters.
What happens
A user writes the file the way OpenCode's docs show it:
// opencode.jsonc
{
// never push from this project
"permission": { "bash": { "git push *": "deny" } }
}read_configcallsutils::from_json_str, which is plainserde_json::from_str.serde_jsonstops at the first//.read_configprints[rtk] warning: failed to parse permissions from <path>to stderr and returnsNone.load_opencode_rulesends up with no rules.check_command_with_opencode_rulesreturnsDefault, notDeny.opencode_answercomputesbefore = Default, rewritesgit push origin maintortk git push origin main, computesafter = Default, sees them equal, and returns the rewrite.
OpenCode then evaluates permissions on the rewritten string. The rule git push * does not match rtk git push origin main, so the deny never fires and the command runs.
Why this matters
rtk's guard exists precisely to stop a rewrite from changing what the user's rules decide. It compares the verdict before and after — but both verdicts come from the rules rtk read. When the file fails to parse, both say "no rule matched", the comparison succeeds, and the guard reports that nothing changed. The property holds only while the rules load, and the failure mode of loading is the one case where it cannot notice.
djbclark reproduced the underlying mechanism on 2.0.26 in #4187: execute.before runs before permission evaluation, so the engine judges the string the plugin handed back.
Scope
permissions_opencode.rs is the only reader of .jsonc in the tree, and there is no comment-stripping helper anywhere in src/. JSONC also permits trailing commas, which serde_json rejects for the same reason.
Suggested fix
Strip comments and trailing commas before parsing, honouring string literals so a path like "//server/share" survives. src/discover/lexer.rs already walks bytes with in-string and in-quote state, so the tokenizer exists.
Worth doing alongside:
- Treat an unparsable file as "rules present, refuse to rewrite" rather than "no rules". An unreadable policy file should fail closed, the same way an unreadable agent markdown file does after feat(hook/opencode): support OpenCode V2, Desktop, and Windows (#3463, #3326) #4187. Silently continuing is what turns a typo into lost enforcement.
- Decide what the stderr warning is for. It is currently the only signal, and it lands on the same stream as ordinary output.
Verification
Confirmed on develop at 27a659f5: a test writing opencode.jsonc with one // comment and a git push * deny rule reports rules seen = [].
Not verified: the behaviour on a real OpenCode session, and whether OpenCode's own matcher would catch the rewritten command. The bypass follows from the pattern no longer matching the string, not from a reproduced OpenCode run.
Activity
rtk-wshm-sync-bot commentedon Oct 12, 2026
🔍 Automated Triage
bughighSummary
JSONC comments/trailing-commas in opencode.jsonc cause silent parse failure, dropping all permission rules and letting rtk rewrite past a
denyrule unnoticed.📁 Relevant files
src/permissions_opencode.rssrc/discover/lexer.rssrc/utils.rsSuggested Actions
Triaged automatically by wshm · This is an automated analysis, not a human review.
amnesiaof commentedon Oct 12, 2026
File paths in the automated triage are wrong on two of three. The real ones:
src/hooks/permissions_opencode.rs—read_configat :204,CONFIG_NAMESat :196,opencode_configsat :167src/core/utils.rs—from_json_strat :98, which is plainserde_json::from_strsrc/discover/lexer.rs— the string-aware byte walker, correct as listedAlso
#4349is a pull request, not an issue: it is the delegation change that introduced this path, and the test it added is intests/hook_decision_protocol_test.rs.The diagnosis in the triage is right and needs no correction.