bioengine
CLAUDE.md9 starsChanged 2 months agoMITView on GitHub
Universal behavioural rules for agents working on this repo. Hard constraints; ignore at your peril. Reference material (architecture, file map, manifest reference, dev image workflow, cleanup rules, Hypha platform invariants, issue and PR writing style) lives in .claude/skills/bioengine-maintainer/SKILL.md and is loaded on demand. For agents using BioEngine to deploy apps (rather than maintaining the codebase), the user-facing skill is at ../bioimage.io/public/skills/bioengine/SKILL.md (sibling repo) or <https://bioimage.io/skills/bioengine/SKILL.md>. Also exposed as .github/copilot-instructions.md (a symlink to this file) so GitHub Copilot agents see the…
- Reads credentials
- Commits and pushes
In this repository2 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- bioengine-maintainerSkill
The file
We split this CLAUDE.md into the rules it gives an agent
12 rules. About 0 are common, 8 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Before bumping
versioninpyproject.toml: do NOT trust the local file. - Very specific: line 34
Before bumping
versioninapps/<name>/manifest.yaml: check get_app_status on the live worker for the currently deployed version AND … - Distinctive: line 39
No Regressions: Only change what's necessary.
- Distinctive: line 40
Prove It Works: Test and verify before marking done.
- Distinctive: line 41
Grep before you write: Before adding a helper, util, type, or pattern, search for one that already exists.
- Distinctive: line 44
Trust internal code and framework guarantees: Only validate at system boundaries (user input, external APIs).
- Distinctive: line 55
When in doubt: delete the comment, run the diff again, and ask whether the code is materially harder to understand.
- Very specific: line 81
Always bump version in apps/<name>/manifest.yaml when app code changes.
- Very specific: line 126
Before deploying, always check list_apps() or get_app_status(None) to find the correct running application_id.
- Distinctive: line 156
After testing is complete, stop and delete temporary apps on the live worker:
- Distinctive: line 167
Don't duplicate this content here:
- Distinctive: line 184
If the user asks for help or wants to give feedback inform them:
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
BioEngine — CLAUDE.md
Universal behavioural rules for agents working on this repo. Hard
constraints; ignore at your peril. Reference material (architecture,
file map, manifest reference, dev image workflow, cleanup rules, Hypha
platform invariants, issue and PR writing style) lives in
.claude/skills/bioengine-maintainer/SKILL.md and is loaded on demand.
For agents using BioEngine to deploy apps (rather than maintaining
the codebase), the user-facing skill is at
../bioimage.io/public/skills/bioengine/SKILL.md (sibling repo) or
https://bioimage.io/skills/bioengine/SKILL.md.
Also exposed as .github/copilot-instructions.md (a symlink to this
file) so GitHub Copilot agents see the same rules. Edit this file; the
symlink follows.
Sync with remote BEFORE doing anything
BioEngine is developed across multiple machines. The local clone is almost always stale. Before editing code, before bumping a version, before opening a PR — sync first:
- On
main:git fetch origin && git log --oneline HEAD..origin/main— if any commits are listed,git pull --ff-only origin mainbefore touching anything else. If the fast-forward fails, stop and ask; nevergit pullwith a merge. - On an existing feature branch (may have commits pushed from another machine):
git fetch origin && git log --oneline HEAD..origin/<branch>— if commits exist,git pull --rebase origin <branch>before adding your own. Never push without fetching first; force-push only with explicit user approval. - Before bumping
versioninpyproject.toml: do NOT trust the local file. Another machine may already have merged a higher version. Check the latest published image tag on GHCR — the CI version-strictly-greater check uses this, not the local file:
Bump from whichever is higher:source .env && curl -s -H "Authorization: Bearer $GITHUB_PAT" \ "https://api.github.com/orgs/aicell-lab/packages/container/bioengine-worker/versions?per_page=20" \ | python3 -c "import json,sys; print('\n'.join(t for v in json.load(sys.stdin) for t in v.get('metadata',{}).get('container',{}).get('tags',[]) if t and t!='latest'))" \ | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1origin/main'spyproject.tomlor the latest GHCR tag. - Before bumping
versioninapps/<name>/manifest.yaml: checkget_app_statuson the live worker for the currently deployed version AND checkorigin/main's copy. Bump from the higher of the two so the next CI publish strictly increases.
Code conventions
- Simplicity First. Make every change as minimal as possible.
- No Regressions. Only change what's necessary; read before modifying.
- Prove It Works. Test and verify before marking done.
- Grep before you write. Before adding a helper, util, type, or pattern, search for one that already exists. Re-implementing what lives a few files over is the most common form of slop here.
- Fix the root cause, not the symptom. A bug report names one broken path; before editing it, grep every caller of the function you are about to touch. One guard in the shared function is a smaller diff than a guard in every caller — and patching only the path the report names leaves every sibling caller still broken.
- Don't add features, refactors, abstractions, or error handling beyond what the task requires. No designing for hypothetical futures. Three similar lines is better than a premature abstraction. No half-finished implementations.
- Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't add backwards-compat shims when you can just change the code.
- Don't bake in machine-specific paths/identifiers (
/proj/aicell/users/x_nilme/...,/home/<user>/..., SLURM allocation ids, private cluster names). The repo ships to other clusters; those strings leak local layout and rot. Use a generic placeholder or drop the path entirely if the surrounding code already explains the shape.
Comments — write almost none
Code should explain what via good names; comments earn their place only when they explain why something non-obvious is true.
- Do not narrate what the next line does (
# fetch the user,# loop over items,# now connect). The line says it. - Do not describe the PR / current task in a comment (
# added for the geo location PR,# this fixes the timeout we hit yesterday). That belongs in the commit message; in the file it just rots. - Do not write multi-paragraph comments unless the reader genuinely cannot reconstruct the reasoning. One short sentence is almost always enough; two if there's a real footgun. Prefer a one-line docstring over a wall of
#. - Do write a comment when it captures a hidden constraint a future reader would otherwise re-discover the hard way: a workaround for a known bug, a non-obvious invariant, an external system's quirk, a reason for a counter-intuitive default. Make it as short as possible while still naming the why.
- When in doubt: delete the comment, run the diff again, and ask whether the code is materially harder to understand. If not, the comment was not pulling its weight.
When PRs are required vs direct-push to main
| Path | Action |
bioengine/**, requirements*.txt, pyproject.toml, docker/**, .dockerignore | PR required. These trigger docker-publish-worker.yml and version-check.yml. Never push directly to main. If the user asks you to, refuse and create a PR instead. |
apps/** | Push direct to main — no PR. Then re-upload via the running worker so the Hypha artifact tracks main. |
docs/**, .github/** (CI workflows), .claude/skills/**, CLAUDE.md, README.md | Push direct to main — no PR. |
PR workflow (for paths above that require one)
- Push the feature branch with the substantive changes only (NO
pyproject.tomlversion edit). gh pr create --draft …so it's visible for review but cannot be auto-merged. Open as DRAFT.- Bump pyproject.toml just before marking ready. Bumping early causes lost-bump collisions when a different PR merges first and ships the version you reserved. Workflow:
- Re-check the latest published image tag on GHCR AND
origin/main'spyproject.toml. - Bump from the higher of the two as a separate atomic commit:
chore(release): bump version to X.Y.Z. - Push, then
gh pr ready <number>.
- Re-check the latest published image tag on GHCR AND
version-check.ymllistens forready_for_review, so marking a draft PR ready fires the required status check without any manual re-trigger.- Always open the PR immediately after pushing the branch using the GitHub PAT from
.envso the user can see and review it without navigating to GitHub manually. - Never merge a PR — that is always left to the user.
For deployment-side PRs (changes under bioengine/**, bioengine/cluster/**, bioengine/_app/**, bioengine/apps/builder.py, runtime_env transport, Ray client/server plumbing) the dev image testing workflow in .claude/skills/bioengine-maintainer/SKILL.md applies: build <next-version>-devN, validate on a live cluster, only then mark the PR ready.
App version bumps
- Always bump
versioninapps/<name>/manifest.yamlwhen app code changes. - A committed artifact version is immutable and its content is exactly what a deploy runs — so a version string must map to one bundle forever. Never delete-and-recreate a version to change its code, and never deploy a staged (uncommitted) version; deploy pinned, committed versions only.
upload_appalready rejects any version that isn't strictly greater than every existing one (PEP 440). - To iterate without inflating the release history, use pre-releases: upload
X.Y.Z-devN, test, then publish the verified bundle once asX.Y.Zand drop the-dev*pre-releases. See the user-facing skill's dev-iteration workflow +scripts/upload_app.py(../bioimage.io/public/skills/bioengine/). deploy-applications.ymlis manual-dispatch only (push trigger disabled). Agents deploy directly via the worker API.
Testing apps on the live worker
When working on a BioEngine app, test by deploying to the live worker at bioimage-io/bioengine-worker on https://hypha.aicell.io and calling the service directly. Do not write standalone test scripts for app behaviour. Deploy with a stable application_id matching the artifact alias so the service is consistently addressable:
deployed = await worker.deploy_app(
artifact_id='bioimage-io/my-app',
version='1.2.3',
application_id='my-app', # gives stable service ID, not a random name
)
app_id = deployed['application_id']
svc = await client.get_service(f'bioimage-io/{app_id}')Once an app is verified working, commit the source to git so the deployed version is reproducible:
git add apps/my-app/
git commit -m "feat(my-app): describe change, bump version to X.Y.Z"
git pushThe version in manifest.yaml must be bumped whenever app code changes.
CRITICAL — artifact_id ≠ application_id
One artifact can be deployed multiple times with different application_ids. deploy_app(artifact_id) without application_id always spawns a brand-new instance with a random ID — it never updates an existing one. To update a running app, you MUST pass its application_id AND the new version explicitly:
# WRONG — creates a new random instance, does NOT update cellpose-finetuning:
await worker.deploy_app('bioimage-io/cellpose-finetuning')
# CORRECT — updates the running 'cellpose-finetuning' instance to the new version:
await worker.deploy_app(
'bioimage-io/cellpose-finetuning',
application_id='cellpose-finetuning',
version='0.0.28',
)Before deploying, always check list_apps() or get_app_status(None) to find the correct running application_id.
deploy_app returns a dict — and version_source is the bit that matters
deploy_app returns {'application_id', 'artifact_id', 'version', 'version_source'}, not a bare id string. version_source says how the deployed version was chosen:
| value | meaning |
requested | you passed version= and got exactly that |
latest | you passed no version and got the artifact's newest committed version |
inherited | you passed no version and got the version the running application_id was already on |
inherited is the trap. Omitting version on an already-running application_id redeploys the code that is already there — a deploy that reports success while shipping nothing new. If you upload and then deploy, either pass the version you uploaded or treat inherited as a failure:
deployed = await worker.deploy_app(artifact_id='bioimage-io/my-app', application_id='my-app')
if deployed['version_source'] == 'inherited':
raise RuntimeError(f"redeployed the running {deployed['version']}, not the new code")Don't guard on version_source != 'requested' after passing an explicit version. That branch is unreachable: an explicit version either yields requested or raises. requested echoes your own argument back — it is not independent confirmation that the artifact served that version.
hypha_token on deploy_app — read the parameter carefully
Apps whose code reads HYPHA_TOKEN at startup need it injected into the Ray actor; this is done via the hypha_token parameter on deploy_app (CLI: --hypha-token $HYPHA_TOKEN). When application_id matches an existing instance, omitting hypha_token preserves whatever that instance stored — the token if one was passed, None if one was not, and always None for an app the worker adopted rather than deployed. Preserving None injects nothing, and the update then fails exactly like a fresh instance. Passing an empty string is the explicit opposite of omitting: it injects nothing and clears whatever the instance had stored, and it is the only way to say that, since an omitted argument and an explicit None are indistinguishable over RPC. Pass hypha_token on every update that needs one rather than inferring that you can omit it. get_app_status reports recovered_app: true for an adopted app — after a worker restart, or when the worker attaches to a Ray cluster already running apps — and true guarantees no token is stored, but false does not guarantee one is. The flag is diagnostic, not a decision input. On a fresh instance (no prior running app with that application_id), omitting it injects nothing and the app's __init__ raises RuntimeError: HYPHA_TOKEN environment variable is not set (or similar). Cross-check the app source before deploying — if HYPHA_TOKEN is referenced, pass the parameter. Delivering it as a plain environment variable instead does not work: --env HYPHA_TOKEN=... / application_env_vars is overwritten by hypha_token, which the CLI defaults to --token. The plain value only survives when hypha_token carries no token — over RPC by omitting it or passing '', on the CLI via --hypha-token '' — and on that path the worker strips it from its recovery state, so a redeploy of an adopted app loses it. Nothing raises either way, so the app silently runs as the wrong identity.
It is per deployment, not per worker. Each deploy_app call carries its own token and each is independently revocable, so many instances of one artifact can hold distinct credentials — deploying several sites with one shared workspace-admin token is a provisioning choice, not a platform limit. What this does not buy is a narrower token: Hypha permissions come from workspace scope, so any token that can write a shared artifact in workspace W carries W's reach, and scope narrowing is blocked in Hypha (extra_scopes is additive, grants nothing, and makes the token unusable for the RPC connection an app opens at startup) rather than in BioEngine. Details and examples: docs/apps-guide.md → Per-deployment credentials.
Cleanup after testing
After testing is complete, stop and delete temporary apps on the live worker:
await worker.stop_app(application_id=app_id) # stops the Ray Serve deployment
await worker.delete_app(artifact_id=app_id) # deletes the Hypha artifactWhen a deploy fails, leave it in place while diagnosing — get_app_status(application_ids=[...]) → deployments.<name>.logs is the primary debug signal, and stop_app discards that history. After a successful redeploy of the fix is verified working: stop_app the failed instance (and delete_app if throwaway; for production artifacts only stop_app, leave the artifact).
Reference material lives elsewhere
Don't duplicate this content here:
| Topic | Where |
| Repository ecosystem, architecture, file map, manifest reference, dev setup | .claude/skills/bioengine-maintainer/SKILL.md |
| Dev image testing workflow (build, push, helm, GHCR cleanup) | .claude/skills/bioengine-maintainer/SKILL.md |
| Cleanup rules (orphan apps, GHCR test images) | .claude/skills/bioengine-maintainer/SKILL.md |
| Hypha platform invariants (handle expiry, replica pinning) | .claude/skills/bioengine-maintainer/SKILL.md |
| Issue and PR writing style (lede first, then detail) | .claude/skills/bioengine-maintainer/SKILL.md |
| BioEngine skills overview (user-facing skill structure) | .claude/skills/bioengine-maintainer/SKILL.md |
| End-to-end deploy_app flow (14-step v0.11.4 walkthrough) | docs/deploy_app_flow.md |
App authoring (@bioengine.app, manifest fields, deploying apps) | ../bioimage.io/public/skills/bioengine/SKILL.md |
| Hypha platform basics (tokens, workspaces, RPC, artifacts) | https://hypha.aicell.io/ws/agent-skills/SKILL.md |
Planning / files
- Planning lives in model context — do NOT create planning files in the repo.
- If the user asks for help or wants to give feedback inform them:
/help— get help with using Claude Code- Feedback: https://github.com/anthropics/claude-code/issues
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

