Can we make it so anyone can reply in any workspace thread if the workspace is set to open?
Open workspaces
Plan: add a per-workspace "open" switch (owner-only). When on, any signed-in user can reply in that workspace's threads (and start threads there); when off, today's members-only rule stays.
- DB:
workspaces.open boolean not null default false(drizzle/0005 + journal entry; applied by the build-time migrator on prod deploy). - Access (
lib/session.ts): newrequireThreadWriter/requireWriter= member or workspace is open. Used by reply + new-thread routes.requireThreadMember(strict) stays for run/fork, and asking Claude stays members-only even in open workspaces — a run uses the owner's GitHub token and a sandbox, so guests shouldn't be able to trigger it. Easy to loosen later if you want. - API: new
PATCH /api/workspaces/[id]{ open }, owner-only. - UI: toggle on the workspace page for owners; guest notes on the workspace + thread pages explain the open state; thread page composer shows for guests in open workspaces (without the Ask Claude controls);
/threads/newlists open workspaces too. Also fixes the existing bug where non-members saw per-post Ask Claude/Fork buttons.
threadide@e6f08e6Implemented and pushed to thread/057d7756 (commit e6f08e6). tsc and next build are clean. Taking a mockup screenshot of the new workspace Access card and the guest view of a thread, then I'll post the diff.
Summary of what changed:
workspaces.openboolean (drizzle/0005, default false — every existing workspace stays members-only).lib/session.ts:requireWriter/requireThreadWriter= member or open; used by reply + new-thread routes.requireMemberForAgentblocksaskClaudefor non-members; run/fork routes keep the strictrequireThreadMember.PATCH /api/workspaces/[id] { open }(owner only) + a Members only | Open segmented switch on the workspace page.- Thread page: non-members in an open workspace get the composer (no Ask Claude checkbox/model picker) and a one-line note;
/threads/newalso lists open workspaces, marked "(open)".
threadide@e6f08e6Done — pushed to thread/057d7756 (threadide @ e6f08e6). tsc and next build pass. No PR opened; say the word if you want one.
What "open" means
A workspace has a new owner-only switch, Members only | Open (Access card on the workspace page). When Open:
- any signed-in user can reply in the workspace's threads and start threads there;
- asking Claude (runs, forks) stays members-only, since a run spends the owner's GitHub token and a sandbox. Guests see the composer without the Ask Claude checkbox/model picker, and the API returns 403
only workspace members can ask Claude here; replying is fineif they try; - admin (repos, members, invite, delete) is unchanged.
Default is members-only, so nothing changes for existing workspaces until an owner flips the switch.
Changes
- DB:
workspaces.open boolean not null default false—drizzle/0005_open_workspaces.sql+ journal entry. Applied byscripts/migrate.tson the production build when this merges (preview deploys don't migrate, so on preview the workspace pages will 500 with "column open does not exist" until then — expected). - Access (
lib/session.ts): writes now have two tiers.requireWriter/requireThreadWriter= member or open, used byPOST /api/threadsandPOST /api/threads/[id]/posts.requireThreadMember(strict) still guards run/fork; newrequireMemberForAgent(member)blocksaskClaudefor guests.GET …/postsnow usesrequireThreadExists(it's a read path; it was wrongly members-only). - API:
PATCH /api/workspaces/[id] { open: boolean }, owner only.lib/data.ts:setWorkspaceOpen,listPostableWorkspaces(member or open). - UI:
OpenWorkspaceToggle(components/workspace-forms.tsx) as a.segradio group; "open" badge next to the workspace name on/workspacesand the workspace page; guest notes on the workspace page + thread page explain the state;/threads/newlists open workspaces marked "(open)" with run controls hidden and defaults to a workspace you're a member of. - Side fix: thread page
canAskClaudenow also requires membership, so plain viewers no longer see per-post Ask Claude/Fork buttons that would 403 (was a known gotcha).
Not done / open questions
- If you'd rather guests in open workspaces could ask Claude, it's a one-line change: drop the
requireMemberForAgentcalls and make the thread page'scanAskClaude = ws !== null && canPost. I kept it closed by default on purpose. - Open workspaces are still only discoverable by browsing
/workspaces; there's no "join" action — guests just post.
Diff · 15 files
diff --git a/threadide/lib/session.ts b/threadide/lib/session.ts
@@ -51,9 +51,13 @@ export async function membership(workspaceId: string, userId: string) {
/**
* Access model: any signed-in user can READ every workspace and thread on the site.
- * Membership gates WRITES (posting, creating threads, asking Claude); "owner" gates
- * workspace admin (repos, members, invite, delete).
+ * WRITES split in two tiers:
+ * - posting (replies, new threads): members, or anyone signed in when the workspace is OPEN
+ * (workspaces.open) → requireWriter / requireThreadWriter;
+ * - asking Claude (runs, forks) and admin (repos, members, invite): members only; "owner" gates
+ * admin → requireMember / requireThreadMember.
+ * Runs stay members-only even in open workspaces because they spend the owner's GitHub token and
+ * a sandbox.
*/
@@ -62,6 +66,32 @@
+export type WorkspaceAccess = {
+ member: Awaited<ReturnType<typeof membership>>;
+ open: boolean;
+ canPost: boolean;
+};
+
+export async function workspaceAccess(workspaceId: string, userId: string): Promise<WorkspaceAccess> {
+ const [[ws], member] = await Promise.all([
+ db.select({ open: workspaces.open }).from(workspaces).where(eq(workspaces.id, workspaceId)),
+ membership(workspaceId, userId),
+ ]);
+ if (!ws) throw new Forbidden(404, "not found");
+ return { member, open: ws.open, canPost: member !== null || ws.open };
+}
+
+/** For posting paths: member, or any signed-in user when the workspace is open. */
+export async function requireWriter(workspaceId: string, user: CurrentUser) {
+ const access = await workspaceAccess(workspaceId, user.id);
+ if (!access.canPost) throw new Forbidden(404, "not found");
+ return access;
+}
@@ -70,16 +100,31 @@
+/** For reply paths: members, or anyone signed in when the thread's workspace is open. */
+export async function requireThreadWriter(threadId: string, user: CurrentUser) {
+ const t = await requireThreadExists(threadId);
+ if (!t.workspaceId) return { ...t, member: null };
+ const access = await requireWriter(t.workspaceId, user);
+ return { ...t, member: access.member };
+}
+
+/** Ask Claude / fork / run inside a workspace: members only, even when the workspace is open. */
+export function requireMemberForAgent(member: unknown) {
+ if (!member) throw new Forbidden(403, "only workspace members can ask Claude here; replying is fine");
+}
diff --git a/threadide/app/api/threads/[id]/posts/route.ts b/threadide/app/api/threads/[id]/posts/route.ts
@@ -26,10 +27,14 @@ export const POST = guarded(async (req: Request, { params }: Params) => {
- const thread = await requireThreadMember(id, user);
+ const thread = await requireThreadWriter(id, user);
const parsed = Body.safeParse(await req.json());
if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
- if (parsed.data.askClaude) requireWorkspaceForAgent(thread);
+ if (parsed.data.askClaude) {
+ requireWorkspaceForAgent(thread);
+ requireMemberForAgent(thread.member);
+ }
diff --git a/threadide/app/api/threads/route.ts b/threadide/app/api/threads/route.ts
@@ -47,8 +47,11 @@ export const POST = guarded(async (req: Request) => {
- if (workspaceId) await requireMember(workspaceId, user);
- else if (parsed.data.askClaude) return NextResponse.json({ error: "pick a workspace to ask Claude; threads without one are discussion only" }, { status: 400 });
+ if (workspaceId) {
+ const access = await requireWriter(workspaceId, user);
+ if (parsed.data.askClaude) requireMemberForAgent(access.member);
+ } else if (parsed.data.askClaude) return NextResponse.json({ error: "pick a workspace to ask Claude; threads without one are discussion only" }, { status: 400 });
diff --git a/threadide/app/api/workspaces/[id]/route.ts b/threadide/app/api/workspaces/[id]/route.ts
new file mode 100644
+const Patch = z.object({ open: z.boolean() });
+
+/** Owner-only workspace settings. Today that's just the open/members-only switch. */
+export const PATCH = guarded(async (req: Request, { params }: Params) => {
+ const user = await requireUserApi();
+ const { id } = await params;
+ await requireMember(id, user, "owner");
+ const parsed = Patch.safeParse(await req.json());
+ if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
+ const ws = await setWorkspaceOpen(id, parsed.data.open);
+ if (!ws) throw new Forbidden(404, "not found");
+ return NextResponse.json({ id: ws.id, open: ws.open });
+});
diff --git a/threadide/app/threads/[id]/page.tsx b/threadide/app/threads/[id]/page.tsx
@@ -48,12 +48,13 @@
const ws = thread.workspace;
const member = ws ? await membership(ws.id, user.id) : null;
- const canPost = ws ? member !== null : true;
- const canAskClaude = ws !== null;
+ const canPost = ws ? member !== null || ws.open : true;
+ const canAskClaude = ws !== null && member !== null;
@@ -116,7 +117,14 @@
{canPost ? (
- <Composer threadId={thread.id} disabled={live} canAskClaude={canAskClaude} />
+ <>
+ {ws && !member && (
+ <p className="muted guest-note">
+ <Link href={`/workspaces/${ws.id}`}>{ws.name}</Link> is open: anyone signed in can reply here. Only members can ask Claude.
+ </p>
+ )}
+ <Composer threadId={thread.id} disabled={live} canAskClaude={canAskClaude} />
+ </>
) : (
diff --git a/threadide/db/schema.ts b/threadide/db/schema.ts
@@ -110,6 +111,9 @@ export const workspaces = pgTable("workspaces", {
createdBy: uuid("created_by").references(() => users.id, { onDelete: "set null" }),
+ // Open workspace: any signed-in user may reply and start threads here, not just members.
+ // Asking Claude (runs, forks) stays members-only — see lib/session.ts.
+ open: boolean("open").notNull().default(false),
diff --git a/threadide/drizzle/0005_open_workspaces.sql b/threadide/drizzle/0005_open_workspaces.sql
new file mode 100644
+ALTER TABLE "workspaces" ADD COLUMN "open" boolean DEFAULT false NOT NULL;