-
-
Notifications
You must be signed in to change notification settings - Fork 0
Assistant Integration
codegraph install wires the CodeGraph skill into a host AI assistant so it
queries the graph before falling back to broad file exploration. It writes a
per-platform skill file (where the platform has one), injects an always-on
instructions section into the platform's instructions file, and (for Claude
Code) registers PreToolUse hooks in .claude/settings.json. For Codex it
also registers a native MCP server and a SessionStart hook, with a --global
mode for the Codex desktop app (see Codex). All writes are idempotent
and target the current working directory.
The companion codegraph uninstall reverses it, and codegraph skill check/bless guard the generated artifacts against drift (a dev/CI tool).
codegraph install [platform] [--global]
platform defaults to claude. Files are written under the current directory
(the repo root). The command prints each path it wrote. --global applies only
to codex and targets the global ~/.codex/config.toml instead of the project
(see Codex).
codegraph install
codegraph install agents
codegraph install copilot
codegraph install codex # Codex CLI (project .codex/)
codegraph install codex --global # Codex desktop app (global ~/.codex)
| Argument(s) | Skill file | Always-on instructions file | Extra wiring |
|---|---|---|---|
claude |
.claude/skills/codegraph/SKILL.md |
CLAUDE.md |
PreToolUse hooks in .claude/settings.json
|
codex |
none | AGENTS.md |
MCP server + SessionStart hook in .codex/ (project), or global MCP with --global
|
agents, agent, opencode
|
none | AGENTS.md |
none |
gemini |
none | GEMINI.md |
none |
cursor |
none | .cursorrules |
none |
copilot, github-copilot
|
none | .github/copilot-instructions.md |
none |
kilo, kilocode
|
none | .kilocode/rules/codegraph.md |
none |
Platform names are case-insensitive. codex is its own platform (it reads
AGENTS.md but also gets native MCP/hook wiring, see Codex); opencode
maps onto the plain agents platform. Only Claude gets a dedicated SKILL.md;
the other platforms consume the always-on instructions file directly. Any needed
parent directories (for example .github/, .kilocode/rules/) are created.
-
Skill file (Claude only):
.claude/skills/codegraph/SKILL.md. It carries frontmatter (name: codegraph) and instructs the assistant to query the graph before grepping or broad reading, listing the build/query CLI commands and the MCP tools (see MCP-Server). -
Always-on section: a marked block injected into the platform's instructions file:
<!-- codegraph:start --> ## CodeGraph This repo has a CodeGraph knowledge graph (`codegraph-out/graph.json`). Query it before broad file exploration: `codegraph query "<question>"`, `codegraph affected <node>`, or run `codegraph serve` for the MCP tools. Rebuild with `codegraph extract .` / `codegraph update <files>`. <!-- codegraph:end -->The block is delimited by
<!-- codegraph:start -->and<!-- codegraph:end -->. On reinstall it is replaced in place (never duplicated), and any prose around it is preserved. A new instructions file is created if none exists. -
PreToolUse hooks (Claude only): two entries merged into
.claude/settings.jsonunderhooks.PreToolUse(see below). -
MCP server + hook (Codex only): an MCP server registration and a
SessionStarthook, in the project.codex/or the global~/.codex/(see Codex).
Install can be run repeatedly without piling up duplicates:
- The always-on block is matched by its marker and replaced in place. A truncated or hand-edited block (a dangling start marker) is repaired into a single clean block.
- The settings hooks are matched by matcher plus the literal
codegraphin the body; any prior CodeGraph hooks are removed before the current pair is appended, so a reinstall keeps exactly two. Foreign hooks and unrelated top-level settings keys are preserved. A corruptsettings.jsonis treated as empty and rewritten.
Codex is wired differently from Claude, and the CLI and desktop app read configuration from different places, so there are two modes.
Writes, under the current repo:
-
.codex/config.toml-- a[mcp_servers.codegraph]entry that launchescodegraph serve(stdio MCP). No--graph, so it resolvescodegraph-out/graph.jsonrelative to the server's working directory. -
.codex/hooks.json+.codex/codegraph-hook.py-- aSessionStarthook that injects model-visible context (once per session, only when a graph exists) telling the agent to query the graph first. - The always-on
AGENTS.mdblock.
The Codex CLI loads a project's .codex/ layer only for trusted projects, so
trust the folder in Codex for the server and hook to take effect.
Why SessionStart and not PreToolUse (Claude's choice): Codex does not honor
additionalContext on PreToolUse (it marks the hook run failed), and its
top-level systemMessage is UI-only and never reaches the model. SessionStart
additionalContext is injected as model-visible developer context, so that is
where the nudge lives.
The desktop app ignores a project's .codex/config.toml for MCP and reads
servers only from the global ~/.codex/config.toml. For app users, --global
registers a per-repo server there instead:
-
~/.codex/config.tomlgains[mcp_servers.codegraph-<repo>](named after the repo dir, sanitized), launchingcodegraph serve --graph <absolute path>. The absolute--graphis required because the app gives a server no per-project working directory. Your other servers and the[projects.*]trust list are preserved. - The always-on
AGENTS.mdblock (the app reads projectAGENTS.md). - No hook is written (the app would not fire it); orientation rides on
AGENTS.md.
After installing: build the graph with codegraph extract ., restart the Codex
app, and check Settings > MCP servers for the codegraph-<repo> entry.
Install for each repo you use; each appears as its own server. The Codex home
directory honors CODEX_HOME (otherwise ~/.codex). codegraph must be on your
PATH (e.g. cargo install --path bin/codegraph) so the app can launch it.
For Claude, two PreToolUse hooks are written into .claude/settings.json. They
nudge, never block (they fail open, so a legitimate tool call always
proceeds), and they only fire when codegraph-out/graph.json exists. Each hook's
shell snippet parses the tool input with python3.
-
Bash matcher: fires when a shell command looks like a search
(
grep,rg,ripgrep,find,fd,ack,ag). It injects additional context telling the assistant to runcodegraph query "<question>"before grepping raw files. -
Read|Glob matcher: fires when a
Read/Globtargets a source or doc file (by extension, for example.py .js .ts .go .rs .java .mdand many others) outsidecodegraph-out/. It injects context telling the assistant to runcodegraph query/codegraph explain/codegraph pathfirst, and to carry the same rule into subagent prompts.
When a hook fires, Claude Code receives the additionalContext text as a
PreToolUse hook output, steering the assistant toward the graph before it reads
or greps. Because the hook is gated on codegraph-out/graph.json, nothing fires
until a graph has been built (see Quickstart and
Extraction).
codegraph uninstall [platform]
codegraph uninstall codex --global
codegraph uninstall --all
platform defaults to claude. Uninstall removes the dedicated skill file (if
any), tidies now-empty skill directories, and strips the always-on marker block
from the instructions file. If nothing else remains in that file, the file is
removed; otherwise the surrounding prose and its blank-line spacing are
preserved. For Claude it also removes exactly the CodeGraph PreToolUse hooks,
leaving foreign hooks intact. For Codex it removes the project .codex/ server,
hook, and script (or, with --global, this repo's codegraph-<repo> entry from
~/.codex/config.toml), preserving foreign servers. --all uninstalls from
every supported platform (project scope).
The skill artifacts are generated by pure slot substitution over an embedded
template, with a committed golden snapshot tree (expected/) next to the
skillgen crate source. These commands are dev/CI tools run from a repo checkout:
codegraph skill check
codegraph skill bless
-
codegraph skill checkre-renders every artifact (one per platform plus the shared always-on section) and byte-diffs it against the committed snapshots (ignoring line-ending style). It printsskill artifacts are in sync with expected/.when clean, or lists each drift and exits non-zero. Acargo testrun also fails on drift. -
codegraph skill blessrewrites the committed snapshot tree from the current render, printing the paths written. Run it after an intentional template change.
Note: because the snapshot tree is resolved relative to the crate source, these commands are meaningful only from a repo checkout; an installed binary reports the snapshots missing by design.
-
MCP-Server -- run
codegraph serveand the tools the skill points an assistant at. - Quickstart -- build a graph first so the hooks activate.
- Configuration -- environment variables and settings.
- Commands -- the full CLI reference.
Getting started
Concepts
Using CodeGraph
Integrations
Scaling
Reference