CLAUDE.md
Guides Claude Code on the architecture, commands, and conventions of a CLI tool for managing Claude Code sessions with tmux and git worktrees.
What this file does
Guides Claude Code on the architecture, commands, and conventions of a CLI tool for managing Claude Code sessions with tmux and git worktrees.
When to use it
- You want Claude Code to understand a Bun + TypeScript monorepo with CLI and TUI layers
- You need Claude to follow custom session naming and worktree branch patterns
- You want Claude to know about WebSocket streaming and state management patterns
- You want Claude to use specific test and typecheck commands during development
Assumes this stack
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Claude Session Manager (CSM) is a CLI tool for managing Claude Code sessions across local and remote machines using tmux and git worktrees. It provides both a command-line interface and an interactive TUI dashboard built with React + Ink.
Commands
bun install # Install dependencies
bun link # Link globally as 'csm' command
bun run dev # Run CLI locally
bun test # Run all tests
bun test:unit # Unit tests only
bun test:integration # Integration tests only
bun run typecheck # TypeScript type checking (tsc --noEmit)
Run a single test file: bun test src/path/to/file.test.ts
Architecture
Runtime: Bun with native TypeScript support (no build step). ES modules throughout.
Three layers:
-
CLI layer (
src/index.ts,src/commands/) — Argument parsing and command dispatch. Commands:create,attach,kill,list/ls,hosts,tui,help. No command launches the TUI dashboard. -
Core library (
src/lib/) — Business logic abstractions:tmux.ts— tmux session operations (create, attach, kill, list, state reading)worktree.ts— Git worktree lifecycle (create branchcsm/<name>-<timestamp>, metadata via.csm-metadata.json)config.ts— Config management at~/.config/csm/config.jsonssh.ts— Abstracts local vs remote command execution over SSHclaude-state.ts— Reads Claude Code session state from/tmp/csm-claude-state/linear.ts— Linear issue search, comments (fetch + create)tool-rules.ts— Tool approval rule evaluation engine (glob pattern matching, first-match-wins)event-store.ts— Persistent JSONL event store for SSE replay (~/.config/csm/events/)claude-usage.ts— Claude usage tracking via OAuth credentials (file, macOS Keychain)ws-session-manager.ts— WebSocket session state management and event broadcasting
-
TUI layer (
src/tui/) — Interactive dashboard using React + Ink:App.tsx— Root component withuseReducerstate management- Views:
Dashboard,CreateSession,SessionDetail - Components:
Header,Footer,SessionList,StatusBar hooks/useSessions.ts— Session fetching with 5-second auto-refreshtheme.ts— Centralized color/styling constants
-
Web layer (
src/web/) — React web dashboard (HeroUI + Vite):router.tsx— React Router configuration- Views:
Dashboard,SessionDetail,CreateSession,TasksView,TaskDetailView,ToolRulesView,SettingsView,ProjectsView,HostsView - Components: layout (
Header,Footer,Sidebar), session (SessionCard,SessionTable,GitChanges,FavoriteButton), messaging (ClaudeView,LogViewer,MessageInput), tools (ToolApprovalModal,ToolApprovalBanner), common (Chip,StatusBadge) - Hooks:
useSessionStream(WebSocket streaming),useToolApprovals,useClaudeUsage,useLinearTasks
State management: TUI uses useReducer with actions (SET_VIEW, SET_SESSIONS, SET_LOADING, SET_ERROR, SET_MESSAGE). Views: "dashboard" | "create" | "detail". Web uses TanStack Query for server state and Zustand for client state (favorites).
Path alias: @/* maps to src/* (configured in tsconfig.json).
Conventions
- Session names are prefixed with
csm-(e.g., tmux sessioncsm-my-feature) - Worktree branches follow pattern
csm/<session-name>-<timestamp> - Worktree metadata stored in
.csm-metadata.jsonat worktree root tmux.tsdynamically generates aCLAUDE.mdin worktrees viawriteClaudeContext()with Linear issue context- Commands return
{ success, stdout, stderr, exitCode }result objects - TUI attaches to tmux by exiting the Ink app, running tmux attach, then relaunching TUI on detach (
exitTuiAndAttach())
What's inside
4 sections: project overview, 8 commands, 4-layer architecture with 15+ modules, 5 conventions
Change this for your project
- Replace
danilotorrisi/claude-session-managerwith your repository name - Replace
csmcommand name with your CLI tool name - Replace
~/.config/csm/paths with your config directory - Replace
csm-session prefix with your naming convention
Where it goes
Save as CLAUDE.md in your repository root. Claude Code reads it automatically at the start of every session.
Worth borrowing
- Three-layer separation (CLI, core library, TUI) keeps concerns isolated
- Dynamic CLAUDE.md generation per worktree via writeClaudeContext() embeds context where needed
- TUI attaches to tmux by exiting the app, running attach, then relaunching on detach
Related Documents
Code indexing for AI agents: summarization strategies and evaluation systems
Synthesises 2024-2025 research on code indexing for AI agents, covering summarisation strategies, hybrid retrieval architectures, and evaluation benchmarks.
write-script
Guides an AI through writing a YouTube video script with strict structural, language, and quiz rules for a survival channel.
Claude AI Git Workflow Integration
Recommends using the git-ai-commit CLI tool for AI-generated commit messages instead of manual ones.
Missing Business Agents Research — FLUXION 2026
Identifies 12 missing business operations agents for an indie software company and ranks them by impact and effort with €0 implementation plans.