Claude Code setup: CLAUDE.md, rust-analyzer through LSP, and CodeGraph #1197

Open
github-bot wants to merge 2 commits from github-bot/gh-1197 into main AGit
Owner

@⁠KluseG on GitHub · 2026-11-25 23:29 UTC · original
KluseG:docs/claude-code-setup → main · +78 −0 · 3 files · 2 commits · open

This fork is developed with Claude Code (see the README's credits). Today every session starts with no
project context. It finds its way around about 134k lines of Rust with text search and whole-file reads.
That is costly here: victory-shader/src/emit/lower.rs is about 12k lines, victory-gpu/src/host.rs
about 9k, and victory-gpu alone is about 60k. This PR adds three things that make those sessions
cheaper and safer. Only the first two change files in the repo.

1. CLAUDE.md: project rules loaded into every session

Claude Code reads CLAUDE.md at the start of every session. The new file is short (67 lines) and
holds what a session currently has to rediscover, or can get wrong:

  • Rule #1 and how it is enforced. It explains that cargo xtask policy checks untracked,
    not-ignored
    files too, and that cargo test runs it (repository_passes_policy). So any stray
    cache or index file breaks the tests. It also says never to paste game-derived output into commits,
    tests or docs. This is the rule an AI session is most likely to break by accident, for example by
    quoting shader disassembly in a test.
  • The real build and CI commands. These are the two clippy runs (plain and --all-features),
    --locked, and the diag profile, so a session checks its work the same way CI does.
  • A crate map with sizes, plus a note to navigate the very large files by symbol, not read them whole.
  • The fork's conventions: new behaviour goes off by default behind a VICTORY_* switch (there are
    about 250 of them, read where they are used); no claimed speed-up without a measured run; and credit
    for ported patches.

2. rust-analyzer through Claude Code's LSP support

Claude Code has an LSP tool that uses a language server installed through a code-intelligence plugin.
With rust-analyzer behind it, a session can:

  • jump to definitions and list all references by symbol instead of grepping. This matters in this
    codebase because the same names recur across victory-gpu and victory-shader (there are three
    host.rs files and two resource.rs files);
  • see rust-analyzer's diagnostics right after each edit (type errors, borrow errors, unused
    Results, which unused_must_use = "deny" turns into hard errors), before a slow full cargo clippy
    run on a 2024-edition workspace.

.claude/settings.json enables the official plugin for the project:

{ "enabledPlugins": { "rust-analyzer-lsp@claude-plugins-official": true } }

Each contributor still has to do two things once (enabling the plugin in the repo does not install it):

rustup component add rust-analyzer
claude plugin install rust-analyzer-lsp@claude-plugins-official --scope project

Caveats:

  • Non-Windows hosts. 36 files are cfg(windows), and the toolchain targets
    x86_64-pc-windows-msvc. Run on macOS or Linux, rust-analyzer analyses for the host target, so it
    treats that code as inactive. On the Windows dev machine it works as is. Fixing this elsewhere would
    need a small project plugin that passes cargo.target to rust-analyzer; that is not part of this PR.
  • rust-toolchain.toml. Adding "rust-analyzer" to components in this file would install the
    binary automatically for everyone, CI included. I left that out so this PR doesn't change CI; it is
    an easy follow-up if you want it.
  • No Claude Code on the web. The plugin's language server doesn't start in Claude Code on the web
    (cloud sessions).

3. CodeGraph: a local code graph over MCP (opt-in, nothing committed)

CodeGraph (MIT) indexes the code with tree-sitter into a
local SQLite database (.codegraph/). It serves the index to Claude Code as an MCP server. Rust is a
fully supported language. One codegraph_explore call returns the relevant symbols' source, the call
paths between them and a summary of what depends on them. That suits questions this fork asks all the
time, such as "what reads VICTORY_CARD_HASH_LEN, and what does that code call?", or "what does
changing changed_runs affect?".

