Skip to content

Latest commit

 

History

History
73 lines (44 loc) · 11 KB

CLAUDE.md

File metadata and controls

73 lines (44 loc) · 11 KB

CLAUDE.md

Project

Claude Code Hub — a unified launcher that combines multiple Claude Code tools (Marketplace + Kanban + Cost + Memory Diagnoser) into a single chromeless PWA via iframes and git submodules.

Commands

npm start                # Start hub + all sub-apps (http://localhost:3540)
npm run dev              # Start with auto-open browser
npm run lint             # Biome over public/app.js, server.js and packages/claude-hub-sdk, plus the escaping and security-lib checks
npm run test:e2e         # Hub keys in Chrome (needs Chrome); by hand only, not in npm test, the hook or CI

test/fixtures/key-matrix.json is the list of key presses and what each one must do. npm test runs it against the hub page and the SDK; npm run test:e2e presses it in Chrome against a scratch hub with fixture apps. A row with todo is a known bug. Add a row with each key change.

The hub is usually already running on :3540. Check it with curl -s -o /dev/null -w '%{http_code}' http://localhost:3540/api/config (401 without the token still means it is up; add ?token=$(cat ~/.claude-hub/token) to read it). Use it only for read-only checks. To test a fix, start a second hub on other ports (--port, --marketplace-port, --kanban-port, --cost-port, --memory-port) so the running one is not disturbed. Start it with CCK_TERMINALS_FILE=<scratch path>: its cck shares the config dir and would otherwise rewrite the real board's terminals.json. Also set CLAUDE_HUB_NO_ONBOARDING=1 and CLAUDE_HUB_NO_UPDATE_CHECK=1, so no welcome dialog or update toast covers the page under test.

CLI flags: --port <n>, --<id>-port <n> (kanban, marketplace, cost, memory), --hub-dir <path>, --pool-size <n> (else poolSize in config.json, else 3), --no-mods (or modsEnabled: false), --open, --detached (do not stop when stdin closes), --install/--uninstall (with --dir <config dir>), --tray/--autostart/--no-autostart/--tray-status and --app-id <id> (Windows and macOS), -v/--version and -h/--help. lib/cli.js holds FLAGS and HELP and runs before anything else in server.js: an unknown flag or word fails with the help, so it never reaches the running-hub check, which prints the URL with the token. A new flag goes in FLAGS, HELP and reference/configuration.md; test/cli.test.js checks they agree.

Hub dir. --hub-dir, else CLAUDE_HUB_DIR, else ~/.claude-hub. It holds config.json, token and hub.json; one hub runs per hub dir. A test hub can use its own dir instead of overriding USERPROFILE.

App ports. Each config dir has its own set of public app ports (proxySets in server.js), and the proxy sends a request to the pool of the dir that owns the port, never to the active pool. The port is the app's origin, so each dir has its own localStorage. The legacy dir (legacyConfigDir in config.json: ~/.claude when listed, else the first dir) uses the base ports: --<id>-port, else port in the app's apps entry, else the manifest's run.defaultPort. Every other dir gets a block from the hub port + 10 (lib/dir-ports.js), saved in dirPorts. Sets open at startup and on add, and close on remove. A busy port falls back to a random one for that run and is not saved, so the app has empty localStorage for that run. The proxies listen through their own net guard: the guard keeps one actualPort for its Origin check, and that must stay the hub port.

Topic docs

Read the doc before you change its area:

  • Tray, --tray/--autostart, or hub.json and the one-hub-per-dir check: docs/agents/tray.md
  • Install, plugin/, ext (extensions, dock add-ons, features): docs/agents/extensions.md
  • Hub client UI, the app launcher, settings, or a hub shortcut and the user keymap: docs/agents/hub-client.md
  • SDK (packages/claude-hub-sdk), a sub-app's HUB_INTEGRATION region, or the postMessage protocol: docs/agents/sdk.md
  • Voice (lib/voice/, voice in config.json): docs/agents/voice.md
  • Liveness: proxy retries, IPC ping, slow ports, stopping an app: docs/agents/liveness.md
  • Website (website/, screenshots, Git LFS): docs/agents/website.md

Performance

Every feature, in the hub or a sub-app, states its performance impact before you build it: what work it adds, where that work runs (startup, a hot path such as a render, a poll, the session list or a keystroke, or only on demand), and how often. If the change can cause a delay the user notices, push back and propose a cheaper design before you write it. Report the impact with the change.

Architecture

Apps. lib/apps.js lists the four built-in apps (id, submodule dir, npm package) in default tab order; nothing else in server.js names them all. Name, icon, entry, default port, loading verbs, actions and capabilities come from the app's hub-app.json (in the submodule, else the npm package). An app whose manifest is missing or fails validation is logged and skipped. test/apps.test.js validates each app's manifest, so the release run checks the pinned packages.

