Skip to content

Commit 9166fc7

Browse files
committed
document per-project Claude Code configuration
Identity and every behavior flag are readable from the environment, and MCP server processes inherit the session environment, so an env-free registration in ~/.claude.json configures per project: each project carries its GERRIT_* identity and GERRIT_MCP_* behavior in the env block of .claude/settings.local.json, shared values sit in ~/.claude/settings.json, and the server's own defaults cover the rest. Identity stays per project deliberately - repositories may review on different Gerrit instances with different credentials. Layering rules established empirically against Claude Code: settings env is inherited by MCP server processes with normal settings precedence; a variable named in the registration's env block shadows every settings layer; $VAR/${VAR} references there never resolve from settings files - ${VAR} expands only from the shell that launched claude, otherwise the literal string is passed through.
1 parent e3d3778 commit 9166fc7

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,51 @@ claude mcp add gerrit \
114114
}
115115
```
116116

117+
## Per-project configuration in Claude Code
118+
119+
Everything the server needs is read from the environment — the identity variables above plus a `GERRIT_MCP_*`
120+
mirror for every flag (see [Configuration reference](#configuration-reference)) — and MCP server processes inherit
121+
the session environment. In Claude Code that turns one user-level registration into per-project configuration,
122+
down to different Gerrit instances with different credentials per repository.
123+
124+
**`~/.claude.json`** — the registration; no `env` block:
125+
126+
```json
127+
{
128+
"mcpServers": {
129+
"gerrit": {
130+
"command": "go-gerrit-mcp"
131+
}
132+
}
133+
}
134+
```
135+
136+
**`<project>/.claude/settings.local.json`** — the project's environment; every `env` entry reaches the server
137+
process:
138+
139+
```json
140+
{
141+
"env": {
142+
"GERRIT_URL": "https://gerrit.example.com",
143+
"GERRIT_USERNAME": "your-username",
144+
"GERRIT_TOKEN": "your-http-credential",
145+
"GERRIT_MCP_GROUPS": "read,comment",
146+
"GERRIT_MCP_PROJECTS": "core,infra"
147+
}
148+
}
149+
```
150+
151+
Values shared by most projects can sit one layer down in `~/.claude/settings.json` — settings files merge with
152+
`.claude/settings.local.json` over `.claude/settings.json` over `~/.claude/settings.json` — so a project declares
153+
only its deltas. Anything no layer sets falls back to the server's own defaults: read-only, own changes.
154+
155+
The registration's `env` block stays empty for a reason: a variable named there shadows every settings layer, and
156+
references are not a way around that — they never resolve from settings files. `${VAR}` expands only from the
157+
shell environment that launched `claude`, and anything unresolved reaches the server as a literal string.
158+
159+
Other MCP clients inherit their launch environment the same way, so per-directory tooling such as
160+
[direnv](https://direnv.net/) achieves the identical split without client support.
161+
117162
## Capability groups
118163

119164
Capability is selected at startup via `--groups` as a comma-separated list. Groups are independent and combinable —

0 commit comments

Comments
 (0)