Its README claims 88% fewer tool calls and 62% fewer tokens across its benchmark repos. For Tokio it
claims 3 tool calls instead of 29. These are the project's own numbers and we haven't measured them
here. The project also says the index leaves more retrieval context in the window over a long session.

There is nothing to commit. Anyone who wants it runs:

npm i -g @colbymchenry/codegraph
codegraph init --local-only        # builds .codegraph/, keeps it out of git
codegraph install --target=claude --location=global

Code doesn't leave the machine. The CLI sends anonymous usage counts by default; turn that off with
codegraph telemetry off. This PR adds /.codegraph/ to .gitignore. Otherwise the database would
show up as untracked binary data, and cargo xtask policy, and with it cargo test, would fail.

What changes

File Change
CLAUDE.md new: rules, commands, layout, conventions
.claude/settings.json new: enables rust-analyzer-lsp@claude-plugins-official
.gitignore ignores /.claude/settings.local.json, /CLAUDE.local.md, /.codegraph/

No Rust code changes. cargo xtask policy --staged passes on the three files.

Found while testing (not fixed here)

On main, cargo xtask policy fails. The reason is that two diagnostic logs are over the policy's
512 KiB limit: diagnostics/timing-run-2026-11-25.txt (3,311,492 bytes, added in 44bff61) and
diagnostics/timing-run-295s-2026-11-25.txt (6,551,447 bytes, added in 32b31f7). So
repository_passes_policy, and with it the CI test step, should fail on main as it stands. I left
it alone because the fix is a policy choice: trim the logs, or add an exception with a reason in
xtask/src/policy.rs.

🤖 Generated with Claude Code

