+ {claude.available
+ ? `Available: ${claude.version}`
+ : "Claude is unavailable on PATH or did not respond."}
+
+
+ {claude.loginAppearsPresent
+ ? "Credentials file exists; login may be available."
+ : "No credentials file found."}
+
+ >
+ ) : (
+
Checking CLI...
+ )}
+
+
+ Run claude, then /login. Credentials are
+ checked for existence only.
+
+
+
+
About/System
+ {info && (
+
+
ShellBook version
+
{info.version}
+
Workspace
+
{info.workspacePath}
+
Data directory
+
{info.dataDirPath}
+
Node version
+
{info.nodeVersion}
+
+ )}
+
+ {message &&
{message}
}
+
+ );
+}
diff --git a/apps/web/src/SetupScreen.tsx b/apps/web/src/SetupScreen.tsx
new file mode 100644
index 0000000..80dd6ed
--- /dev/null
+++ b/apps/web/src/SetupScreen.tsx
@@ -0,0 +1,20 @@
+import { PasswordForm } from "./PasswordForm";
+import { settingsApi } from "./settingsApi";
+export function SetupScreen({ onComplete }: { onComplete: () => void }) {
+ return (
+
+
Set up ShellBook
+
+ Enter the one-time token from the setup-token file in the server data
+ directory.
+
+ {
+ await settingsApi.setup(body);
+ onComplete();
+ }}
+ />
+
+ );
+}
diff --git a/apps/web/src/settingsApi.ts b/apps/web/src/settingsApi.ts
new file mode 100644
index 0000000..a0caff0
--- /dev/null
+++ b/apps/web/src/settingsApi.ts
@@ -0,0 +1,31 @@
+import type {
+ SetupStatusResponse,
+ SetupRequest,
+ ChangePasswordRequest,
+ SessionSettingsResponse,
+ ClaudeStatusResponse,
+ SystemInfoResponse,
+} from "@shellbook/core";
+import { HttpError } from "./api";
+async function request(path: string, body?: unknown): Promise {
+ const response = await fetch(`/api${path}`, {
+ method: body === undefined ? "GET" : "POST",
+ credentials: "same-origin",
+ headers: body === undefined ? {} : { "Content-Type": "application/json" },
+ body: body === undefined ? undefined : JSON.stringify(body),
+ });
+ if (!response.ok) throw new HttpError(response.status);
+ return response.status === 204
+ ? (undefined as T)
+ : (response.json() as Promise);
+}
+export const settingsApi = {
+ setupStatus: () => request("/auth/setup"),
+ setup: (body: SetupRequest) => request("/auth/setup", body),
+ password: (body: ChangePasswordRequest) =>
+ request("/settings/password", body),
+ revoke: () => request("/settings/sessions/revoke", {}),
+ session: () => request("/settings/session"),
+ claude: () => request("/settings/claude"),
+ system: () => request("/settings/system"),
+};
diff --git a/apps/web/src/tests/settings.test.tsx b/apps/web/src/tests/settings.test.tsx
new file mode 100644
index 0000000..c1ebf73
--- /dev/null
+++ b/apps/web/src/tests/settings.test.tsx
@@ -0,0 +1,91 @@
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vitest";
+import { PasswordForm } from "../PasswordForm";
+import { SetupScreen } from "../SetupScreen";
+import { SettingsPage } from "../SettingsPage";
+import { HeaderNavigation } from "../HeaderNavigation";
+import { settingsApi } from "../settingsApi";
+afterEach(() => vi.restoreAllMocks());
+function fill(label: string, value: string) {
+ fireEvent.change(screen.getByLabelText(label), { target: { value } });
+}
+it("validates confirmation and clears credentials after setup", async () => {
+ const submit = vi.fn().mockResolvedValue(undefined);
+ render();
+ fill("Setup token", "token");
+ fill("New password", "long password here");
+ fill("Confirm password", "wrong password here");
+ fireEvent.click(screen.getByRole("button", { name: "Set up ShellBook" }));
+ expect(await screen.findByText("Passwords do not match")).toBeInTheDocument();
+ expect(submit).not.toHaveBeenCalled();
+ fill("Confirm password", "long password here");
+ fireEvent.click(screen.getByRole("button", { name: "Set up ShellBook" }));
+ await waitFor(() =>
+ expect(submit).toHaveBeenCalledWith({
+ token: "token",
+ currentPassword: "",
+ newPassword: "long password here",
+ confirmPassword: "long password here",
+ }),
+ );
+ await waitFor(() =>
+ expect(screen.getByLabelText("New password")).toHaveValue(""),
+ );
+});
+it("submits setup and enters the app", async () => {
+ vi.spyOn(settingsApi, "setup").mockResolvedValue();
+ const done = vi.fn();
+ render();
+ fill("Setup token", "token");
+ fill("New password", "long password here");
+ fill("Confirm password", "long password here");
+ fireEvent.click(screen.getByRole("button", { name: "Set up ShellBook" }));
+ await waitFor(() => expect(done).toHaveBeenCalledOnce());
+});
+it("shows password failure and preserves the form for retry", async () => {
+ render(
+ ,
+ );
+ fill("Current password", "wrong");
+ fill("New password", "long password here");
+ fill("Confirm password", "long password here");
+ fireEvent.click(screen.getByRole("button", { name: "Change password" }));
+ expect(await screen.findByRole("status")).toHaveTextContent("Unable to save");
+});
+it("renders system/session/Claude information and opens the terminal", async () => {
+ vi.spyOn(settingsApi, "system").mockResolvedValue({
+ version: "1.2",
+ workspacePath: "/workspace",
+ dataDirPath: "/data",
+ nodeVersion: "v22",
+ });
+ vi.spyOn(settingsApi, "session").mockResolvedValue({
+ lifetimeSeconds: 86400,
+ });
+ vi.spyOn(settingsApi, "claude").mockResolvedValue({
+ available: true,
+ version: "Claude 1",
+ loginAppearsPresent: true,
+ });
+ const revoke = vi.spyOn(settingsApi, "revoke").mockResolvedValue();
+ const open = vi.fn();
+ render();
+ expect(await screen.findByText("/workspace")).toBeInTheDocument();
+ expect(screen.getByText(/86400 seconds/)).toBeInTheDocument();
+ expect(screen.getByText("Available: Claude 1")).toBeInTheDocument();
+ fireEvent.click(screen.getByText("Open terminal to log in"));
+ expect(open).toHaveBeenCalledOnce();
+ fireEvent.click(screen.getByText("Sign out all sessions"));
+ await waitFor(() => expect(revoke).toHaveBeenCalledOnce());
+ expect(await screen.findByRole("status")).toHaveTextContent(
+ "This browser remains signed in",
+ );
+});
+it("provides the shared feature navigation", () => {
+ const change = vi.fn();
+ render();
+ fireEvent.click(screen.getByText("Settings"));
+ expect(change).toHaveBeenCalledWith("Settings");
+ expect(screen.getByText("Hosts")).toBeInTheDocument();
+ expect(screen.getByText("Notebooks")).toHaveAttribute("aria-current", "page");
+});
diff --git a/deploy/README.md b/deploy/README.md
index bbc4f3f..176e2af 100644
--- a/deploy/README.md
+++ b/deploy/README.md
@@ -15,9 +15,11 @@ LAN/Tailscale addresses. No password is set initially: API access fails closed.
`SHELLBOOK_PORT`, `SHELLBOOK_TRUSTED_PROXIES` (comma-separated proxy IPs),
and `TS_AUTHKEY` in the host environment. Auth keys are transferred in a
mode-0600 temporary file and removed, never stored in the service env.
-3. In the CT run the printed password command. It also accepts one password
- line on stdin; do not pass passwords as arguments. Source-checkout command:
- `SHELLBOOK_DATA_DIR=/var/lib/shellbook pnpm --filter @shellbook/server set-password`.
+3. Open ShellBook in your browser. In the CT run `cat /var/lib/shellbook/setup-token`
+ and enter the token with a new password (at least 12 characters) in the setup screen.
+ This token is private, survives restart, and is deleted after setup. It is never logged.
+ Alternative password CLI: `SHELLBOOK_DATA_DIR=/var/lib/shellbook pnpm --filter @shellbook/server set-password`
+ from the checkout (hidden prompt or one password line on stdin; never arguments).
4. Run `claude` as shellbook and use `/login`. Authorize
`/home/shellbook/.ssh/id_ed25519.pub` on managed hosts. The service user has
no sudo access. Initialize notebooks manually if templates were absent.
@@ -36,8 +38,13 @@ leaves the running service in place. Check `journalctl -u shellbook`.
Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up
along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults
to 2592000 (30 days). Cookies survive restart. Logout clears the browser cookie;
-password changes do not revoke existing cookies. For emergency revocation stop
-the service, delete `session-secret` from the data directory and start it again.
+Settings supports changing the password and signing out all sessions; both revoke
+older cookies and close active WebSockets, while the current browser receives a fresh
+cookie. CLI password changes invalidate cookies on their next request. For emergency
+revocation stop the service, delete `session-secret`, and restart it.
+Settings also shows paths, versions, and Claude CLI status, and opens the terminal
+for `claude` then `/login` as the service user. A credentials file's existence is only
+a hint, not proof that a login is valid.
Forward auth is off by default. To enable it set
`SHELLBOOK_FORWARD_AUTH_HEADER=Remote-User` and trusted proxy IPs. The header is
diff --git a/deploy/install.sh b/deploy/install.sh
index 25751f9..35ae991 100755
--- a/deploy/install.sh
+++ b/deploy/install.sh
@@ -122,7 +122,9 @@ systemctl enable shellbook
systemctl restart shellbook
cat <<'EOF'
Next steps:
-1. Set the password (hidden prompt):
+1. Open ShellBook in the browser and enter the setup token shown by:
+ cat /var/lib/shellbook/setup-token
+ Alternative password CLI (hidden prompt):
runuser -u shellbook -- env SHELLBOOK_DATA_DIR=/var/lib/shellbook node /opt/shellbook/apps/server/dist/cli/set-password.js
2. Log into Claude as the service user:
runuser -l shellbook -c '/home/shellbook/.local/bin/claude'
diff --git a/docs/spec.md b/docs/spec.md
index 3c0ef21..ed0f965 100644
--- a/docs/spec.md
+++ b/docs/spec.md
@@ -157,9 +157,24 @@ only, then removed.
## 7. Security
- The app can run commands on every host → treat access as root-equivalent.
-- Built-in login: one password (scrypt hash in config), session cookie signed with a
- secret persisted on disk → **logins survive restarts**. Optional: trust a
- forward-auth header from Traefik instead.
+- Built-in login: one scrypt password hash in `auth.json`; session cookies are HMAC
+ signed with a persisted mode-0600 secret and bound to the current password hash.
+ Logins survive restarts; changing the password invalidates other cookies.
+- First run creates a random mode-0600 `setup-token` in the data directory. Only its
+ path is logged. Public GET `/api/auth/setup` reports whether setup is needed;
+ POST requires the token (constant-time comparison), matching passwords of at
+ least 12 characters (maximum 4096 bytes), and consumes the token once. Configured
+ instances reject setup with 409. Setup and login share a per-IP rate limit.
+- Settings changes require the current password, or atomically rotate the signing
+ secret to sign out all sessions. Both issue a fresh cookie to the current browser
+ and close existing WebSockets; future connections must authenticate again.
+ Forward-auth identities remain governed by the upstream proxy.
+- Every API route is authenticated except exact health, login, and setup paths;
+ the origin check also covers those exceptions and WebSocket upgrades.
+ Optional forward-auth headers are accepted only from configured trusted peers.
+- Claude status executes only `claude --version` with argv, timeout, and output limit.
+ Login status checks only the existence of `~/.claude/.credentials.json` under the
+ service user home; credential contents are never read or returned.
- Listens on `127.0.0.1` or LAN; intended behind Traefik + firewall (LAN/Tailscale only).
- Terminal panel = shell as the service user: same trust level as the app itself.
- No secrets in notebooks, audit log or artifacts metadata.
diff --git a/packages/core/src/protocol.ts b/packages/core/src/protocol.ts
index c32a806..d424ca7 100644
--- a/packages/core/src/protocol.ts
+++ b/packages/core/src/protocol.ts
@@ -126,3 +126,12 @@ export type ServerEvent =
export type TerminalClientMessage =
| { type: "input"; data: string }
| { type: "resize"; cols: number; rows: number };
+
+// Settings and first-run setup (#10). Only GET/POST /auth/setup is public.
+export interface SetupStatusResponse { required: boolean }
+export interface NewPasswordRequest { newPassword: string; confirmPassword: string }
+export interface SetupRequest extends NewPasswordRequest { token: string }
+export interface ChangePasswordRequest extends NewPasswordRequest { currentPassword: string }
+export interface SessionSettingsResponse { lifetimeSeconds: number }
+export interface ClaudeStatusResponse { available: boolean; version: string | null; loginAppearsPresent: boolean }
+export interface SystemInfoResponse { version: string; workspacePath: string; dataDirPath: string; nodeVersion: string }