Graphify — Knowledge-Graph Navigation
graphify alongside a multi-service architecture saves a meaningful amount of tokens compared to relying solely on CLAUDE.md files. The two tools serve different roles in context management, and combining them is more efficient than either alone on a large, multi-service repo.
How They Compare for Token Efficiency
| Feature | CLAUDE.md Files | Graphify (/graphify) |
|---|---|---|
| Primary Function | System instructions, coding standards, high-level architectural rules. | Structural knowledge graph mapping codebase relationships and dependencies. |
| Context Loading Strategy | Eager / always loaded — read into context on session start or when opening directories. | Lazy / query-based — retrieves only the subgraph or dependency path needed for the current prompt. |
| Token Cost Profile | Fixed baseline overhead on every turn. | One-time indexing cost, then far less context per navigation query — see Measured Token Savings below. |
Why CLAUDE.md Alone Bloats Context on 24+ Microservices
- Context accumulation — with 24+ microservices and extensive
CLAUDE.mdfiles across them, the assistant spends hundreds or thousands of tokens just holding instructions and directory layouts before a question is even asked. - Sequential file scanning — tracing a bug or a request across services without a graph relies on
grepor opening multiple files one at a time, which burns tokens scanning lines that turn out to be irrelevant.
How Graphify Complements CLAUDE.md
- Precision retrieval via subgraphs —
graphifyparses the codebase into local graph nodes. When Claude needs to see how Service A talks to Service B, it runs a scoped graph query (graphify query "...") and loads only the relevant structural nodes instead of reading raw source files line by line. - Slimmer CLAUDE.md files — keep each service’s
CLAUDE.mdto high-level conventions, build commands, and rules only. Letgraphifyhandle the deep file dependencies and service interconnections.
Recommended Setup for 24+ Microservices
- Slim down
CLAUDE.md— roughly 100–200 lines per service (build/test commands, formatting preferences, key architectural constraints). Avoid full file trees or extensive code maps inline. - Run
graphify— index the repositories into a persistent local knowledge graph (graph.html, graph metadata), and let Claude query it when tracing cross-service logic.
macOS Setup for Claude Code
Applies to macOS 12+ on Apple Silicon and Intel.
Prerequisites
Install uv (a standalone installer), then reload the shell:
curl -LsSf https://astral.sh/uv/install.sh | sh
source ~/.zshrc
uv --version
Step 1: Install Graphify
uv tool install graphifyy
Note: the PyPI package name is
graphifyy(two y’s), but the CLI command it installs isgraphify.
Make sure graphify is on PATH — on a fresh zsh terminal, ~/.local/bin may not be yet:
uv tool update-shell
Then close and reopen the terminal (or source ~/.zshrc).
Step 2: Register the Graphify Skill for Claude Code
graphify install --platform claude
(Optional) strict mode forces Claude Code to consult the structural graph before falling back to raw grep/file reads:
graphify install --platform claude --strict
Step 3: Configure .graphifyignore and .gitignore
Create a single .graphifyignore at the monorepo root. It covers both index noise and secrets — see Security Considerations below for why each secret pattern is there.
# --- Build output / dependencies (index noise) ---
node_modules/
dist/
build/
target/
.venv/
*.min.js
*.map
pnpm-lock.yaml
yarn.lock
package-lock.json
*.log
graphify-out/
# --- Environment and secret files ---
.env
.env.*
!.env.example
*.env
*.pem
*.key
*.p12
*.pfx
*.crt
*.jks
*.keystore
# --- Credentials and cloud configs ---
credentials.json
*service-account*.json
*firebase-adminsdk*.json
auth_key.json
google-services.json
GoogleService-Info.plist
secrets.yaml
secrets.json
config/secrets/
.npmrc
*.tfstate
*.tfvars
# --- Cloud provider CLI folders ---
.aws/
.gcp/
.azure/
# --- Local data, API-client environments, and Claude config ---
datasets/
**/bruno/**/environments/
.claude/settings.local.json
Keep the generated graph out of Git:
echo "graphify-out/" >> .gitignore
Step 4: Index the Microservices and Install Git Hooks
- Generate the knowledge graph from the workspace root (or inside an individual service folder):
# Code only — free, runs locally, nothing leaves your machine (recommended start)
graphify . --code-only
Code is indexed locally from the AST. Docs and images need an LLM for semantic extraction, so plain graphify . in a terminal stops with no LLM API key found unless a key is set. Pick one:
| Option | Command | Cost / data sent | Use when |
|---|---|---|---|
| Code only (recommended) | graphify . --code-only |
Free, local, nothing leaves your machine | Mainly need the code graph |
| Inside Claude Code | /graphify . in a Claude session |
The session itself reads the docs — no key, but uses session tokens | Want docs in the graph without managing a key |
| API key in the terminal | export GEMINI_API_KEY=… then graphify . |
Billed to that provider; doc contents are sent to them | Re-indexing often outside Claude |
Export a key in the shell profile or the current terminal only — never in a repo .env. To keep business-requirement/architecture docs out of the graph entirely, add that docs folder to .graphifyignore.
- Install Git hooks so the graph updates automatically on checkout and commit:
graphify hook install
Step 5: Verify the Setup
Start Claude Code in the workspace root and ask about cross-service relationships, e.g.:
“Run a graph query to show how Service A routes requests to Service B.”
Claude Code runs graphify query against graphify-out/graph.json instead of reading raw source files, saving context tokens.
The graph can also be queried directly from the terminal:
graphify query "how does order-service call payment-service"
graphify path "OrderService" "PaymentOrderService" # shortest link between two nodes
graphify explain "PaymentOrderService" # a node and its neighbours
It’s working correctly if results point to real files and line numbers. “0 nodes found” for code known to exist means it wasn’t indexed.
Step 6: Make Graphify Always-On for the Project
By default Claude only uses graphify when /graphify <question> is typed. To make Claude consult the graph first on every codebase question, run once from the workspace root:
graphify claude install --project
Use --project for a repo whose config is committed. Without it, the hook commands embed the installing machine’s absolute path to graphify, which is wrong on every other machine. --project writes the bare graphify command instead, so each contributor needs graphify on PATH (Step 1).
It changes three things:
| File | Change |
|---|---|
CLAUDE.md |
Adds a ## graphify section telling Claude to check the graph before answering codebase questions and to rebuild it after code changes. |
.claude/settings.json |
Merges two PreToolUse hooks beside the existing protect-env.js guard: graphify hook-guard search on Bash|Grep, and graphify hook-guard read on Read|Glob (10s timeout each). A backup is saved as .claude/settings.json.graphify-bak. |
.claude/skills/graphify/, .claude/CLAUDE.md |
A project copy of the skill and its references. |
Why the project skill copy stays in the repo
--project copies the graphify skill into .claude/skills/graphify/ and registers it in .claude/CLAUDE.md. Keep both committed. A teammate who clones the repo gets the /graphify command and the same skill instructions without installing the skill globally, and everyone works from one pinned version of the instructions, even if their globally installed graphify versions differ. Without the copy, /graphify only exists for people who already ran graphify install --platform claude on their own machine.
What a teammate still has to do on their own machine after cloning:
- Install the CLI (Step 1). The committed hooks call the bare
graphifycommand, so it must be onPATH. - Build the graph once with
graphify . --code-only(Step 4).graphify-out/is gitignored, so nothing is shared. - Run
graphify hook installfor automatic rebuilds. Git never commits.git/hooks/, so each clone needs its own install.
When the graphify CLI is upgraded, re-run graphify claude install --project and commit the refreshed .claude/skills/graphify/ so the copy doesn’t drift from the CLI.
When graphify-out/graph.json exists, each hook injects a reminder before the tool call: run graphify query "<question>" first, and grep or read raw files only afterwards. If the file changed after the last build, the reminder says the graph may be stale and reading directly is fine.
A hook can only add a reminder or block a call. It cannot switch Claude from grep to the graph, so the CLAUDE.md section is what actually changes behaviour. The hooks add a small amount of text to every Bash, Grep, Read and Glob call, so on small lookups in a known file the reminder can cost more than it saves.
Optional flags:
--strict(needs--project) blocks the first raw file read of each session until onegraphify queryhas run.GRAPHIFY_HOOK_STRICT=0turns strict mode off at runtime without reinstalling.
After installing: delete .claude/settings.json.graphify-bak once the merged settings.json looks right, make sure graphify-out/ is in .gitignore, and start a new Claude Code session so the hooks load. To undo everything, run graphify claude uninstall.
The hooks do not update the graph. Run graphify hook install for an automatic rebuild of changed code files after each commit, and /graphify --update after documentation changes. A stale graph can give wrong answers.
Measured Token Savings
A local comparison on this repo: the size of graphify’s query answer against the files a grep-and-read search would load. The code-only graph had 12,940 nodes and 39,496 links. Tokens are estimated as characters ÷ 4.
| Question | Graphify answer | Grep-and-read (every matching file) | Ratio |
|---|---|---|---|
How does order-service call payment-service? |
~200 tokens | 19 files, ~16,000 tokens | ~75× |
| Where is the tenant code generated for orders? | ~1,600 tokens | 17 files, ~21,000 tokens | ~13× |
| How is the document audit event published? | ~1,600 tokens | 21 files, ~14,000 tokens | ~8× |
This is a best case for graphify. It measures only how much text each approach loads, not the total tokens a real session uses. Two things narrow the gap:
- Claude doesn’t read every grep hit. It opens the 3–6 files that look most relevant, so the realistic baseline is a few thousand tokens, not the full total above.
- Graphify only tells Claude where to look. Claude still opens a few files to answer properly, and a too-small answer can cost more tokens if it sends Claude the wrong way.
Expect the biggest saving on cross-service “how does X flow” questions, and little or none on “fix this bug in this file” tasks, where the file has to be read anyway.
Running a Real Comparison
- Pick several questions whose answers are already known, ideally ones that cross services.
- For each, open a fresh Claude Code session and ask it normally. Note the tokens used at the end.
- In another fresh session, ask
/graphify query "<same question>"and note the tokens the same way. - Compare both the tokens and whether the answer was right. Fewer tokens with a wrong answer is not a saving.
Use a fresh session each time so earlier answers don’t sit in context and skew the result.
Security Considerations
Graphify reads file contents to analyze code structure (ASTs, function calls, class definitions, imports). If a sensitive file sits inside the indexed directory and isn’t excluded, graphify reads it during the scan.
What Graphify Reads and Generates
- Source code and local files — graphify parses every file it isn’t told to ignore. If
.envfiles, keys, certificates, or secret config files are in the target directory, it reads their raw text. - Local output (
graphify-out/) — the graph is stored ingraphify-out/graph.json(plusgraph.html). If secrets end up in node properties or extracted text, they persist in these files.
How Secrets Could Leak
- Into the LLM context — if secrets are stored in
graph.json,graphify querycan return those nodes to Claude Code, which sends them to the model. - Into Git — if
graphify-out/isn’t in.gitignore, the generated graph (and any captured secrets) can be committed and pushed to the remote.
Recommended Security Setup
- Exclude secrets using the secret sections of the
.graphifyignorein Step 3 above. - Keep output out of Git by adding
graphify-out/to.gitignore(also in Step 3). - Verify nothing sensitive was indexed — see the checks below.
Additional Considerations
- Indexing may send content to the LLM, not only queries. Code files are parsed locally, but graphify’s extraction of non-code files (Markdown, PDFs, images) can run through Claude itself. Anything not ignored may reach the model at index time, before a single query runs. Check which mode the installed graphify version uses, and exclude non-code folders not meant to be sent (e.g. seed data containing realistic PII).
- Supply-chain risk.
graphifyyis a near-typo of the CLI name, the classic shape of a typosquat. Confirm the PyPI project links to the official upstream repository before installing, and pin a version (uv tool install graphifyy==<version>) instead of always pulling the latest. - Global Claude Code changes.
graphify install --platform claudewrites into the global Claude Code config (skill files, and in--strictmode a hook that runs on tool calls). Review what it adds under~/.claude/, and confirm it doesn’t override or bypass this repo’s own secret-guard hook — see Hooks, Permissions and the Locked Policy. - Git hooks run code on every commit/checkout.
graphify hook installwrites into.git/hooks/. Check that it doesn’t overwrite an existing hook, and remember that re-indexing on checkout means a branch with a newly added secret file is indexed automatically unless that file is already ignored. graph.htmlis a shareable artifact. It renders node labels and extracted text. Treat it like source code with possible secrets: don’t upload it, attach it to tickets, or share it outside the team.- The
grepcheck below only matches paths. Searching forenvfinds indexed file names, not leaked secret values. It also prints matching lines to the terminal (and into a Claude session, if Claude runs it). Prefer counts or filenames, and use a real secret scanner. - Ignore rules aren’t retroactive. If a secret was indexed before it was added to
.graphifyignore, deletegraphify-out/and rebuild. Then rotate the secret if the graph was ever committed, shared, or queried by Claude.
Verifying the Output
# Count path matches without printing the matching lines
grep -ci "\.env" graphify-out/graph.json
# Scan the output folder for secret values (requires gitleaks: brew install gitleaks)
gitleaks detect --no-git --source graphify-out --redact
If either check finds something: delete graphify-out/, fix .graphifyignore, re-run graphify ., and rotate any exposed credential.
Protecting Secrets with Claude Code Hooks
.graphifyignore alone is not enough to protect secrets. It only controls what graphify reads while it builds the graph. It does nothing when Claude (or a prompt) runs a raw shell command such as grep -rn "API_KEY" . or cat .env, which reads files directly.
Why Ignore Files Can Fail
| Layer | What it protects | What it doesn’t stop |
|---|---|---|
.graphifyignore |
Files read by graphify during indexing |
Claude’s own Read/Grep/Bash tool calls |
permissions.deny in .claude/settings.json |
Claude’s built-in file tools (e.g. Read(./.env)) |
Shell commands that read the same file via Bash |
PreToolUse hook |
Every matching tool call, including Bash commands, before it runs |
Secrets already captured in graphify-out/graph.json |
Claude Code has no
.claudeignorefile. File-level exclusion is done withpermissions.denyrules insettings.json, plus aPreToolUsehook for anything a deny rule can’t express.
Residual graph artifacts are the gap no hook covers: if a secret was indexed before .graphifyignore existed, it lives in graphify-out/graph.json, and graphify query returns it to Claude like any other node. The only fix is to rebuild the graph (see Verifying the Output above).
Use the Workspace Hooks — Don’t Add Another
The shared workspace already runs a PreToolUse secret guard (env-guard) and a scope guard on every session. In the dev container they are installed as a locked managed policy. No extra hook is needed for graphify. If a new secret-file shape appears, add its pattern to the existing env-guard. See Hooks, Permissions and the Locked Policy for what they block, how to test them and how to change them.
How It Interacts with Graphify’s Own Hook
Claude Code runs every matching PreToolUse hook, and any one of them can block a call, so graphify’s hook-guard entries cannot switch off the secret guard. Graphify reads files itself when it indexes, so .graphifyignore is the only control at index time. Check it before running graphify . in a new folder, and run the graph.json verification checks in your own terminal.
Verify the Hook
Ask Claude Code:
“Run grep across the repository for DB_PASSWORD in .env files.”
Expected result: the call is rejected with an [env-guard] Blocked Bash: … message, and no file contents enter the context window.