Skip to content

Commit c1a8e9e

Browse files
committed
chore(sync): cascade fleet template@4f6744a
Auto-applied by socket-wheelhouse sync-scaffolding into socket-mcp. 1 file(s) touched: - scripts/install-claude-plugins.mts
1 parent d10ab0d commit c1a8e9e

1 file changed

Lines changed: 1 addition & 85 deletions

File tree

scripts/install-claude-plugins.mts

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
* - For each plugin in the wheelhouse marketplace's
99
* `.claude-plugin/marketplace.json`, ensures it's installed at the
1010
* pinned SHA.
11-
* - Merges `env.CODEX_TRUSTED_ENV_PARENTS` into
12-
* `~/.claude/settings.json` so the upstream codex plugin's
13-
* SessionStart hook honors `~/.claude/session-env/` as a trusted
14-
* parent (Claude Code places per-session env files there, outside
15-
* `os.tmpdir()`).
1611
*
1712
* Idempotent — running twice is a no-op. Designed for `pnpm setup`
1813
* wiring in every fleet repo.
@@ -24,7 +19,7 @@
2419
*/
2520

2621
import { spawnSync } from 'node:child_process'
27-
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
22+
import { existsSync, readFileSync } from 'node:fs'
2823
import path from 'node:path'
2924
import process from 'node:process'
3025

@@ -39,13 +34,6 @@ const logger = getDefaultLogger()
3934
const MARKETPLACE_NAME = 'socket-wheelhouse'
4035
const MARKETPLACE_URL = 'https://github.com/SocketDev/socket-wheelhouse'
4136

42-
// The env var the codex plugin's SessionStart hook reads. Setting it
43-
// in `~/.claude/settings.json:env` makes Claude Code pass it to every
44-
// hook invocation. The value is the path Claude Code places per-session
45-
// env files under; the hook treats it as a trusted parent in addition
46-
// to `os.tmpdir()`.
47-
const CODEX_TRUSTED_ENV_PARENTS_KEY = 'CODEX_TRUSTED_ENV_PARENTS'
48-
4937
interface MarketplaceListEntry {
5038
name: string
5139
source: string
@@ -79,28 +67,6 @@ interface MarketplaceManifest {
7967
plugins?: MarketplacePlugin[]
8068
}
8169

82-
/**
83-
* Resolve the user's home directory. Matches the resolution order
84-
* `@socketsecurity/lib/env/home` uses (HOME → USERPROFILE), with a
85-
* fail-fast guard against the degenerate empty-string case.
86-
*/
87-
function resolveHome(): string {
88-
for (const candidate of [process.env['HOME'], process.env['USERPROFILE']]) {
89-
if (candidate && path.isAbsolute(candidate)) {
90-
return candidate
91-
}
92-
}
93-
throw new Error(
94-
'HOME / USERPROFILE not set to an absolute path — cannot resolve ' +
95-
'Claude Code config dir.',
96-
)
97-
}
98-
99-
const HOME = resolveHome()
100-
const CLAUDE_CONFIG_DIR = path.join(HOME, '.claude')
101-
const CLAUDE_SETTINGS_JSON = path.join(CLAUDE_CONFIG_DIR, 'settings.json')
102-
const CLAUDE_SESSION_ENV_DIR = path.join(CLAUDE_CONFIG_DIR, 'session-env')
103-
10470
/**
10571
* Run `claude` CLI synchronously; return stdout + exit code. Stderr
10672
* goes through to our own stderr so the user sees CLI errors in real
@@ -214,55 +180,6 @@ function ensurePluginInstalled(plugin: MarketplacePlugin): void {
214180
}
215181
}
216182
217-
interface SettingsShape {
218-
env?: Record<string, string>
219-
[k: string]: unknown
220-
}
221-
222-
function mergeTrustedEnvParent(): boolean {
223-
let settings: SettingsShape = {}
224-
if (existsSync(CLAUDE_SETTINGS_JSON)) {
225-
try {
226-
settings = JSON.parse(
227-
readFileSync(CLAUDE_SETTINGS_JSON, 'utf8'),
228-
) as SettingsShape
229-
} catch (e) {
230-
throw new Error(
231-
`~/.claude/settings.json is not parseable JSON: ${errorMessage(e)}. ` +
232-
'Fix it by hand before re-running this script.',
233-
)
234-
}
235-
}
236-
237-
const env = settings.env ?? {}
238-
const existing = env[CODEX_TRUSTED_ENV_PARENTS_KEY]
239-
const existingEntries = existing
240-
? existing.split(path.delimiter).map(s => s.trim()).filter(Boolean)
241-
: []
242-
if (existingEntries.includes(CLAUDE_SESSION_ENV_DIR)) {
243-
logger.log(
244-
`${CODEX_TRUSTED_ENV_PARENTS_KEY} already includes ${CLAUDE_SESSION_ENV_DIR}.`,
245-
)
246-
return false
247-
}
248-
const merged = [...existingEntries, CLAUDE_SESSION_ENV_DIR].join(
249-
path.delimiter,
250-
)
251-
const next: SettingsShape = {
252-
...settings,
253-
env: { ...env, [CODEX_TRUSTED_ENV_PARENTS_KEY]: merged },
254-
}
255-
writeFileSync(
256-
CLAUDE_SETTINGS_JSON,
257-
JSON.stringify(next, null, 2) + '\n',
258-
'utf8',
259-
)
260-
logger.log(
261-
`Set ${CODEX_TRUSTED_ENV_PARENTS_KEY}=${merged} in ${CLAUDE_SETTINGS_JSON}.`,
262-
)
263-
return true
264-
}
265-
266183
function main(): void {
267184
logger.log(`Reconciling Claude Code plugins to ${MARKETPLACE_NAME}`)
268185
const marketplace = ensureMarketplace()
@@ -276,7 +193,6 @@ function main(): void {
276193
for (const plugin of plugins) {
277194
ensurePluginInstalled(plugin)
278195
}
279-
mergeTrustedEnvParent()
280196
logger.log('Done.')
281197
}
282198

0 commit comments

Comments
 (0)