codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

First-class install target + prompt-hook for ZCode (Z.ai)

Open dogking95 opened this issue 3 months ago • 2 comments

Request

Add ZCode (Z.ai's coding agent harness, https://zcode.z.ai) as a first-class --target for codegraph install, so codegraph install --target=zcode writes the MCP config automatically.

Related: tracking issue #649 (zcode is already listed there from #962). Opening a dedicated issue to attach the concrete config format and hook details so the target is easier to land.

Why

ZCode is a first-class MCP + hooks-capable agent. Today, ZCode users have to hand-edit the MCP config. CodeGraph works great once configured manually — the ask is just the one-command install target like the other agents have.

What ZCode needs

1. MCP server config (install target)

ZCode reads MCP servers from ~/.zcode/cli/config.json (user scope) or <workspace>/.zcode/config.json (workspace scope), under mcp.servers:

{
  "mcp": {
    "servers": {
      "codegraph": {
        "type": "stdio",
        "command": "codegraph",
        "args": ["serve", "--mcp"],
        "enabled": true,
        "timeoutMs": 60000
      }
    }
  }
}

That's it for MCP — same codegraph serve --mcp as everywhere else. A new file in src/installer/targets/ plus a registry entry, as you noted in #649.

2. (Bonus) UserPromptSubmit prompt-hook

ZCode also exposes a UserPromptSubmit hook that can inject context per turn. If CodeGraph shipped a prompt-hook for ZCode (analogous to what exists for Claude Code), it could inject relevant-symbols context on each prompt. This is optional — the MCP target alone is the main ask.

ZCode hooks docs: https://zcode.z.ai/cn/docs/hooks ZCode plugin/MCP docs: https://zcode.z.ai/cn/docs/plugin

Config location summary

Scope Path
User ~/.zcode/cli/config.json
Workspace <workspace>/.zcode/config.json

Happy to test a PR on Windows if that helps.

dogking95 avatar Aug 10 '26 03:08 dogking95

Another ZCode user confirming demand — this target would be very welcome.

Verified today on Windows that CodeGraph v1.6.0 works with ZCode via the manual MCP config (stdio initialize handshake OK, no compatibility issues on the ZCode side). Other ZCode users can wire it up themselves right now: add CodeGraph as a stdio MCP server running codegraph serve --mcp in ZCode's MCP config (user scope ~/.zcode/cli/config.json or workspace .zcode/config.json) and restart the session.

A few notes that may help when implementing the target:

  • ZCode's MCP config schema is strict — unknown keys silently drop the server entry; stdio env vars go under env (not environment).
  • Both config scopes auto-connect at session start; bumping the per-server timeout helps on cold starts.
  • On Windows the installer would need to resolve the .cmd launcher; an absolute path works fine.

Happy to test a pre-release build.

liurambler avatar Sep 05 '26 11:09 liurambler

Recommend zcode-codegraph-kit if you use codegraph with Zcode — it keeps your agent on codegraph_explore instead of grep, so exploration is faster and uses fewer tokens. Index auto-syncs after every edit.

npx zcode-codegraph-kit

simpleKalvin avatar Sep 07 '26 03:09 simpleKalvin