Capabilities. provides.projects.path and provides.terminal.liveWork name the provider of the project list and the embedded terminal; the first enabled app in tab order that declares one wins (today Kanban). The terminal env, the terminal token, pool pinning and /api/projects go to that app. When two enabled apps declare the same capability, action or port, the hub logs it at startup; the first in tab order wins. With no enabled provider, the terminal is off and /api/projects answers 503 at once.

apps in config.json. The hand-edited list in ~/.claude-hub/config.json ([{id, enabled, port, path, hidden, deferredStart}]) reorders the apps and turns them off: a disabled app is not spawned and gets no proxy port or tab. hidden: true keeps the app running and in the app launcher but gives it no tab key and no place in the Ctrl+Alt+Left/Right cycle; its frame loads only when the launcher or an action opens it. deferredStart: true does not spawn the app with its pool, and the hub page does not load its frame until its tab opens; its first page load (its tab, a pane, an action) starts it (startOnDemand), as does the launcher's Start. One the user stopped stays stopped. path (relative to the hub dir) runs the app from that folder: a fork in place of a built-in id, or a new app under a new id; its hub-app.json id must match.

Hub server (server.js) spawns four child processes — marketplace, kanban, cost, and memory — passing CLAUDE_HUB=1, HUB_URL, CLAUDE_HUB_DIR (cck's terminal strips HUB_URL and CLAUDE_HUB from sessions but keeps this, so a session finds hub.json and token), CLAUDE_CONFIG_DIR, HUB_SDK_SERVER (the path of the hub's packages/claude-hub-sdk/src/server.js) and HUB_APP_SETTINGS (the app's saved settings as JSON, for an app that has settings) env vars, over an IPC channel. It parses their stdout to detect actual ports (handles fallback when default ports are busy) and exposes GET /api/config returning the live app URLs.

Config dirs. The hub keeps a list of Claude config dirs and the active one in ~/.claude-hub/config.json (GET/POST/DELETE /api/config-dirs, POST /api/config-dirs/activate). Every sub-app resolves CLAUDE_CONFIG_DIR once at startup, so each dir gets its own set of four children. Sets stay alive after a switch (LRU pool, --pool-size, default 3) so switching back is instant; the activate response carries that set's app URLs (fallback ports when the defaults are taken) and the client reloads every iframe. Removing a dir kills its set.

Each hub window has its own dir. The page keeps it and its previous dir in sessionStorage, so a reload and a hub restart bring the window back on it, and sends both URI-encoded in X-Hub-Config-Dir and X-Hub-Previous-Config-Dir on every /api call (hubFetch; a new page call must use it). The windowDirs middleware sets req.dir and req.previous: no header means the global activeConfigDir, which is only the dir a new window opens on (the last one activated anywhere). A header that names a dir no longer listed gets 409 {code: 'unknown_config_dir'} and the page reloads; GET /api/config instead answers the global dir with dirFallback: true, and the page shows a toast. With a header, GET /api/config starts that dir's set if it has none, and waits only for its proxy ports; without one it never spawns, so a second start's running-hub check stays fast. Each window opens /api/events?dir=: a dir with an open window is pinned against eviction like one with live terminals, so --pool-size is a soft limit, and removing a dir sends dir-removed to its windows. A window cannot remove its own dir. POST /api/config-dirs/swap goes to the window's previous dir, else previousConfigDir, else the other of exactly two dirs, else 409, and the client opens the palette. configDirSwitch in config.json (palette, default, or swap) picks what hub.configDirPicker runs. cck's plugin (hooks and context mod) is installed per dir, so a dir without it shows tasks and sessions but no live agent activity.

Hub token. The hub page (/, /index.html) and every /api/* route require the token in ~/.claude-hub/token (created on first run, mode 600, kept across restarts). Loopback is not a user boundary, and /api/config carries cck's terminal token. The banner and --open use /?token=…; the hub answers with an HttpOnly, SameSite=Strict hub_token cookie and a redirect that drops the query. Without the token the page answers 401 with public/locked.html. Scripts, icons and the manifest stay public, because Chrome fetches the manifest without cookies. Delete the file to rotate the token.

Hub client (public/app.js) creates one iframe per app and switches tabs with keys only (Ctrl+Alt+Left/Right, Alt+1…). Apps talk to the hub through the SDK's ClaudeHub over postMessage; the hub validates each message's origin.

Update check. lib/update-check.js asks npm for claude-code-hub@latest on start. GET /api/update waits for a check in flight and answers {version, update}; the page shows a toast for it on load. The check is off in a git checkout and with CLAUDE_HUB_NO_UPDATE_CHECK, so a dev hub never shows it.

Git Submodules

After cloning: git submodule update --init then npm install in root, marketplace/, cck/, cost/, and memory/.

Submodules are often on a detached HEAD. Before you change one, run git -C <submodule> checkout main, so a commit does not land on a detached HEAD and get lost.

Each sub-app has its own linter (Biome) and pre-commit hooks; the hub root has npm run lint and husky pre-commit hooks.