Skip to content

Add hook support for Trae IDE (PreToolUse on RunCommand tool) #3234

Closed

Description

@gjw-rx

Summary

Request native hook support for Trae IDE (ByteDance's agentic IDE), enabling rtk init --agent trae or rtk hook trae. The hook should rewrite Bash-equivalent commands issued via Trae's RunCommand tool before execution, so RTK's compact output reaches the Trae-bound LLM.

Background

RTK already ships hooks for Claude Code, Cursor, Gemini CLI, Copilot, and Factory Droid. Trae IDE (agentic IDE from ByteDance, not the open-source trae-agent) is a growing user base that supports the same PreToolUse/PostToolUse hook protocol, but uses a different command-execution tool name and a slightly different hook config location.

I've verified the gap experimentally:

Step Result
rtk hook claude with tool_name: "Bash" stdin ✅ Returns {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"}}}
rtk hook claude with tool_name: "RunCommand" stdin (Trae's tool name) ❌ No rewrite — rtk passes through silently (tool name unrecognized)
rtk hook cursor with tool_name: "RunCommand" ❌ Same — no rewrite

So even though Trae speaks the Claude-Code-compatible stdin protocol, RTK's Bash-only tool-name match means Trae commands are never rewritten.

Trae's Hook Protocol (verified)

Config file

  • Path: ~/.trae-cn/hooks.json (user-global; also ~/.trae/hooks.json on some builds)
  • Format — same shape as Claude Code's settings.json hooks:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "RunCommand",
        "hooks": [
          { "type": "command", "command": "rtk hook trae" }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "RunCommand",
        "hooks": [
          { "type": "command", "command": "rtk hook trae --post" }
        ]
      }
    ]
  }
}

stdin payload (PreToolUse)

Same fields as Claude Code, except tool_name is RunCommand instead of Bash:

{
  "hook_event_name": "PreToolUse",
  "session_id": "...",
  "cwd": "D:\\project\\path",
  "tool_name": "RunCommand",
  "tool_input": {
    "command": "git status",
    "blocking": true,
    "command_type": "short_running_process",
    "requires_approval": false
  }
}

Expected stdout response (PreToolUse)

Trae accepts the same hookSpecificOutput.updatedInput JSON shape as Claude Code:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecisionReason": "RTK auto-rewrite",
    "updatedInput": { "command": "rtk git status" }
  }
}

Exit code semantics appear identical to Claude Code (0 = proceed, 2 = block).

Key differences from Claude Code

Claude Code Trae IDE
Command tool name Bash RunCommand
Config file ~/.claude/settings.json ~/.trae-cn/hooks.json
tool_input fields {command} {command, blocking, command_type, requires_approval}
Init command (proposed) rtk init -g rtk init -g --agent trae

Proposed Implementation (minimal)

  1. Add Trae variant to the hook agent enum in src/hooks/ (alongside Claude, Cursor, Gemini, Copilot, Droid).
  2. In the PreToolUse processor, match tool_name == "RunCommand" the same way Bash is matched for Claude.
  3. Read tool_input.command, run the existing rewrite engine, emit updatedInput.command with the rewritten command (preserve the other tool_input fields — blocking, command_type, requires_approval — unchanged).
  4. Add rtk init -g --agent trae that patches ~/.trae-cn/hooks.json with a PreToolUse / RunCommand hook entry (mirror the existing rtk init -g patcher for Claude).
  5. Add rtk hook trae subcommand (can initially delegate to the same handler as rtk hook claude but with RunCommand as the accepted tool name).

Why This Fits RTK

  • Same protocol: Trae speaks the Claude-Code-compatible stdin/stdout JSON contract. The rewrite engine is reusable as-is.
  • Single-line change in spirit: the only behavioral delta is the accepted tool_name.
  • High-value user base: Trae is ByteDance's flagship agentic IDE with a large Chinese-market footprint; users currently have zero RTK integration path.
  • Follows existing pattern: mirrors exactly how Cursor/Copilot/Droid variants were added.

Verification Plan (for the PR)

I'm happy to test a build on Windows + Trae against:

  • git status / git log / git diff → expect compact RTK output
  • pytest → expect failures-only output
  • ls / find → expect compact listings
  • Exit-code 0 / 2 path both respected by Trae

Environment

  • RTK: latest develop (tested rtk hook claude and rtk hook cursor)
  • OS: Windows 11
  • Trae IDE: built-in hook system at ~/.trae-cn/hooks.json (verified working with a PostToolUse + RunCommand Python hook locally)
  • Reference for Trae's hook protocol: Volcengine enterprise hook docs (enterprise variant uses type: http; the local type: command variant used here follows the Claude-Code-compatible shape)

Activity

  1. added
    enhancement
    help wanted
    on Jul 27, 2026
  2. pszymkowiak commented on Jul 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 90%

    Summary

    Add Trae IDE hook support (RunCommand tool_name, ~/.trae-cn/hooks.json) mirroring existing Claude/Cursor/Copilot/Droid hook integrations.

    📁 Relevant files
    • src/hooks/mod.rs
    • src/hooks/claude.rs
    • src/hooks/cursor.rs
    • src/init.rs

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

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:cliarea:configenhancementhelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions