rtk-ai/rtk · error

Trae hooks.json version must be 1

Error message

Trae hooks.json version must be 1

What it means

rtk validates an existing Trae `hooks.json` before merging its hook entries. The schema requires the top-level `version` field to be exactly the JSON number 1. If `version` is present with any other value (or type), rtk bails because it only knows how to safely merge into version-1 Trae hook configs.

Solutions

  1. Edit hooks.json and set `"version": 1` (number, not string).
  2. If the file was written by a newer Trae version, update rtk or migrate the hooks manually into a version-1 file.
  3. Back up and reset hooks.json to a minimal `{"version":1,"hooks":{}}` and rerun `rtk init`.

Example fix

// before (.trae/hooks.json)
{ "version": 2, "hooks": {} }
// after
{ "version": 1, "hooks": {} }
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
function traeready(p = '.trae/hooks.json') {
  if (!fs.existsSync(p)) return true;
  const j = JSON.parse(fs.readFileSync(p, 'utf8'));
  return j.version === undefined || j.version === 1; // must be number 1
}

Type guard

const isV1 = (j) => typeof j === 'object' && j !== null && (j.version === undefined || j.version === 1);

Try / catch

match rtk init result { Err if msg contains 'version must be 1' => fix version field and retry }

Prevention

When it happens

Trigger: Running `rtk init` for Trae where `.trae/hooks.json` (or `.trae-cn/hooks.json`) exists and its parsed JSON root has a `version` field not equal to `serde_json::json!(1)` — e.g. 2, "1" as a string, or null.

Common situations: Hand-edited hooks.json with a bumped version; a different tool wrote a newer schema version; version stored as a string instead of a number.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/a88c16cd6cd60026. Report an issue: GitHub.

Appendix: source

Thrown at src/hooks/init.rs:5096

    }
}

fn read_trae_hooks_json(path: &Path) -> Result<(serde_json::Value, bool)> {
    match read_json_file(path)? {
        Some(root) => Ok((root, true)),
        None => Ok((serde_json::json!({ "version": 1 }), false)),
    }
}

fn validate_trae_hooks_json(root: &serde_json::Value) -> Result<()> {
    let root_object = root
        .as_object()
        .context("Trae hooks.json root must be an object")?;
    if root_object
        .get("version")
        .is_some_and(|version| version != &serde_json::json!(1))
    {
        anyhow::bail!("Trae hooks.json version must be 1");
    }
    if root_object
        .get("hooks")
        .is_some_and(|hooks| !hooks.is_object())
    {
        anyhow::bail!("Trae hooks value is not an object");
    }
    if root_object
        .get("hooks")
        .and_then(|hooks| hooks.get(PRE_TOOL_USE_KEY))
        .is_some_and(|pre_tool_use| !pre_tool_use.is_array())
    {
        anyhow::bail!("Trae PreToolUse value is not an array");
    }
    Ok(())
}

/// Install RTK's Trae hook in every supplied target. All targets are read and

View on GitHub (pinned to 0924356b4c)