Add a new component that creates an xterm window. This will let us use claude directly…
- User
Add a new component that creates an xterm window. This will let us use claude directly from gossamer, instead of having to open separate terminal windows
Assistant
Now I have a clear picture. I'll implement the xterm terminal using:
node-ptyin the main process (spawns a real PTY)@xterm/xterm+@xterm/addon-fitin the renderer- IPC bridge through the preload script
- A new
/terminalroute + nav item
Assistant
Good. Now let me implement all the pieces:
Assistant
Now create the Terminal screen:
Assistant
Now add the route and nav item:
Assistant
Now let's verify it builds cleanly:
Assistant
Clean build. Here's what was added:
src/main/index.ts— IPC handlers forpty:spawn,pty:write,pty:resize,pty:kill. Spawns a real PTY usingnode-pty(your login shell from$SHELL) and streams output back to the renderer.src/preload/index.ts—contextBridgeexposeswindow.ptyto the renderer with full isolation.src/renderer/src/screens/Terminal.tsx— xterm.js terminal with the fit addon (auto-resizes to fill the panel), Mantine-matching dark theme, and aResizeObserverthat keeps the PTY cols/rows in sync.App.tsx—/terminalroute added.Layout.tsx— "Terminal" nav item with>symbol; navigating away and back spawns a fresh shell.
Note: navigating away kills the PTY session (terminal state is lost on route change). If you want the session to persist across navigation, let me know and I can add a keep-alive approach.
- User
yes, add a keep alive approach
Assistant
The approach: always mount
<Terminal />inLayout.tsxand toggle visibility with CSS (display: none/flex). When the terminal becomes visible again, we callfitAddon.fit()so xterm re-measures correctly.Assistant
Now update
Layout.tsxto always mount Terminal and show/hide it with CSS:Assistant
Remove the
/terminalroute fromApp.tsxsince Terminal is now managed by Layout directly:Assistant
Clean. Here's how the keep-alive works:
<Terminal active={...} />is always mounted insideLayout.tsx, outside the<Outlet />, so the React router never unmounts it.- When you navigate away, the terminal div gets
display: noneand the outlet getsdisplay: flex— and vice versa. - The
activeprop triggers arequestAnimationFrame(() => fitAddon.fit())when you navigate back, so xterm re-measures after the browser has re-painted the visible panel. - The PTY process and all terminal history survive navigation completely.
- User
Error with the terminal view: No routes matched location "/terminal"
Assistant
Need to add back the
/terminalroute so the router doesn't error — just rendernullsince the terminal is handled by Layout.Assistant
Fixed. The route now exists for the router, but renders
null— the actual terminal panel is always mounted in Layout and shown/hidden via CSS.- User
the terminal shows up now but it immediately says "process exited"
Assistant
The terminal is mounted while hidden (
display: none), sofitAddon.fit()gets zero dimensions and the PTY starts with a broken terminal size, causing an immediate exit. The fix: defer initialization until the terminal is first made visible.Assistant
The key change: initialization now only runs when
activeistruefor the first time — at which point the container is visible and has real dimensions, sofitAddon.fit()measures correctly and the PTY starts with the right cols/rows.- User
Make this component reusable so that we can create new instances of it at will. I want to be able to have one window per claude code session, potentially. Also i want to be able to spawn new windows within the app to fix open items
Assistant
This needs a few moving pieces:
- Multi-PTY main process — keyed by id instead of a single global
- Updated preload — all IPC calls include an id
Terminal.tsx— takesid+cwdpropsTerminalManager.tsx— tab bar, always-mounted terminal instancesTerminalContext.tsx— lets any screen callopenTerminal({ cwd })Layout.tsx— hosts the manager + provides context
Assistant
Now the context that lets any screen open a terminal:
Assistant
Now the
TerminalManager— tab bar + always-mounted terminal panels:Assistant
Now update
Layout.tsxto host the manager state and provide the context:Assistant
Now update the
Layoutfunction to manage tab state and wire the context:Assistant
Now wrap the return with the context provider and swap the terminal rendering:
Assistant
Close the provider tag at the end:
Assistant
Also need to handle the nav item click — clicking "Terminal" in the sidebar should open a new tab if none exist yet:
Assistant
Clean. Here's what you now have:
Multiple terminals, all kept alive:
- Each tab has its own PTY process in the main process (keyed by id)
- All terminal panels are always mounted — switching tabs is instant, no session loss
Opening terminals from anywhere in the app:
tsximport { useTerminal } from "../TerminalContext"; function SomeScreen() { const { openTerminal } = useTerminal(); // Open a plain terminal openTerminal(); // Open one in a specific directory (e.g. from a repo or checkpoint) openTerminal({ cwd: "/path/to/repo", label: "fix: auth bug" }); // Open or focus a named terminal (e.g. one per session) openTerminal({ id: sessionId, label: session.name, cwd: session.localPath }); }The
iddeduplication means callingopenTerminal({ id: sessionId })will focus the existing tab rather than opening a duplicate — perfect for "one terminal per Claude session."