NewWacht Bench is live — AI-assisted development for Wacht

useProjectThreads() hook

useProjectThreads() is the project-local thread collection hook. It lists the threads that belong to one project and exposes the thread mutations that create, update, archive, and unarchive those threads.

Usage

The following example shows a basic usage of useProjectThreads().

import { useProjectThreads } from '@wacht/nextjs';export default function ProjectThreadList({  projectId,}: {  projectId: string;}) {  const { threads, createThread } = useProjectThreads(projectId);  return (    <div>      <button        onClick={async () => {          await createThread({            title: 'Planning thread',            agent_id: 'agent_123',          });        }}      >        New thread      </button>      <ul>        {threads.map((thread) => (          <li key={thread.id}>{thread.title}</li>        ))}      </ul>    </div>  );}

Return value

The hook returns the following fields and methods.

threads?: AgentThread[] | undefined;
Threads in the current project.
createThread?: (request: CreateAgentThreadRequest) => Promise<ApiResult<AgentThread>> | undefined;
Creates a thread in the current `projectId`. The created thread is available on `result.data`.
createThreadForProject?: (targetProjectId: string, request: CreateAgentThreadRequest) => Promise<ApiResult<AgentThread>> | undefined;
Creates a thread for an explicit target project and is useful when the surrounding UI can switch project targets.
updateThread?: (threadId: string, request: UpdateAgentThreadRequest) => Promise<ApiResult<AgentThread>> | undefined;
Updates a thread and returns the updated thread on `result.data`.
archiveThread?: (threadId: string) => Promise<ApiResult<AgentThread>> | undefined;
Archives one thread and returns the archived thread on `result.data`.
unarchiveThread?: (threadId: string) => Promise<ApiResult<AgentThread>> | undefined;
Restores one thread and returns the thread on `result.data`.

Overview

This hook reads one project thread list and keeps the write-side thread helpers beside it. The list itself is a single-page project thread read, while the thread feed hook covers the larger infinite-scroll sidebar pattern.

When to use it

Use useProjectThreads() when you need the canonical thread collection for one project, or when you want the project-scoped thread creation and archive helpers in the same place.

On this page