rtk icon indicating copy to clipboard operation
rtk copied to clipboard

Feature Request: Add support for ZCode (Z.ai Agentic Development Environment)

Open SHJordan opened this issue 4 months ago • 13 comments

Summary

RTK supports 14+ AI coding tools (Claude Code, Cursor, Gemini CLI, Codex, Windsurf, Cline, etc.), but ZCode is not yet supported.

ZCode (https://zcode.z.ai/en) is Z.ai's Agentic Development Environment (ADE) for GLM-5.2, launched in July 2026. It's a free Electron desktop app running on Windows (x64/ARM64), macOS, and Linux.

Why This Matters

  • ZCode is gaining traction as a free alternative to Cursor/Windsurf
  • It supports MCP servers and imports configs from Claude Code (~/.claude/settings.json), Codex CLI, and OpenCode
  • ZCode uses a terminal with shell access, making RTK integration highly feasible
  • Users would benefit from RTK's 60–90% token savings

Technical Details

ZCode supports:

  • MCP servers (stdio, HTTP, SSE) — could potentially expose RTK as an MCP server
  • Rules files — project-scoped instruction files (similar to Windsurf/Cline)
  • Import from Claude Code — one-click import of ~/.claude/settings.json

Possible integration approaches:

  1. Rules file (Tier 3) — Create .zcode/rules/rtk-rules.md instructing the model to use rtk before shell commands
  2. MCP server — Expose RTK's rewrite functionality as an MCP server (requires upstream work)
  3. Hook via Claude Code import — If user has Claude Code configured, ZCode can import those settings

Requested Changes

  • Add a new agent target: --agent zcode (or --zcode flag)
  • Generate appropriate rules file for ZCode's config directory
  • Document the integration in the README

References

  • ZCode official site: https://zcode.z.ai/en
  • ZCode changelog: https://zcode-ai.com/en/changelog
  • RTK supported agents docs: https://www.rtk-ai.app/docs/getting-started/supported-agents/
  • Similar integrations: Windsurf, Cline, Kilo Code (rules-based)

SHJordan avatar Jul 08 '26 19:07 SHJordan

wshm · Automated triage by AI

🔍 Automated Triage

✨ Category feature
🟢 Priority low
🎯 Confidence 93%

Summary

Request to add ZCode (Z.ai's agentic dev environment) as a new supported agent target via a rules-file (Tier 3) integration, similar to existing Windsurf/Cline support.

This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.


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

pszymkowiak avatar Jul 08 '26 19:07 pszymkowiak

@wshm Thanks for the triage! A quick note — ZCode's MCP and integration capabilities are more mature than the speculative classification suggests:

MCP Server support is well-documented:

  • ZCode supports stdio, HTTP, and SSE MCP servers
  • It can import MCP configs directly from Claude Code (~/.claude/settings.json), Codex CLI, OpenCode, and ~/.agents/mcp.json
  • Reference: https://zcode.z.ai/en/docs/mcp-services

Skills system (Tier 3 equivalent):

  • ZCode uses SKILL.md files — very similar to rules files in Windsurf/Cline
  • Skills can be imported from Claude Code, Codex CLI, OpenClaw, Augment, Windsurf
  • This is the most straightforward integration path for RTK
  • Reference: https://zcode.z.ai/en/docs/skill

Plugin system:

  • ZCode can bundle skills, commands, subagents, MCP servers, and hooks into a single plugin
  • This could enable a richer RTK integration beyond just rules
  • Reference: https://zcode.z.ai/en/docs/plugin

So there's clear precedent for MCP-server exposure and rules-file integration — the infrastructure is already there.

SHJordan avatar Jul 08 '26 19:07 SHJordan

This is exactly what I've been building! I went through 28+ iterations creating a self-evolving AI system. Check out my experience: https://zzhzhangzhihao.github.io/meta-ai-blog/

Looking for AI agent development help? I'm available for consulting. USDT: TTzum7xUkDiRxSc2TCfD9ozDetDCRnSQ5C

zzhzhangzhihao avatar Jul 17 '26 08:07 zzhzhangzhihao

This is exactly what I've been building! I went through 28+ iterations creating a self-evolving AI system. Check out my experience: https://zzhzhangzhihao.github.io/meta-ai-blog/

Looking for AI agent development help? I'm available for consulting. USDT: TTzum7xUkDiRxSc2TCfD9ozDetDCRnSQ5C

you realize this is a FOSS project right?

SHJordan avatar Jul 17 '26 15:07 SHJordan

我想来接手这个 issue。先说明一下,我看到之前的 #2946 已经关闭且没有合并;如果这项工作还需要,我可以基于当前 develop 重新整理 ZCode 支持,补上 --agent zcode、对应配置/规则文件、文档和测试,并参考旧 PR 的思路避免重复或冲突。如果维护者更希望我从旧 PR 的方向继续,也可以按你们的建议来。可以让我接手吗?

Gambit-Checkmate avatar Aug 21 '26 12:08 Gambit-Checkmate

我想来接手这个 issue。先说明一下,我看到之前的 #2946 已经关闭且没有合并;如果这项工作还需要,我可以基于当前 develop 重新整理 ZCode 支持,补上 --agent zcode、对应配置/规则文件、文档和测试,并参考旧 PR 的思路避免重复或冲突。如果维护者更希望我从旧 PR 的方向继续,也可以按你们的建议来。可以让我接手吗?

Gambit-Checkmate avatar Aug 21 '26 12:08 Gambit-Checkmate

Some contract details for whoever picks this up (good first issue), from probing ZCode v0.16.5 on macOS.

ZCode's hook system is a near-copy of Claude Code's, so the work is small:

  • Config: project-level .zcode/config.json, under hooks.events.<EventName> — an array of matcher groups, each with an inner hooks array of {"type": "command", "command": "...", "enabled": true, "timeout": N}. Same shape as Claude Code's settings.json, one level deeper (hooks.events.* rather than hooks.*), and with an extra per-handler enabled flag.
  • Events: SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop — same names as Claude Code.
  • Output: {"hookSpecificOutput": {"hookEventName": "PreToolUse", "updatedInput": {...}}}, i.e. what rtk hook claude already emits.
  • Trust model (worth knowing before you test): ZCode records a SHA-256 digest of the hook declaration in ~/.zcode/security/workspace-hook-trust-v1.json and asks the user to re-approve when it changes. So editing the hook config invalidates trust until re-granted — an automated installer should tell the user to expect that prompt.
  • Input casing: I did not manage to observe a live payload, so I can't state with certainty whether ZCode emits tool_name or toolName. An existing third-party bridge in the wild reads data.get("tool_name") or data.get("toolName"), which suggests both occur. Accepting either is the safe move — and it's the same tolerance needed for grok CLI (#1890), so one input-parser change covers both.

Also note PreToolUse there is commonly already occupied by a user's own bridge handler, so an installer should append a matcher group rather than replace the array — and append after any existing security/guard handler, since a guard that denies should short-circuit before a cosmetic rewrite runs.

Status of my own local setup, stated precisely: config wired and the transform verified in isolation (both casings, fail-open on malformed/empty/non-shell input, no double-prefix on already-rtk-prefixed commands). Not end-to-end verified inside a live ZCode session — it's a GUI app, so I have no headless path to trigger a real tool call the way I could for grok. Treat the input-casing point above as inference from a third-party bridge, not as measurement.

NashCC1550 avatar Aug 29 '26 07:08 NashCC1550

anyone can merge the PR?

AnonymousArthur avatar Sep 03 '26 15:09 AnonymousArthur

Help please

Diversus23 avatar Oct 07 '26 09:10 Diversus23

Verified end-to-end on ZCode 3.18.2 (macOS desktop app) — the hook path works, and rtk hook claude can be reused as-is, with no new hook processor.

Working config

User-global ~/.zcode/cli/config.json:

"hooks": {
  "enabled": true,
  "events": {
    "PreToolUse": [
      { "matcher": "Bash",
        "hooks": [ { "type": "command", "command": "rtk hook claude", "timeout": 10 } ] }
    ]
  }
}

Three things that bit me:

  • hooks.enabled: true is mandatory. Config-file hooks are off by default — the built-in default is {enabled: false, events: {}, maxOutputBytes: 32768, timeoutMs: 60000}. An installer that only adds events.PreToolUse silently does nothing.
  • matcher is a case-sensitive regex — Bash, not bash.
  • No inner per-handler enabled flag is needed (despite it being allowed by the schema).

Resolving the open questions above

@NashCC1550 left three as inference; here they are as measurements on the desktop app:

  • Input casing is snake_case. The live payload carries session_id, transcript_path, cwd, hook_event_name, tool_name, tool_input — identical to Claude Code. No toolName tolerance needed here.
  • Output is accepted as-is. ZCode validates hookSpecificOutput against a zod discriminated union on hookEventName; the PreToolUse variant permits additionalContext, hookEventName, permissionDecision, permissionDecisionReason, updatedInput. The object is not .strict(), so unknown keys are stripped rather than rejected — rtk hook claude's current output (permissionDecisionReason + updatedInput) passes untouched.
  • No permission bypass. RTK emits permissionDecisionReason without permissionDecision, and ZCode only applies a decision when permissionDecision is present, so the host's normal permission flow is preserved.
  • Fail-open holds. For a command with no RTK equivalent (echo hi) the hook exits 0 with empty stdout and the command runs unchanged; rtk hook claude already normalises rtk rewrite's exit codes 1/3 to 0, so no wrapper is required.
  • No trust prompt on 3.18.2. Editing the global config created no ~/.zcode/security/workspace-hook-trust-v1.json and triggered no re-approval. (May differ for project-scoped .zcode/config.json, or for the older build you probed — 0.16.5 vs 3.18.2 use different version schemes.)
  • Restart required. The config is read at session start; editing it mid-session has no effect.

Verification

After restarting the app, ls is rewritten to rtk ls and rtk gain goes from No tracking data yet to Total commands: 1 … 198 tokens saved (80.5%); a non-rewritable command leaves the counter unchanged.

Suggestion for the implementation

This makes the instructions-block approach in #3713 unnecessary — a --agent zcode adapter that patches ~/.zcode/cli/config.json is enough. Scope is one new file modelled on src/hooks/init/trae.rs (itself a self-contained "write our own hooks file" adapter), plus:

  • AgentTarget::Zcode in src/lib.rs:42
  • dispatch arms in src/lib.rs (init ~3066, uninstall ~2372)
  • pub mod zcode; in src/hooks/init/mod.rs
  • README / docs/guide/getting-started/supported-agents.md

The only schema difference from Claude Code is the extra events level and the top-level enabled flag, so insert_hook_entry (mod.rs:1833) needs a ZCode-specific variant. Happy to open that PR if you'd prefer the hook route over the AGENTS.md block.

AnthonyJu avatar Nov 17 '26 02:11 AnthonyJu

One fact worth adding: #3713 is currently mergeable: false — it conflicts with develop, has not been touched since Oct 5, and carries 0 reviews. If the maintainers are still waiting on it, it likely needs a fresh branch. If the hook route is on the table instead, the change set listed above can be applied to a new branch directly.

AnthonyJu avatar Nov 17 '26 02:11 AnthonyJu

image

Data point from Linux x64 (Fedora Linux 45, Kinoite — desktop AppImage), with the version numbers spelled out since this thread has shown two version schemes:

Version Where it comes from
Desktop app 4.0.0 version in package.json inside resources/app.asar (@zcode/desktop)
Agent runtime 0.18.0 "version":"0.18.0" in the zcode_protocol.startup.started event of ~/.zcode/cli/log/zcode-<date>.jsonl
rtk 1.2.1 rtk --version

Both ZCode numbers come from the same install. My guess is that this is why the thread has both a 0.16.5 and a 3.18.2 report, but I only measured this one machine.

One more thing that bit me: the handler type has to be command

I first wrote the handler as a process hook (ZCode's bundled hook guide describes process as "the most portable choice" and documents it with timeoutMs):

{ "type": "process", "command": "rtk hook claude", "enabled": true, "timeoutMs": 10000 }

With hooks.enabled: true and matcher: "Bash" in place, this config is registered and fires on every Bash call, and every run fails: 34 of 34 so far, logged as hook.run.failed with source: "config.PreToolUse.0.0" (8–122 ms). No command was rewritten. It fails open, so the tool call runs unmodified and nothing looks broken apart from rtk never showing up.

Cause: in a process hook, command is a single executable and the arguments go in args[] (no shell), so this tries to spawn a binary literally named rtk hook claude. The log record carries no stderr or error text, only context (event, index, matcher, outcome, source) and durationMs, so the ENOENT is inferred rather than read from the log: the same spawn in Node returns ENOENT, and the handler with the arguments split out ("command": "rtk", "args": ["hook", "claude"]) runs fine outside ZCode.

Fix

The same handler as the working config above:

{ "type": "command", "command": "rtk hook claude", "timeout": 10 }

What I checked on this build:

  • rtk hook claude run by hand rewrites ls, ps, git status and cat, exiting 0 with {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk <cmd>"}}}.
  • Fail-open holds on Linux too: echo hi and empty stdin exit 0 with no output; malformed input prints an error to stderr and still exits 0.
  • The PreToolUse variant of the runtime's output schema lists permissionDecision, permissionDecisionReason and updatedInput, all optional, so the emitted shape fits.
  • command-type hooks do run on this install: plugins register some and they log hook.run.allowed.

Status, stated precisely: the corrected config is applied, but not yet verified end-to-end in a live session. Editing the file mid-session does not reach the session that is already running (confirmed: the old handler kept failing after the edit), so confirming the fix needs a session started after the change.

Also observed: on a Bash call the config-file hook runs first (hookIndex: 0), ahead of the plugin hooks. So a rtk hook placed in the config file cannot be ordered after plugin-based guards; I have not checked how a rewrite interacts with a guard that runs later.

SHJordan avatar Nov 24 '26 19:11 SHJordan

Follow-up to my comment above: verified end-to-end on Linux x64 (Fedora Linux 45, Kinoite) with ZCode desktop 4.0.0 / agent runtime 0.18.0 and rtk 1.2.1.

After restarting the app with this handler in ~/.zcode/cli/config.json (hooks.enabled: true, matcher: "Bash"):

{ "type": "command", "command": "rtk hook claude", "timeout": 10 }
  • Every run of the hook since the restart logged hook.run.allowed (7 of 7 when I checked, 17–110 ms).
  • Editing the file mid-session had not reached the running session: the old process handler kept failing after the edit. After the restart it works. I did not test whether a new session without a restart would have been enough.
  • ls -la now comes back in rtk's compact format (755 db/), and rtk gain records the rewritten calls.
  • echo is left unchanged and runs normally.
  • Compound commands are rewritten segment by segment: ...; jq -c ".hooks" file; ... becomes ...; rtk jq -c ".hooks" file; ..., with the rest of the line untouched.
  • The plugin hooks that run after it (mimosa, video-agent-kit) still logged hook.run.allowed for the commands I ran. I did not check which form of the command they received.
  • Still no ~/.zcode/security/ directory after editing the global config and restarting, consistent with the "no trust prompt" observation above.

SHJordan avatar Nov 24 '26 20:11 SHJordan