Flag a project for prototype mode: no git worktrees, Claude edits the current checkout directly. Works for background jobs too.

A Claude Code plugin that flags a project for prototype mode: no git worktrees, Claude edits the current checkout directly. Works for interactive sessions and background jobs.

claude plugin marketplace add brunolca/claude-plugins
claude plugin install prototype-mode@brunolca
Or from inside Claude Code: /plugin marketplace add brunolca/claude-plugins, then /plugin install prototype-mode@brunolca.
Commit this to the project's .claude/settings.json so everyone who trusts the repo is offered the plugin, and prototype mode is on for all of them:
{
"extraKnownMarketplaces": {
"brunolca": {
"source": { "source": "github", "repo": "brunolca/claude-plugins" }
}
},
"enabledPlugins": { "prototype-mode@brunolca": true },
"worktree": { "bgIsolation": "none" }
}
/proto on team writes the worktree part for you.
| Command | Effect |
|---|---|
/proto on | Sets worktree.bgIsolation: "none" in .claude/settings.local.json (just you) |
/proto on team | Same, in .claude/settings.json (commit it to share) |
/proto off [team] | Removes it; a team "none" is overridden locally with "worktree" |
/proto / /proto status | Shows the effective mode and where it comes from |
The status line shows 🧪 prototype mode while it's on.
worktree.bgIsolation: "none" is Claude Code's own setting. It turns off the guard that blocks Edit/Write in the main checkout until EnterWorktree is called. The CLAUDE_BG_ISOLATION env var outranks it. This part works even without the plugin.EnterWorktree. It says nothing else about how to work.EnterWorktree is refused, and isolation: "worktree" is stripped from subagent (Agent) calls.claude --plugin-dir . # load this checkout for one session
claude plugin validate .
claude plugin test .
Requires a Claude Code build with function-hook plugins (2.1.289 or newer).
hooks/register.ts 153 lines1import type { EngineInterface, Register, Settings } from 'claude-code'
2
3// Prototype mode is the engine's own `worktree.bgIsolation: "none"` setting:
4// with it, background jobs may edit the main checkout directly instead of
5// being blocked until they call EnterWorktree. `/proto on` writes it to the
6// project's .claude/settings.local.json (just you) or, with `team`, to
7// .claude/settings.json (commit it to share). This plugin adds the rest:
8// it tells the model, refuses EnterWorktree and drops subagent isolation.
9const STATUS = '🧪 prototype mode'
10
11// Only about worktrees: any wording about pace or workflow leaks into how the
12// model reasons and makes it shallower.
13const PROMPT = `# No worktrees
14This project works directly in the current checkout instead of in git worktrees. Editing here is allowed in background sessions too: don't call EnterWorktree before editing, and don't create worktrees unless the user asks for one.`
15
16type Isolation = 'none' | 'worktree'
17type Where = 'local' | 'project'
18
19const FILES: Record<Where, string> = {
20 local: '.claude/settings.local.json',
21 project: '.claude/settings.json',
22}
23
24const isolationOf = (settings: Settings): Isolation | undefined => {
25 const worktree = settings.worktree as { bgIsolation?: unknown } | undefined
26 const value = worktree?.bgIsolation
27
28 return value === 'none' || value === 'worktree' ? value : undefined
29}
30
31// The env var outranks every settings file, as it does for the engine's guard.
32const effective = async ($: EngineInterface): Promise<Isolation> => {
33 const env = await $.env.get('CLAUDE_BG_ISOLATION')
34 if (env === 'none' || env === 'worktree') return env
35
36 return isolationOf(await $.settings.read()) ?? 'worktree'
37}
38
39const isOn = async ($: EngineInterface) => (await effective($)) === 'none'
40
41const readJson = async ($: EngineInterface, path: string) => {
42 if (!(await $.fs.exists(path))) return {}
43 const parsed: unknown = JSON.parse(await $.fs.read(path))
44
45 return parsed !== null && typeof parsed === 'object' ? (parsed as Record<string, unknown>) : {}
46}
47
48// Sets (or, with undefined, removes) worktree.bgIsolation in one settings file,
49// keeping everything else in it.
50const writeIsolation = async ($: EngineInterface, where: Where, value: Isolation | undefined) => {
51 const path = `${await $.session.root()}/${FILES[where]}`
52 const settings = await readJson($, path)
53 const { bgIsolation: _old, ...worktree } = (settings.worktree ?? {}) as Record<string, unknown>
54 const next = value === undefined ? worktree : { ...worktree, bgIsolation: value }
55 const { worktree: _was, ...rest } = settings
56 const out = Object.keys(next).length === 0 ? rest : { ...rest, worktree: next }
57 await $.fs.write(path, `${JSON.stringify(out, null, 2)}\n`)
58
59 return path
60}
61
62const refreshStatus = async ($: EngineInterface) => $.ui.status((await isOn($)) ? STATUS : undefined)
63
64const describe = async ($: EngineInterface) => {
65 const root = await $.session.root()
66 const env = await $.env.get('CLAUDE_BG_ISOLATION')
67 const local = isolationOf(await $.settings.read({ source: 'local' }))
68 const project = isolationOf(await $.settings.read({ source: 'project' }))
69 const lines = [
70 `Prototype mode is ${(await isOn($)) ? 'ON' : 'OFF'} for ${root}.`,
71 ` ${FILES.local}: ${local ?? 'unset'}`,
72 ` ${FILES.project}: ${project ?? 'unset'}`,
73 ]
74 if (env !== undefined) lines.push(` CLAUDE_BG_ISOLATION=${env} (outranks both files)`)
75
76 return lines.join('\n')
77}
78
79export const register: Register = on => {
80 on('session.start', async ($, e, next) => {
81 await $.command.register({
82 name: 'proto',
83 description: 'Prototype mode (no worktrees, work on main): /proto [on|off|status] [team]',
84 })
85 await refreshStatus($)
86
87 return next(e)
88 })
89
90 on('command.run', { command: 'proto' }, async ($, e) => {
91 const [verb = 'status', scope] = e.args.trim().toLowerCase().split(/\s+/)
92 const isTeam = scope === 'team'
93
94 if (verb === 'status' || verb === '') return { text: await describe($) }
95 if ((verb !== 'on' && verb !== 'off') || (scope !== undefined && !isTeam)) {
96 return { text: 'Usage: /proto [on|off|status] [team]' }
97 }
98
99 try {
100 if (verb === 'on') {
101 const path = await writeIsolation($, isTeam ? 'project' : 'local', 'none')
102 // A personal "worktree" left in the local file would outrank a team "none".
103 if (isTeam && isolationOf(await $.settings.read({ source: 'local' })) === 'worktree') {
104 await writeIsolation($, 'local', undefined)
105 }
106 await refreshStatus($)
107 const text = `Prototype mode ON: set worktree.bgIsolation "none" in ${path}. Background jobs now edit this checkout directly.${isTeam ? ' Commit that file to share it.' : ''}`
108
109 return { text, context: [text] }
110 }
111
112 // off: clear ours; if the team file still says "none", override it locally.
113 await writeIsolation($, isTeam ? 'project' : 'local', undefined)
114 const isStillNone = isolationOf(await $.settings.read({ source: 'project' })) === 'none'
115 if (!isTeam && isStillNone) await writeIsolation($, 'local', 'worktree')
116 await refreshStatus($)
117 const text = `Prototype mode OFF: background jobs isolate in worktrees again.${!isTeam && isStillNone ? ` (${FILES.project} still says "none"; overridden in ${FILES.local}.)` : ''}`
118
119 return { text, context: [text] }
120 } catch (error) {
121 return { text: `Could not update settings: ${String(error)}` }
122 }
123 })
124
125 on('prompt.compose', async ($, e, next) => {
126 const composed = await next(e)
127 if (!(await isOn($))) return composed
128
129 return {
130 sections: [
131 ...composed.sections,
132 { id: 'prototype-mode:rules', text: PROMPT, scope: 'session' },
133 ],
134 }
135 })
136
137 on('tool.call', { tool: 'EnterWorktree' }, async ($, e, next) =>
138 (await isOn($))
139 ? {
140 deny: 'Prototype mode is on for this project: do not create a worktree. Keep working directly in the current checkout on the current branch; edits there are allowed.',
141 }
142 : next(e),
143 )
144
145 // Subagents run in the shared checkout too.
146 on('tool.call', { tool: 'Agent' }, async ($, e, next) => {
147 if (e.isolation !== 'worktree' || !(await isOn($))) return next(e)
148 const { isolation: _dropped, ...rest } = e
149
150 return next(rest)
151 })
152}
153