Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- No changes yet.
### Added

- Claude Code MCP user scope (`claudeScope: "user"`, with `"global"` as an alias), defaulting new home-directory installs to user scope while normal repositories keep project scope. User entries carry a per-project prefix; scope changes, disabling Claude and reset clean up recorded CLI registrations without removing another project's servers.

### Fixed

- Claude user-scope status prefers the project's scoped registration when legacy server names are also visible.

## [0.9.2] - 2026-10-12

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Eighteen tools. "Verified" means the tool's own CLI was run against the file thi
| Integration | `--llm` id | MCP config it writes | Skills | Verified |
|:--|:--|:--|:--:|:--:|
| Codex | `codex` | `.codex/config.toml` (managed block, project trust handled) | native | ✅ |
| Claude Code | `claude` | `.mcp.json` project scope, plus root `CLAUDE.md` wrapper | bridge | ✅ |
| Claude Code | `claude` | `.mcp.json` project scope or CLI local/user scope, plus root `CLAUDE.md` wrapper | bridge | ✅ |
| Claude Desktop | `claude_desktop` | global `claude_desktop_config.json`, stdio servers only | — | ✅ |
| Gemini CLI | `gemini` | `.gemini/settings.json` | bridge | ✅ |
| Cursor | `cursor` | `.cursor/mcp.json` + CLI enable | bridge | ✅ |
Expand Down Expand Up @@ -326,7 +326,7 @@ No. <code>AGENTS.md</code> stays the instruction file every tool reads. This CLI
<details>
<summary><b>Why does Claude Code use <code>.mcp.json</code> now?</b></summary>
<br/>
Project scope is the location Anthropic documents for teams: it lives in the repository, so everyone working on it gets the same servers, and in `commit-generated` mode it is reviewed like any other file. Before 0.9.0 the CLI registered servers in the machine-local <code>~/.claude.json</code>, which nobody else could see. Set <code>integrations.options.claudeScope</code> to <code>"local"</code> for the old behaviour; projects upgrading from schema 3 keep it automatically.
Project scope is the location Anthropic documents for teams: it lives in the repository, so everyone working on it gets the same servers, and in `commit-generated` mode it is reviewed like any other file. Before 0.9.0 the CLI registered servers in the machine-local <code>~/.claude.json</code>, which nobody else could see. Set <code>integrations.options.claudeScope</code> to <code>"local"</code> for the old behaviour; projects upgrading from schema 3 keep it automatically. For servers available in every project, set it to <code>"user"</code> (<code>"global"</code> is an alias) and run <code>agents sync -g</code>. New home-directory installs (<code>agents init -g</code> or <code>agents start -g</code>) default to user scope; normal repositories default to project scope. Existing explicit choices are preserved. See [Claude MCP scopes](docs/agents-system.md#claude-mcp-scopes) for migration and cleanup.
</details>

<details>
Expand Down
50 changes: 48 additions & 2 deletions docs/agents-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ project/
| Tool | Generated Config |
|:-----|:-----------------|
| **Codex** | `.codex/config.toml`, managed block only |
| **Claude Code** | `.mcp.json` (project scope) + root `CLAUDE.md` wrapper; `claude mcp add -s local` when `claudeScope` is `local` |
| **Claude Code** | `.mcp.json` (project scope) + root `CLAUDE.md` wrapper; `claude mcp add -s local` or `-s user` when `claudeScope` is `local` or `user` |
| **Claude Desktop** | Global `claude_desktop_config.json`, local stdio MCP only, preserving other entries |
| **Gemini** | `.gemini/settings.json` |
| **Cursor** | `.cursor/mcp.json` + CLI enable |
Expand Down Expand Up @@ -99,6 +99,52 @@ exactly those and leaves everything else, including entries added by hand.
Claude Code (project scope) and Copilot CLI both do, so it is written once for both,
and `agents sync` reports that per-tool `targets` cannot isolate servers inside it.

## Claude MCP Scopes

`integrations.options.claudeScope` accepts:

| Value | Storage | Availability |
| --- | --- | --- |
| `project` | Repository `.mcp.json` | Everyone using that repository |
| `local` | Project entry in `~/.claude.json`, through the Claude CLI | You, in that project |
| `user` | User entry in `~/.claude.json`, through the Claude CLI | You, in every project |

`global` is accepted as an alias for `user`. New home-directory installs, including
`agents init -g` and `agents start -g`, default to `user`; normal repositories default
to `project`. Existing explicit values are preserved, including `local` from a schema 3
migration. `-g` selects `~/.agents`; it does not override an explicit scope.

To move an existing home install from `local` or `project` to `user`, set this in
`~/.agents/agents.json`:

```json
{
"integrations": {
"enabled": ["claude"],
"options": { "claudeScope": "user" }
}
}
```

Then run:

```bash
agents sync -g
# Later syncs should report no changes:
agents sync -g --check
```

Claude CLI must be installed for local/user registrations. User entries use
`agents__<hash of the source project path>__<server>` so separate configs do not overwrite
each other. Sync removes recorded registrations in the previous scope before adding
entries in the new CLI scope. When moving from project scope, it removes managed
`.mcp.json` entries unless Copilot CLI still needs them. Failed CLI removals retain
ownership for retry; `--check` reports drift without adding or removing registrations.
Disabling Claude or running `agents reset -g` also removes its recorded CLI registrations.

Claude gives local scope precedence over project and user scope. See
[Anthropic's MCP scope documentation](https://code.claude.com/docs/en/mcp#mcp-installation-scopes).

## Claude Instructions

- `AGENTS.md` is the only canonical instruction source in the project.
Expand Down Expand Up @@ -241,7 +287,7 @@ syncing every server is the opposite of what was asked for.

## Entries in Global Configs

Claude Desktop, the global Windsurf config and the Goose config live in the home
Claude Code user scope, Claude Desktop, the global Windsurf config and the Goose config live in the home
directory and are shared by every project on the machine. Entries this CLI writes into
them are named `agents__<hash of the project path>__<server>`, so two projects that both
define a server called `fetch` keep their own entry and `agents reset` in one of them
Expand Down
3 changes: 2 additions & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path'
import { isHomeDirectory } from '../core/paths.js'
import { ensureProjectGitignore } from '../core/gitignore.js'
import { AGENTS_SCHEMA_VERSION } from '../types.js'
import { initializeProjectSkeleton } from '../core/project.js'
Expand All @@ -23,7 +24,7 @@ export async function runInit(options: InitOptions): Promise<void> {
integrationOptions: {
cursorAutoApprove: true,
antigravityGlobalSync: true,
claudeScope: 'project',
claudeScope: isHomeDirectory(projectRoot) ? 'user' : 'project',
copilotCliPath: '.mcp.json'
},
syncMode: 'source-only',
Expand Down
12 changes: 6 additions & 6 deletions src/commands/mcp-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { listMcpEntries, loadMcpState, type McpServerEntry } from '../core/mcpCr
import { resolveFromConfigAndLocal, resolveServer } from '../core/mcp.js'
import { commandExists, runCommand } from '../core/shell.js'
import { listCursorMcpStatuses, sanitizeTerminalOutput, type CursorServerState } from '../core/cursorCli.js'
import { toProjectScopedName } from '../core/globalScope.js'
import { toManagedClaudeName } from '../integrations/claude.js'
import * as ui from '../core/ui.js'
import type { IntegrationName, McpServerDefinition } from '../types.js'
Expand Down Expand Up @@ -266,7 +267,7 @@ function runRuntimeChecks(entries: McpServerEntry[], projectRoot: string, timeou
}

if (integration === 'claude') {
runtimeByIntegration.claude = checkClaudeServer(entry.name, claudeProbe)
runtimeByIntegration.claude = checkClaudeServer(entry.name, claudeProbe, projectRoot)
if (claudeProbe.available && runtimeByIntegration.claude.status === 'error') errors += 1
continue
}
Expand All @@ -293,16 +294,15 @@ function runRuntimeChecks(entries: McpServerEntry[], projectRoot: string, timeou
}
}

/** Map one server to what `claude mcp list` says about it, in either scope. */
function checkClaudeServer(name: string, probe: RuntimeProbe<Record<string, ClaudeRuntimeStatus>>): RuntimeIntegrationResult {
/** Map one server to what `claude mcp list` says about it across MCP scopes. */
function checkClaudeServer(name: string, probe: RuntimeProbe<Record<string, ClaudeRuntimeStatus>>, projectRoot: string): RuntimeIntegrationResult {
if (!probe.available || !probe.data) {
return {
status: 'unavailable',
message: probe.detail
}
}
// Project scope registers the plain name; local scope keeps the agents__ prefix.
const status = probe.data[name] ?? probe.data[toManagedClaudeName(name)]
const status = probe.data[name] ?? probe.data[toManagedClaudeName(name)] ?? probe.data[toProjectScopedName(projectRoot, name)]
if (status === 'ok') {
return {
status: 'ok',
Expand Down Expand Up @@ -335,7 +335,7 @@ function checkClaudeServer(name: string, probe: RuntimeProbe<Record<string, Clau
}
return {
status: 'error',
message: `Missing from claude mcp list as ${name} or ${toManagedClaudeName(name)}`
message: `Missing from claude mcp list as ${name}, ${toManagedClaudeName(name)} or ${toProjectScopedName(projectRoot, name)}`
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/commands/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
removeCodexManagedBlock,
removeLegacyGeneratedCodexMcp
} from '../core/codexConfig.js'
import { syncClaude } from '../core/claudeSync.js'
import { cleanupManagedClaudeInstructions } from '../core/claudeInstructions.js'
import { cleanupManagedClaudeDesktopConfig } from '../core/claudeDesktop.js'
import { cleanupVscodeSettingsIfManaged } from '../core/vscodeSettings.js'
Expand Down Expand Up @@ -58,6 +59,16 @@ export async function runReset(options: ResetOptions): Promise<void> {

const removed: string[] = []
const warnings: string[] = []
await syncClaude({
enabled: false,
scope: 'local',
check: false,
projectRoot,
servers: [],
statePath: paths.generatedClaudeState,
changed: removed,
warnings
})
const claudeDesktopCleanup = await cleanupManagedClaudeDesktopConfig(projectRoot)
if (claudeDesktopCleanup.changed && claudeDesktopCleanup.path) {
removed.push(claudeDesktopCleanup.path)
Expand Down
46 changes: 24 additions & 22 deletions src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { syncProjectDocsSections } from '../core/projectDocs.js'
import type { AgentsConfig, IntegrationName, SyncMode } from '../types.js'
import { INTEGRATIONS } from '../integrations/registry.js'
import { SKILL_BRIDGES } from '../core/skills.js'
import { getProjectPaths, toHomeRelativePath } from '../core/paths.js'
import { getProjectPaths, isHomeDirectory, toHomeRelativePath } from '../core/paths.js'
import { runReset } from './reset.js'
import { ensureCodexProjectTrusted, ensureGrokProjectTrusted, getCodexTrustState, getGrokTrustState }
from '../core/trust.js'
Expand Down Expand Up @@ -44,6 +44,10 @@ export async function runStart(options: StartOptions): Promise<void> {
throw new Error(`Project path does not exist: ${projectRoot}`)
}

const defaultIntegrationOptions: AgentsConfig['integrations']['options'] = {
...DEFAULT_INTEGRATION_OPTIONS,
claudeScope: isHomeDirectory(projectRoot) ? 'user' : 'project'
}
const interactive = !options.nonInteractive && !options.yes
const paths = getProjectPaths(projectRoot)
const reinit = options.reinit === true
Expand Down Expand Up @@ -95,32 +99,28 @@ export async function runStart(options: StartOptions): Promise<void> {
}

const defaults = getDefaults()
const selectedIntegrations = preserveExistingConfig
? [...(existingConfig?.integrations.enabled ?? [])]
: interactive
? await selectIntegrations(defaults.integrationDefaults)
: defaults.integrationDefaults

const syncMode = preserveExistingConfig
? (existingConfig?.syncMode ?? defaults.syncMode)
: interactive
? await selectSyncMode(defaults.syncMode)
: defaults.syncMode

const hideGeneratedInVscode = preserveExistingConfig
? (existingConfig?.workspace.vscode.hideGenerated ?? defaults.hideGeneratedInVscode)
: interactive
? await selectVscodeHideDefaults(defaults.hideGeneratedInVscode)
: defaults.hideGeneratedInVscode
let selectedIntegrations = defaults.integrationDefaults
let syncMode = defaults.syncMode
let hideGeneratedInVscode = defaults.hideGeneratedInVscode
let integrationOptions = defaultIntegrationOptions

if (preserveExistingConfig) {
selectedIntegrations = [...(existingConfig?.integrations.enabled ?? [])]
syncMode = existingConfig?.syncMode ?? defaults.syncMode
hideGeneratedInVscode = existingConfig?.workspace.vscode.hideGenerated ?? defaults.hideGeneratedInVscode
integrationOptions = existingConfig?.integrations.options ?? defaultIntegrationOptions
} else if (interactive) {
selectedIntegrations = await selectIntegrations(defaults.integrationDefaults)
syncMode = await selectSyncMode(defaults.syncMode)
hideGeneratedInVscode = await selectVscodeHideDefaults(defaults.hideGeneratedInVscode)
}

const access = await resolveIntegrationAccess({
projectRoot,
selectedIntegrations,
interactive,
autoApprove: options.yes || options.nonInteractive,
integrationOptions: preserveExistingConfig
? (existingConfig?.integrations.options ?? DEFAULT_INTEGRATION_OPTIONS)
: DEFAULT_INTEGRATION_OPTIONS,
integrationOptions,
allowOptionPrompts: !preserveExistingConfig
})

Expand Down Expand Up @@ -176,7 +176,9 @@ export async function runStart(options: StartOptions): Promise<void> {
: { changed: [], skipped: [] }

spin?.stop('Setup complete.')
const configMode = preserveExistingConfig ? 'preserved existing config' : forceInitialize ? 'reinitialized' : 'initialized'
let configMode = 'initialized'
if (preserveExistingConfig) configMode = 'preserved existing config'
else if (forceInitialize) configMode = 'reinitialized'

const summaryLines = [
`Project: ${projectRoot}`,
Expand Down
25 changes: 14 additions & 11 deletions src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { listMcpEntries, loadMcpState } from '../core/mcpCrud.js'
import { inspectAntigravitySkillsBridge, SKILL_BRIDGES } from '../core/skills.js'
import { listCursorMcpStatuses, sanitizeTerminalOutput } from '../core/cursorCli.js'
import * as ui from '../core/ui.js'
import type { ClaudeScope } from '../types.js'

export interface StatusOptions {
projectRoot: string
Expand Down Expand Up @@ -144,7 +145,11 @@ export async function runStatus(options: StatusOptions): Promise<void> {
if (enabled.has('codex')) probes.codex_trust = await probeCodexTrust(options.projectRoot)
if (enabled.has('grok')) probes.grok_trust = await probeGrokTrust(options.projectRoot)
if (enabled.has('claude')) {
probes.claude = probeClaude(options.projectRoot, resolved.serversByTarget.claude.map((server) => server.name))
probes.claude = probeClaude(
options.projectRoot,
resolved.serversByTarget.claude.map((server) => server.name),
config.integrations.options.claudeScope
)
}
if (enabled.has('claude_desktop')) {
probes.claude_desktop = claudeDesktopConfigPath && claudeDesktopConfigLabel
Expand Down Expand Up @@ -357,29 +362,27 @@ function probeCodex(projectRoot: string, expectedServerNames: string[]): string
}
}

/**
* Count the MCP servers Claude Code sees for this project.
*
* Project scope registers servers under their plain names, local scope under the
* `agents__` prefix, so both spellings are counted.
*/
function probeClaude(projectRoot: string, expectedServerNames: string[]): string {
/** Count the MCP servers Claude Code sees for this project. */
function probeClaude(projectRoot: string, expectedServerNames: string[], claudeScope: ClaudeScope): string {
if (!commandExists('claude')) return 'claude CLI not found'
const result = runCommand('claude', ['mcp', 'list'], projectRoot)
if (!result.ok) return `failed (${compact(result.stderr)})`
const lines = sanitizeTerminalOutput(result.stdout)
.split('\n')
.map((line) => line.trim())

// One line per expected server: a project-scope entry and its local-scope twin are
// the same server, not two.
const linesByName = new Map<string, string>()
for (const line of lines) {
const name = line.match(/^([a-zA-Z0-9._:-]+):/)?.[1]
if (name !== undefined && !linesByName.has(name)) linesByName.set(name, line)
}
const managedLines = expectedServerNames
.map((name) => linesByName.get(name) ?? linesByName.get(`agents__${name}`))
.map((name) => {
const unscopedLine = linesByName.get(name) ?? linesByName.get(`agents__${name}`)
const scopedLine = linesByName.get(toProjectScopedName(projectRoot, name))
if (claudeScope === 'user') return scopedLine ?? unscopedLine
return unscopedLine ?? scopedLine
})
.filter((line): line is string => line !== undefined)

const managed = managedLines.length
Expand Down
Loading
Loading