**@⁠KluseG** on GitHub · 2026-11-25 23:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/1197) `KluseG:docs/claude-code-setup` → `main` · +78 −0 · 3 files · 2 commits · open This fork is developed with Claude Code (see the README's credits). Today every session starts with no project context. It finds its way around about 134k lines of Rust with text search and whole-file reads. That is costly here: `victory-shader/src/emit/lower.rs` is about 12k lines, `victory-gpu/src/host.rs` about 9k, and `victory-gpu` alone is about 60k. This PR adds three things that make those sessions cheaper and safer. Only the first two change files in the repo. ## 1. `CLAUDE.md`: project rules loaded into every session Claude Code reads `CLAUDE.md` at the start of every session. The new file is short (67 lines) and holds what a session currently has to rediscover, or can get wrong: - **Rule #1 and how it is enforced.** It explains that `cargo xtask policy` checks *untracked, not-ignored* files too, and that `cargo test` runs it (`repository_passes_policy`). So any stray cache or index file breaks the tests. It also says never to paste game-derived output into commits, tests or docs. This is the rule an AI session is most likely to break by accident, for example by quoting shader disassembly in a test. - **The real build and CI commands.** These are the two clippy runs (plain and `--all-features`), `--locked`, and the `diag` profile, so a session checks its work the same way CI does. - **A crate map with sizes**, plus a note to navigate the very large files by symbol, not read them whole. - **The fork's conventions:** new behaviour goes off by default behind a `VICTORY_*` switch (there are about 250 of them, read where they are used); no claimed speed-up without a measured run; and credit for ported patches. ## 2. rust-analyzer through Claude Code's LSP support Claude Code has an `LSP` tool that uses a language server installed through a code-intelligence plugin. With rust-analyzer behind it, a session can: - **jump to definitions and list all references by symbol** instead of grepping. This matters in this codebase because the same names recur across `victory-gpu` and `victory-shader` (there are three `host.rs` files and two `resource.rs` files); - **see rust-analyzer's diagnostics right after each edit** (type errors, borrow errors, unused `Result`s, which `unused_must_use = "deny"` turns into hard errors), before a slow full `cargo clippy` run on a 2024-edition workspace. `.claude/settings.json` enables the official plugin for the project: ```json { "enabledPlugins": { "rust-analyzer-lsp@claude-plugins-official": true } } ``` Each contributor still has to do two things once (enabling the plugin in the repo does not install it): ``` rustup component add rust-analyzer claude plugin install rust-analyzer-lsp@claude-plugins-official --scope project ``` Caveats: - **Non-Windows hosts.** 36 files are `cfg(windows)`, and the toolchain targets `x86_64-pc-windows-msvc`. Run on macOS or Linux, rust-analyzer analyses for the host target, so it treats that code as inactive. On the Windows dev machine it works as is. Fixing this elsewhere would need a small project plugin that passes `cargo.target` to rust-analyzer; that is not part of this PR. - **`rust-toolchain.toml`.** Adding `"rust-analyzer"` to `components` in this file would install the binary automatically for everyone, CI included. I left that out so this PR doesn't change CI; it is an easy follow-up if you want it. - **No Claude Code on the web.** The plugin's language server doesn't start in Claude Code on the web (cloud sessions). ## 3. CodeGraph: a local code graph over MCP (opt-in, nothing committed) [CodeGraph](https://github.com/colbymchenry/codegraph) (MIT) indexes the code with tree-sitter into a local SQLite database (`.codegraph/`). It serves the index to Claude Code as an MCP server. Rust is a fully supported language. One `codegraph_explore` call returns the relevant symbols' source, the call paths between them and a summary of what depends on them. That suits questions this fork asks all the time, such as "what reads `VICTORY_CARD_HASH_LEN`, and what does that code call?", or "what does changing `changed_runs` affect?". Its README claims 88% fewer tool calls and 62% fewer tokens across its benchmark repos. For Tokio it claims 3 tool calls instead of 29. These are the project's own numbers and we haven't measured them here. The project also says the index leaves more retrieval context in the window over a long session. There is nothing to commit. Anyone who wants it runs: ``` npm i -g @colbymchenry/codegraph codegraph init --local-only # builds .codegraph/, keeps it out of git codegraph install --target=claude --location=global ``` Code doesn't leave the machine. The CLI sends anonymous usage counts by default; turn that off with `codegraph telemetry off`. This PR adds `/.codegraph/` to `.gitignore`. Otherwise the database would show up as untracked binary data, and `cargo xtask policy`, and with it `cargo test`, would fail. ## What changes | File | Change | |------|--------| | `CLAUDE.md` | new: rules, commands, layout, conventions | | `.claude/settings.json` | new: enables `rust-analyzer-lsp@claude-plugins-official` | | `.gitignore` | ignores `/.claude/settings.local.json`, `/CLAUDE.local.md`, `/.codegraph/` | No Rust code changes. `cargo xtask policy --staged` passes on the three files. ## Found while testing (not fixed here) On `main`, `cargo xtask policy` fails. The reason is that two diagnostic logs are over the policy's 512 KiB limit: `diagnostics/timing-run-2026-11-25.txt` (3,311,492 bytes, added in `44bff61`) and `diagnostics/timing-run-295s-2026-11-25.txt` (6,551,447 bytes, added in `32b31f7`). So `repository_passes_policy`, and with it the CI test step, should fail on `main` as it stands. I left it alone because the fix is a policy choice: trim the logs, or add an exception with a reason in `xtask/src/policy.rs`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CLAUDE.md: rule #1 and how `cargo xtask policy` enforces it, the build and
CI commands, the crate map with sizes, and the fork's conventions
(VICTORY_* switches off by default, measured claims only).

.claude/settings.json enables rust-analyzer-lsp@claude-plugins-official so
Claude Code navigates by definitions and references and sees rust-analyzer's
diagnostics after each edit. Each contributor still installs the plugin once.

.gitignore: personal Claude Code files and the local CodeGraph index, which
the policy check would otherwise reject as untracked binary data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:20 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1197/head:github-bot/gh-1197'
git switch 'github-bot/gh-1197'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1197'
git switch 'github-bot/gh-1197'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1197'
git switch 'github-bot/gh-1197'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1197'
git switch 'main'
git merge --squash 'github-bot/gh-1197'
git switch 'main'
git merge --ff-only 'github-bot/gh-1197'
git switch 'main'
git merge 'github-bot/gh-1197'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.