Skip to content

rtk hook copilot no-op in JetBrains/IntelliJ Copilot plugin — camelCase run_in_terminal not matched, and IDE host only honors permissionDecision: deny #2443

Closed

Description

@kreuzerkrieg

Summary

rtk hook copilot is a silent no-op inside the JetBrains / IntelliJ GitHub Copilot plugin (CLion, IDEA, Rider, etc., agent mode). The IDE's terminal tool is named run_in_terminal and is delivered in the camelCase payload shape (toolName + toolArgs), which detect_format() only matches when toolName == "bash". As a result the hook fires but never rewrites anything, and rtk gain stays empty.

This is distinct from #1425 / PR #1800: those address the snake_case (tool_name) VS Code Chat path. PR #1800's new CamelCaseCmd branch still only matches toolName == "bash", so it does not fix the JetBrains IDE case.

There is also a second, host-side blocker (see "Host limitation" below) that means transparent modifiedArgs rewriting cannot work in this plugin at all today.

Environment

  • rtk 0.42.2
  • GitHub Copilot plugin for JetBrains (github-copilot-intellij, core 1.11.0-rc.x), agent mode, on CLion 2026.1, Linux
  • Hook installed at both ~/.copilot/hooks/rtk-rewrite.json and project .github/hooks/rtk-rewrite.json, event preToolUse

Hard evidence — the real payload

Captured by tee-ing the hook's stdin to a file. A terminal command from the agent produces:

{
  "timestamp": 1781456705251,
  "cwd": ".",
  "toolName": "run_in_terminal",
  "toolArgs": "{\"command\":\" cd /path/to/repo && git --no-pager log --oneline -20\",\"explanation\":\"Show local git history\",\"isBackground\":false}"
}

Notes:

  • toolName is camelCase and the value is run_in_terminal, not bash.
  • toolArgs is a JSON-encoded string containing command (plus explanation, isBackground which must be preserved).
  • The hook also receives MCP tool calls here, e.g. "toolName": "io.github.github/github-mcp-server/list_commits" — those should keep passing through.

Reproduce directly against the binary:

$ echo '{"toolName":"run_in_terminal","toolArgs":"{\"command\":\"git --no-pager log --oneline -20\"}"}' | rtk hook copilot
            # (no output)

$ echo '{"toolName":"bash","tool_input":{"command":"git --no-pager log --oneline -20"}}' | rtk hook copilot
            # also nothing for the snake_case tool_input shape

$ echo '{"tool_name":"bash","tool_input":{"command":"git --no-pager log --oneline -20"}}' | rtk hook copilot
{"hookSpecificOutput":{...,"updatedInput":{"command":"rtk git --no-pager log --oneline -20"}}}   # only "bash" works

Root cause (code)

src/hooks/hook_cmd.rs, detect_format() — camelCase branch:

if let Some(tool_name) = v.get("toolName").and_then(|t| t.as_str()) {
    if tool_name == "bash" {          // <-- JetBrains sends "run_in_terminal"
        ...
    }
    return HookFormat::PassThrough;
}

