Hmbown/CodeWhale · error

refusing to mutate non-owned root

Error message

refusing to mutate non-owned root {}

What it means

`target_scope_for_root` refuses to mutate any skill root that is not a writable, Codewhale-owned root: the descriptor must pass `is_writable_owned()` AND its kind must be `CodeWhaleProject` or `CodeWhaleGlobal`. This protects third-party/user-managed roots (e.g. a project's checked-in `.claude/skills` or any external directory) from being written by Codewhale's skill mutation operations.

Solutions

  1. Target the Codewhale-owned root instead: use `SkillTargetScope::Project` (workspace `.codewhale/skills`) or `SkillTargetScope::Global` (home `.codewhale/skills`) with `prepare_owned_target`/`install_remote`
  2. If the descriptor comes from config, update its `kind` to `CodeWhaleProject`/`CodeWhaleGlobal` only if the path really is the owned root; otherwise leave it read-only and copy skills in manually
  3. Verify with `root.is_writable_owned()` before calling mutation APIs; route non-owned roots to read-only listing paths
  4. If you intended to mutate a foreign root, that is intentionally unsupported — sync the files yourself or add an explicit integration, not a bypass of this guard

Example fix

// before: mutating a foreign (user-managed) root descriptor
let scope = target_scope_for_root(&user_root)?; // bails: non-owned root
// after: install into the owned project root instead
let skills_dir = prepare_owned_target(workspace, None, SkillTargetScope::Project)?;
Defensive patterns

Strategy: type-guard

Validate before calling

if !root.is_writable_owned() {
    return Err(format!("{} is not a Codewhale-owned root; pick .codewhale/skills instead", root.path.display()));
}
if !matches!(root.kind, SkillRootKind::CodeWhaleProject | SkillRootKind::CodeWhaleGlobal) {
    return Err(format!("{} has foreign kind {:?}; mutation refused", root.path.display(), root.kind));
}

Type guard

fn is_mutable_owned_root(root: &SkillRootDescriptor) -> bool {
    root.is_writable_owned()
        && matches!(root.kind, SkillRootKind::CodeWhaleProject | SkillRootKind::CodeWhaleGlobal)
}

Try / catch

match install_remote(workspace, home, scope) {
    Err(e) if e.to_string().contains("refusing to mutate non-owned root") => {
        eprintln!("{} — target the owned .codewhale/skills root instead", e);
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling `validate_owned_root_descriptor` with a `SkillRootDescriptor` whose kind is a foreign root (not `CodeWhaleProject`/`CodeWhaleGlobal`) or that is not marked writable-owned; passing a user- or project-managed root discovered by a scan into an install/import operation that expects an owned root; constructing a descriptor manually with the wrong `kind` or writability flag.

Common situations: Pointing a skill install at a shared team skills directory checked into the repo instead of `.codewhale/skills`; a root descriptor loaded from config that was created before Codewhale-owned roots existed and carries a legacy kind; tests or scripts building `SkillRootDescriptor` values by hand with mismatched kind/writability.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/806dedc97c957634. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/skills/mutation.rs:264

    if !checked_real_directory(anchor)? {
        bail!("owned skill anchor {} does not exist", anchor.display());
    }

    let codewhale_dir = anchor.join(".codewhale");
    if !checked_real_directory(&codewhale_dir)? {
        create_owned_directory(&codewhale_dir)?;
    }
    validate_owned_target_chain(anchor, &skills_dir, false)?;
    if !checked_real_directory(&skills_dir)? {
        create_owned_directory(&skills_dir)?;
    }
    validate_owned_target_chain(anchor, &skills_dir, true)?;
    Ok(skills_dir)
}

fn target_scope_for_root(root: &SkillRootDescriptor) -> Result<SkillTargetScope> {
    if !root.is_writable_owned() {
        bail!("refusing to mutate non-owned root {}", root.path.display());
    }
    match root.kind {
        SkillRootKind::CodeWhaleProject => Ok(SkillTargetScope::Project),
        SkillRootKind::CodeWhaleGlobal => Ok(SkillTargetScope::Global),
        _ => bail!("refusing to mutate non-owned root {}", root.path.display()),
    }
}

fn validate_owned_root_descriptor(
    ctx: &MutationContext<'_>,
    root: &SkillRootDescriptor,
) -> Result<PathBuf> {
    let target = target_scope_for_root(root)?;
    let expected = resolve_owned_target(ctx.workspace, ctx.home, target)?;
    if root.path != expected {
        bail!(
            "audited owned root {} does not match mutation target {}",
            root.path.display(),

View on GitHub (pinned to 73e0f67d83)