A row above the prompt: the addons checkout's branch and dirty state, the local Odoo service, the worktree envs and their ports

A Copier template that generates a complete Odoo development environment on Nix flakes: native processes, systemd user services, a project-local PostgreSQL cluster, and a Python environment locked with uv.
No container, no global install, no pip in sight. The same generated project also runs as a test or production server.
uvx copier copy --trust gh:okolovmark/nixodoo-copier-template my-odoo-project
cd my-odoo-project
nix run .#create-env # .env: ports, database credentials
nix run .#update-repos # clone Odoo and the addon repos, build the symlink farm
nix run .#bootstrap-deps # import Odoo's requirements.txt into uv.lock
nix profile add .#dev-server # odoo, psql, ruff and friends into your profile
nix run .#setup-dev # postgres cluster (+ odoo.conf, nginx and systemd units without worktree envs)
systemctl --user enable --now postgres.service
With Claude Code and a custom addons repo, every pipeline run then gets its own worktree env (wt-start.sh <slug>): its own Odoo on its own port and its own restore of the prod dump; there is no main Odoo, nginx or database. Without them, setup-dev builds the classic single env (odoo.service, nginx.service, odoo-logrotate.timer) on the ports derived from your version. The generated README.md walks through the test and production flows the same way.
You need Nix with flakes enabled, uv (uvx runs copier without installing it), and a systemd user session. Starting from nothing:
curl -LsSf https://astral.sh/uv/install.sh | sh
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf
sudo systemctl restart nix-daemon
dev-server, test-server, prod-server, the first two wrapping odoo and the Postgres client tools against this project's cluster; prod-server carries Odoo alone - no proxy, no database client.repos.yaml for Odoo, addons.yaml for OCA and custom addon repos, pinned by branch or commit, with a symlink farm builder..env, odoo.conf with a random master password, systemd user units, a log-rotation timer, and an nginx reverse proxy for test (and dev without worktree envs) - production is left to whatever already fronts it.requirements.txt, locked with uv and built with uv2nix, so the flake and your shell agree.CLAUDE.md, guard hooks, Odoo skills including semantic code navigation over the official language server, a requirements interview, a development pipeline, deploy and production-operations runbooks, and a persistent memory.queue_job.The full inventory, including every skill and agent, is in docs/features.md.
Copier asks about twenty questions; most have a sensible default derived from your Odoo version. These are the ones worth a thought:
| Question | Default | Why you might change it |
|---|---|---|
odoo_version | 20.0 | everything else follows from it |
custom_repo_pattern / custom_repo_name | empty | your own addons repo; unlocks the development pipeline |
use_claude_code | true | the whole .claude/ layer |
use_kb | false | memory in kb instead of markdown files |
use_antigravity | false | work in Google Antigravity: next to Claude Code, or instead of it |
service_suffix | empty | set it to run two generated projects on one machine |
project_dir_var | ODOO<major>_PROJECT_DIR | same reason, for the project-root variable |
status_mcp / tickets_mcp | none | wire status posting and ticket tracking to Teams and Odoo |
backup_s3_bucket | empty | restore production dumps locally |
prod_ssh_host / test_ssh_hosts | empty | the deploy and prod-ops runbooks |
Every question and its default: docs/questions.md.
uvx copier update --trust
Template improvements land in the generated project. A few files are yours and are never overwritten (odools.toml, the estimate calibration table); for the rest, resolve conflicts in favour of the project where you have edited it. Hook arrays in .claude/settings.json deserve a second look after an update: copier can add a second key with the same name, and JSON keeps only the last one.
nix flake check shellchecks every generated script; python3 tests/test_nudge_find_code.py runs the hook regression corpus; claude plugin test in a mod's folder runs that mod's tests (CI runs every mod a render ships)MIT
hooks/register.tsx 266 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { EnvSnapshot, GitStatus, Service, Touched, WtEnv } from '../types'
5import {
6 isSameTouched,
7 mergeTouched,
8 parseActive,
9 parseGitStatus,
10 touchedBy,
11 worktreeSlug,
12 wtDb,
13} from './env'
14import type { Where } from './env'
15import { ADDONS, ADDONS_BRANCH, ANSWERS_FILE, ENV_BRANCHES, PORTS, SERVICE_SUFFIX } from './config'
16
17const REFRESH_MS = 20_000
18// the one service outside the worktree envs: the postgres cluster holding every wt_* database
19const SERVICES = [{ name: 'pg', unit: `postgres${SERVICE_SUFFIX}.service`, port: PORTS.pg }] as const
20
21const snapshot = atom({ plugin: 'odoo-env-band', key: 'snapshot' } as const, null)
22const touched = atom({ plugin: 'odoo-env-band', key: 'touched' } as const, { env: false, addons: false, wts: [] })
23
24let project: string | null = null
25
26// the project root: the nearest folder up from the session's root holding the copier answers file
27async function projectDir($: EngineInterface): Promise<string> {
28 if (project !== null) return project
29 const root = await $.session.root()
30 for (let dir = root; dir !== ''; dir = dir.slice(0, dir.lastIndexOf('/'))) {
31 if (await $.fs.exists(`${dir}/${ANSWERS_FILE}`)) return (project = dir)
32 }
33 return (project = root)
34}
35
36async function gitStatus($: EngineInterface, dir: string): Promise<GitStatus | null> {
37 const run = await $.process.run(['git', '-C', dir, 'status', '--porcelain=v2', '--branch'], { timeoutMs: 5000 })
38 return run.exitCode === 0 ? parseGitStatus(run.stdout) : null
39}
40
41async function collect($: EngineInterface): Promise<EnvSnapshot> {
42 const project = await projectDir($)
43 const cwd = await $.session.cwd()
44 const here = worktreeSlug(cwd, project)
45 // the cwd counts for addons and a worktree (going there is deliberate), never for the env repo it starts in
46 const mine = mergeTouched(await read($, touched), {
47 env: false,
48 addons: `${cwd}/`.startsWith(`${project}/${ADDONS}/`),
49 wts: here === null ? [] : [here],
50 })
51
52 const envRoot = `${project}/.worktrees/_env`
53 const slugs = (await $.fs.exists(envRoot))
54 ? (await $.fs.list(envRoot)).filter(entry => entry.kind === 'dir').map(entry => entry.name).sort()
55 : []
56 const ports = await Promise.all(
57 slugs.map(slug => $.fs.read(`${envRoot}/${slug}/port`).then(text => text.trim(), () => '?')),
58 )
59 // wt-start records each env's database (wt_<slug>_<MMDDYY>, the day of its dump)
60 const dbs = await Promise.all(
61 slugs.map(slug => $.fs.read(`${envRoot}/${slug}/db`).then(text => text.trim() || wtDb(slug), () => wtDb(slug))),
62 )
63 const wtUnit = (slug: string) => `odoo${SERVICE_SUFFIX}-wt@${slug}.service`
64 const units = [...SERVICES.map(service => service.unit), ...slugs.map(wtUnit)]
65 const systemctl = await $.process.run(['systemctl', '--user', 'is-active', ...units], { timeoutMs: 5000 })
66 const active = parseActive(systemctl.stdout, units)
67
68 const wts: WtEnv[] = await Promise.all(
69 slugs.map(async (slug, i) => {
70 const isMine = mine.wts.includes(slug)
71 return {
72 slug,
73 port: ports[i] ?? '?',
74 db: dbs[i] ?? wtDb(slug),
75 isActive: active[wtUnit(slug)] === true,
76 isMine,
77 git: isMine ? await gitStatus($, `${project}/.worktrees/${slug}`) : null,
78 }
79 }),
80 )
81 const services: Service[] = SERVICES.map(service => ({
82 name: service.name,
83 port: service.port,
84 isActive: active[service.unit] === true,
85 }))
86 return {
87 env: mine.env ? { git: await gitStatus($, project) } : null,
88 addons: mine.addons ? { git: await gitStatus($, `${project}/${ADDONS}`) } : null,
89 services,
90 wts,
91 }
92}
93
94// a worktree env's address: its database is the subdomain
95const address = (wt: WtEnv) => `${wt.db}.localhost:${wt.port}`
96const webUrl = (wt: WtEnv) => `http://${address(wt)}/web`
97
98async function openUrl($: EngineInterface, url: string): Promise<void> {
99 const run = await $.process.run(['xdg-open', url], { timeoutMs: 10_000 })
100 if (run.exitCode !== 0) $.ui.toast(`odoo-env-band: xdg-open ${url} failed: ${run.stderr.trim() || run.exitCode}`)
101}
102
103let running: Promise<void> | null = null
104
105// one refresh at a time; a call while one runs joins it
106function refresh($: EngineInterface): Promise<void> {
107 running ??= collect($)
108 .then(next => update($, snapshot, () => next))
109 .then(
110 () => undefined,
111 error => $.ui.log(`odoo-env-band: ${String(error)}`, { to: 'debug' }),
112 )
113 .finally(() => {
114 running = null
115 })
116 return running
117}
118
119async function where($: EngineInterface): Promise<Where> {
120 return { project: await projectDir($), cwd: await $.session.cwd(), addons: ADDONS }
121}
122
123// Recomputed from the transcripts, the main thread's and each subagent's, on every load: what this
124// session works in is a fact of its tool calls, so a value an earlier version of these rules kept is
125// replaced, never merged in.
126async function rescan($: EngineInterface): Promise<void> {
127 const at = await where($)
128 const uses = (await $.session.messages()).flatMap(message => message.toolUses)
129 for (const agent of await $.agent.list()) {
130 const found = await $.session.messages({ agentId: agent.id })
131 if (Array.isArray(found)) uses.push(...found.flatMap(message => message.toolUses))
132 }
133 const found = uses
134 .filter(use => use.isError !== true)
135 .reduce<Touched>((all, use) => mergeTouched(all, touchedBy(String(use.tool), use.input, at)), {
136 env: false,
137 addons: false,
138 wts: [],
139 })
140 await update($, touched, () => found)
141}
142
143export const register: Register = on => {
144 on('session.start', async ($, e, next) => {
145 const started = await next(e)
146 await rescan($)
147 void refresh($)
148 $.clock.every(REFRESH_MS, () => void refresh($))
149 return started
150 })
151
152 // a checkout this session starts working in shows at once; so does a git command or a service restart
153 on('tool.call', async ($, e, next) => {
154 const ran = await next(e)
155 if (ran.deny !== undefined || ran.isError === true) return ran
156 const tool = String(e.tool)
157 const found = touchedBy(tool, e as unknown as Record<string, unknown>, await where($))
158 const before = await read($, touched)
159 const after = mergeTouched(before, found)
160 if (!isSameTouched(before, after)) await update($, touched, () => after)
161 if (tool === 'Bash' || !isSameTouched(before, after)) void refresh($)
162 return ran
163 })
164
165 on('turn.complete', async ($, e, next) => {
166 void refresh($)
167 return next(e)
168 })
169
170 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
171 const below = await next(e)
172 const env = await read($, snapshot)
173 if (env === null || e.props.hasSurvey) return below
174
175 const { Box, Button, Link, Text } = $.ui.resolve(e)
176 const mine = env.wts.filter(wt => wt.isMine)
177 const others = env.wts.filter(wt => !wt.isMine)
178
179 const gitState = (git: GitStatus | null, defaults: readonly string[], isWorktree: boolean) =>
180 git === null ? (
181 <Text color="red">no git</Text>
182 ) : (
183 <Box flexDirection="row" columnGap={1}>
184 <Text bold color={defaults.includes(git.branch) ? undefined : 'cyan'}>
185 {git.hasUpstream || defaults.includes(git.branch) || isWorktree
186 ? git.branch
187 : `${git.branch} (local)`}
188 </Text>
189 {git.dirty > 0 ? (
190 <Text color="yellow">{`±${git.dirty} changed`}</Text>
191 ) : (
192 <Text color="green">✓ clean</Text>
193 )}
194 {git.ahead > 0 && <Text dimColor>{`↑${git.ahead} ahead`}</Text>}
195 {git.behind > 0 && <Text color="yellow">{`↓${git.behind} behind`}</Text>}
196 </Box>
197 )
198
199 // the postgres cluster first, then one group per checkout (a worktree's port and state right after its
200 // label, its address last), then the other envs
201 const groups: JSX.Element[] = [
202 <Box flexDirection="row" columnGap={1}>
203 {env.services.map(service => (
204 <Text color={service.isActive ? 'green' : 'red'}>
205 {`${service.name} :${service.port} ${service.isActive ? '●' : '○'}`}
206 </Text>
207 ))}
208 </Box>,
209 ...(env.env === null
210 ? []
211 : [
212 <Box flexDirection="row" columnGap={1}>
213 <Text dimColor>env</Text>
214 {gitState(env.env.git, ENV_BRANCHES, false)}
215 </Box>,
216 ]),
217 ...(env.addons === null
218 ? []
219 : [
220 <Box flexDirection="row" columnGap={1}>
221 <Text dimColor>addons</Text>
222 {gitState(env.addons.git, [ADDONS_BRANCH], false)}
223 </Box>,
224 ]),
225 ...mine.map(wt => (
226 <Box flexDirection="row" columnGap={1}>
227 <Text dimColor>wt</Text>
228 <Text color={wt.isActive ? 'green' : undefined} dimColor={!wt.isActive}>
229 {`:${wt.port} ${wt.isActive ? '● up' : '○ down'}`}
230 </Text>
231 {gitState(wt.git, [ADDONS_BRANCH], true)}
232 {/* the session is served by its database's subdomain (dbfilter ^%d$); a remote surface draws only an
233 https: Link as a link, so there the address is a button that opens the browser */}
234 {e.surface === 'terminal' ? (
235 <Link href={webUrl(wt)} label={address(wt)} />
236 ) : (
237 <Button key={`wt-open-${wt.slug}`} label={address(wt)} plain dimColor onPress={() => openUrl($, webUrl(wt))} />
238 )}
239 </Box>
240 )),
241 ...(others.length === 0
242 ? []
243 : [
244 <Text dimColor>{`${others.length} other wt env${others.length === 1 ? '' : 's'}`}</Text>,
245 ]),
246 ]
247
248 const row = (
249 <Box key="odoo-env" flexDirection="row" columnGap={1} flexWrap="wrap">
250 {groups.map((group, i) => (
251 <Box flexDirection="row" columnGap={1}>
252 {group}
253 {i < groups.length - 1 && <Text dimColor>│</Text>}
254 </Box>
255 ))}
256 </Box>
257 )
258 return (
259 <Box flexDirection="column" rowGap="sm">
260 {below}
261 {row}
262 </Box>
263 )
264 })
265}
266hooks/env.ts 110 lines1import type { GitStatus, Touched } from '../types'
2
3// `git status --porcelain=v2 --branch`: header lines start with '#', every other line is one changed path
4export function parseGitStatus(out: string): GitStatus {
5 let branch = '?'
6 let oid = ''
7 let ahead = 0
8 let behind = 0
9 let hasUpstream = false
10 let dirty = 0
11 for (const line of out.split('\n')) {
12 if (line.startsWith('# branch.head ')) branch = line.slice('# branch.head '.length).trim()
13 else if (line.startsWith('# branch.oid ')) oid = line.slice('# branch.oid '.length).trim()
14 else if (line.startsWith('# branch.upstream ')) hasUpstream = true
15 else if (line.startsWith('# branch.ab ')) {
16 const ab = /\+(\d+) -(\d+)/.exec(line)
17 if (ab) {
18 ahead = Number(ab[1])
19 behind = Number(ab[2])
20 }
21 } else if (line !== '' && !line.startsWith('#')) dirty += 1
22 }
23 if (branch === '(detached)') branch = oid.slice(0, 8) || 'detached'
24 return { branch, dirty, ahead, behind, hasUpstream }
25}
26
27// the worktree env slug when cwd is inside <project>/.worktrees/<slug>/, or in that env's
28// env-repo worktree <project>/.worktrees/_envrepo/<slug>/
29export function worktreeSlug(cwd: string, project: string): string | null {
30 const root = `${project.replace(/\/+$/, '')}/.worktrees/`
31 if (!`${cwd}/`.startsWith(root)) return null
32 const parts = `${cwd}/`.slice(root.length).split('/')
33 const slug = (parts[0] === '_envrepo' ? parts[1] : parts[0]) ?? ''
34 return slug !== '' && slug !== '_env' && slug !== '_envrepo' ? slug : null
35}
36
37// `systemctl --user is-active a b c` prints one state per unit, in argument order
38export function parseActive(out: string, units: readonly string[]): Record<string, boolean> {
39 const states = out.split('\n').map(line => line.trim())
40 return Object.fromEntries(units.map((unit, i) => [unit, states[i] === 'active']))
41}
42
43// an env's database when its env dir records none (restored before wt-start recorded it): wt_<slug>
44export function wtDb(slug: string): string {
45 return `wt_${slug.replace(/-/g, '_')}`
46}
47
48const FILE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit'])
49const WT_PATH = /\.worktrees\/([A-Za-z0-9][A-Za-z0-9._-]*)/g
50const WT_SCRIPT = /\bwt-(?:start|stop|bootstrap|restore|link)\.sh\s+([A-Za-z0-9][A-Za-z0-9._-]*)/g
51// git that changes a checkout, with the -C options before the verb; status, log, diff and worktree list only look
52const GIT_WRITE = /\bgit\b((?:\s+-[Cc]\s+\S+)*)\s+(?:commit|checkout|switch|pull|push|merge|rebase|reset|stash|cherry-pick|revert|am|apply|add|rm|mv|restore)\b/g
53
54export type Where = { project: string; cwd: string; addons: string }
55
56const NONE: Touched = { env: false, addons: false, wts: [] }
57
58function slugsIn(text: string): string[] {
59 return [...text.matchAll(WT_PATH), ...text.matchAll(WT_SCRIPT)]
60 .map(match => match[1] ?? '')
61 .filter(slug => slug !== '' && slug !== '_env')
62}
63
64// an absolute path: the env repo (anything under the project but src/ and .worktrees/), addons, a worktree
65function classify(path: string, where: Where): Touched {
66 const project = `${where.project.replace(/\/+$/, '')}/`
67 const target = `${path.replace(/\/+$/, '')}/`
68 if (!target.startsWith(project)) return NONE
69 const wts = slugsIn(target)
70 if (wts.length > 0) return { env: false, addons: false, wts }
71 if (target.startsWith(`${project}${where.addons}/`)) return { env: false, addons: true, wts: [] }
72 if (target.startsWith(`${project}src/`) || target.startsWith(`${project}.worktrees/`)) return NONE
73 return { env: true, addons: false, wts: [] }
74}
75
76// a `git -C` argument as written: quotes off, $ODOO16_PROJECT_DIR and relative paths resolved
77function resolvePath(raw: string, where: Where): string {
78 const bare = raw.replace(/^["']|["']$/g, '').replace(/^\$\{?ODOO16_PROJECT_DIR\}?/, where.project)
79 return bare.startsWith('/') ? bare : `${where.cwd.replace(/\/+$/, '')}/${bare}`
80}
81
82// Which checkouts one tool call works in. An edit counts, a Bash command that names a worktree or runs a
83// wt-*.sh script on it counts, and so does a changing git command, in its -C directory or the session's
84// cwd. A read, a grep or a `git status` does not.
85export function touchedBy(tool: string, input: Record<string, unknown>, where: Where): Touched {
86 if (FILE_TOOLS.has(tool)) {
87 const path = typeof input.file_path === 'string' ? input.file_path : input.notebook_path
88 return typeof path === 'string' ? classify(path, where) : NONE
89 }
90 if (tool !== 'Bash' || typeof input.command !== 'string') return NONE
91 let found: Touched = { env: false, addons: false, wts: slugsIn(input.command) }
92 for (const match of input.command.matchAll(GIT_WRITE)) {
93 const dir = /-C\s+(\S+)/.exec(match[1] ?? '')?.[1]
94 found = mergeTouched(found, classify(dir === undefined ? where.cwd : resolvePath(dir, where), where))
95 }
96 return found
97}
98
99export function mergeTouched(a: Touched, b: Touched): Touched {
100 return {
101 env: a.env || b.env,
102 addons: a.addons || b.addons,
103 wts: [...a.wts, ...b.wts.filter(slug => !a.wts.includes(slug))],
104 }
105}
106
107export function isSameTouched(a: Touched, b: Touched): boolean {
108 return a.env === b.env && a.addons === b.addons && a.wts.length === b.wts.length && a.wts.every(slug => b.wts.includes(slug))
109}
110types/index.d.ts 37 lines1export type GitStatus = {
2 branch: string
3 dirty: number
4 ahead: number
5 behind: number
6 hasUpstream: boolean
7}
8
9// the checkouts this session works in: by its cwd, its edits and its git / wt-*.sh commands
10export type Touched = { env: boolean; addons: boolean; wts: string[] }
11
12export type Service = { name: string; port: string; isActive: boolean }
13
14export type WtEnv = {
15 slug: string
16 port: string
17 db: string
18 isActive: boolean
19 // this session works in it; only these are drawn, the rest are a count
20 isMine: boolean
21 git: GitStatus | null
22}
23
24export type EnvSnapshot = {
25 // the env repo (the project itself) and the main addons checkout, when this session works in them
26 env: { git: GitStatus | null } | null
27 addons: { git: GitStatus | null } | null
28 services: Service[]
29 wts: WtEnv[]
30}
31
32declare module 'claude-code' {
33 interface PluginState {
34 'odoo-env-band': { snapshot: EnvSnapshot | null; touched: Touched }
35 }
36}
37