run_in_terminal is missing from the camelCase match. (PR #1800 keeps the same tool_name == "bash" condition in CamelCaseCmd, so it remains unfixed there.)

Host limitation — modifiedArgs is ignored in the JetBrains IDE

Even after recognizing run_in_terminal, transparent rewrite won't take effect in this plugin. The IDE agent host (copilot-agent/dist/main.js) invokes the hook and then inspects only permissionDecision:

let o = await ...hook(t, P3, {timestamp, cwd, toolName, toolArgs}, e);
for (let s of o) {
  let c = s.output;
  if (c && c.permissionDecision === deny)
    return { permissionDecision: "deny", permissionDecisionReason: ... };
}

modifiedArgs and hookSpecificOutput.updatedInput are never read (0 occurrences in main.js; they exist only in the bundled @github/copilot SDK, which this agent path does not use). So in the JetBrains IDE the only effective hook action is permissionDecision: "deny" (with a reason).

This means a complete fix needs a deny-with-suggestion path for the IDE: deny the raw command and surface the rtk-rewritten command in permissionDecisionReason, letting the model re-issue rtk … (which then passes through). rtk already advertises "deny-with-suggestion" for Copilot CLI, so the mechanism exists.

Suggested fix

  1. Recognize run_in_terminal (camelCase toolName) in detect_format() in addition to bash.
  2. For the JetBrains/IDE case (where modifiedArgs is ignored), respond with permissionDecision: "deny" + a permissionDecisionReason containing the rewritten command, instead of (or in addition to) modifiedArgs.
  3. Optionally cover other IDE tool names defensively. Note that get_terminal_output (the "read terminal output" tool) carries no command, so it correctly needs no rewrite — only run_in_terminal does.

Tool inventory (JetBrains Copilot built-ins, for reference)

run_in_terminal, get_terminal_output, read_file, create_file, insert_edit_into_file, replace_string_in_file, list_dir, file_search, grep_search, semantic_search, run_subagent, open_file, get_errors, ask_questions, validate_cves. Only run_in_terminal runs a shell command.

Related: #1425, #1839, #1800.

Activity

  1. added
    bug
    help wanted
    on Jun 14, 2026
  2. pszymkowiak commented on Jun 14, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 91%

    Summary

    rtk hook copilot silently no-ops in JetBrains Copilot plugin because run_in_terminal is unrecognized in detect_format()'s camelCase branch; complete fix also requires a deny-with-suggestion response path since the IDE host ignores modifiedArgs entirely

    📁 Relevant files
    • src/hooks/hook_cmd.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. kreuzerkrieg commented on Jun 14, 2026

    @kreuzerkrieg
    Author

    Update: confirmed end-to-end + working PoC fix

    Followed up with live testing on CLion 2026.1 (Copilot plugin core 1.11.0-rc.x). Three findings, all verified against the running agent.

    1. The IDE loads hooks only from .github/hooks/ (not ~/.copilot/hooks/)

    The IntelliJ agent registers exactly one hook source:

    // copilot-agent/dist/main.js
    register("hook", [".github/hooks/**/*.json"])   // oJo = ".github/hooks/**/*.json"

    There is no global/user hooks dir for the IDE — ~/.copilot/hooks/ is Copilot-CLI-only. So a machine-global rtk hook silently does nothing in JetBrains IDEs; it must be committed/placed per-repo under .github/hooks/.

    2. The real payload uses camelCase toolName: "run_in_terminal"

    Captured by tee-ing the hook's stdin:

    {"timestamp":...,"cwd":".","toolName":"run_in_terminal",
     "toolArgs":"{\"command\":\" cd /repo && git --no-pager log --oneline -20\",\"explanation\":\"...\",\"isBackground\":false}"}

    This hits the camelCase branch of detect_format(), which only matched toolName == "bash" → no-op. (PR #1800's CamelCaseCmd keeps the same == "bash" condition, so it doesn't cover this either.)

    3. The IDE host honors only top-level permissionDecision: "deny"

    modifiedArgs/updatedInput are ignored by the IntelliJ host (0 occurrences in main.js; only present in the bundled @github/copilot SDK, which this agent path doesn't use). The hook output is JSON.parse(stdout) and only output.permissionDecision === "deny" is acted upon. So transparent rewrite is impossible here — deny-with-suggestion is the only mechanism that works.

    PoC fix (proof of concept — verified working)

    Implemented locally in src/hooks/hook_cmd.rs:

    • detect_format() recognizes camelCase run_in_terminal → new CopilotIde variant (camelCase bash stays on the existing CLI modifiedArgs path — no regression).
    • handle_copilot_ide() emits a top-level deny-with-suggestion when a beneficial rewrite exists; stays silent (command runs) for already-rtk, non-rewritable, and MCP tool calls.
    fn copilot_ide_response_from_decision(decision: HookDecision, cmd: &str) -> Option<Value> {
        let reason = match decision {
            HookDecision::Defer => return None,
            HookDecision::Deny => { audit_log("deny", cmd, ""); "Blocked by RTK permission rule".into() }
            HookDecision::AllowRewrite(r) | HookDecision::AskRewrite(r) => {
                audit_log("rewrite", cmd, &r);
                format!("RTK token optimization: re-run this command as `{r}` instead.")
            }
        };
        Some(json!({ "permissionDecision": "deny", "permissionDecisionReason": reason }))
    }

    Added unit tests (detection, deny-with-suggestion, passthrough cases, bash no-regression); full hook_cmd suite passes (82/82).

    End-to-end verification in CLion

    Proof-log of two consecutive run_in_terminal calls in one turn:

    20:30:14  toolName:"run_in_terminal" → git pull --rebase … ; git --no-pager log --oneline -20      (raw)
    20:30:18  toolName:"run_in_terminal" → rtk git pull --rebase … ; rtk git --no-pager log --oneline -20  (retried)
    

    The agent was denied on the raw command, read the suggestion, and re-issued the rtk … form ~4s later. rtk gain went from "No tracking data yet" to tracking the commands.

    Note / open design question

    Deny-with-suggestion means each rewritable command is denied once and retried — slightly noisier than transparent rewrite, but it's the only option until the IntelliJ host adds modifiedArgs/updatedInput support. Happy to open a PR with the above if the maintainers are OK with the deny-with-suggestion approach for the IDE path (gated on toolName == "run_in_terminal", leaving Copilot CLI's bash → modifiedArgs path untouched).

  4. lntutor commented on Jul 20, 2026

    @lntutor
    Contributor

    I am working on this against current develop. I will add a dedicated camelCase run_in_terminal host path that emits top-level deny-with-suggestion responses, preserve Copilot CLI bash modifiedArgs behavior, and cover rewrite, deny, defer, and passthrough cases.

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

    area:clibughelp wantedpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions