Core Concepts
Sessions in Craft Agents are workspace-scoped conversations that store:Conversation Data
All messages, tool calls, and agent responses in JSONL format
Metadata
Names, labels, statuses, flags, and timestamps
Attachments
File uploads, plans, and downloaded resources
Token Usage
Input/output tokens, costs, and cache statistics
Storage Structure
Sessions are stored at{workspaceRootPath}/sessions/{id}/ with the following structure:
The JSONL format stores the session header on line 1 (for fast list loading) and one message per line thereafter.
Session Identifiers
Human-Readable IDs
Craft Agents generates memorable session IDs in the format:260304-swift-river260305-bright-forest260305-bright-forest-2(collision handling)
Code Example
packages/shared/src/sessions/slug-generator.ts
Session Persistence
Debounced Async Queue
Craft Agents uses a sophisticated persistence queue to avoid blocking the UI during saves:- Queue Behavior
- Usage
Automatic Debouncing: Multiple rapid changes are coalesced into a single write (500ms window)Async I/O: All writes use Node.js async file operations to prevent main thread blockingPer-Session Serialization: Writes are serialized per session to prevent race conditions on
.tmp filesAtomic Writes: Write to .tmp file, then rename to prevent corruption on crashJSONL Format
Sessions are stored in JSONL (JSON Lines) format for efficient streaming and fast list views: Line 1: Session HeaderThe header includes pre-computed fields (message count, preview, token usage) so the UI can render session lists without parsing all messages.
Session Metadata
Tracked Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique session identifier |
name | string? | Optional user-defined name |
createdAt | number | Unix timestamp (milliseconds) |
lastUsedAt | number | Last access time (any activity) |
lastMessageAt | number? | Last meaningful message (for date grouping) |
sessionStatus | string | Current status (todo/in-progress/done/etc) |
labels | string[] | Applied labels (“bug”, “priority::3”) |
isFlagged | boolean? | Whether session is flagged |
isArchived | boolean? | Whether session is archived |
hasUnread | boolean? | Whether session has unread messages |
permissionMode | string? | Permission mode (safe/ask/allow-all) |
model | string? | LLM model override |
workingDirectory | string? | Current working directory |
Code Example
packages/shared/src/sessions/storage.ts
Listing Sessions
The storage layer provides filtered views for different UI contexts:Active Sessions
Inbox Sessions
Completed Sessions
Archived Sessions
Performance Optimization
The session system is designed for workspaces with thousands of sessions:Session Lifecycle
UI Features
Craft Agents provides several UI features to enhance your session experience:Multi-File Diff Viewer
VS Code-style window for viewing all file changes in a turn. Shows side-by-side diffs of all modifications made by the agent.
Background Tasks
Run long-running operations with progress tracking. Sessions continue working while you focus on other tasks.
Real-Time Tool Visualization
See tool calls as they execute with status indicators and results.
Streaming Responses
Messages appear in real-time as the agent generates them, with syntax highlighting for code blocks.
Background tasks appear in the session list with a progress indicator. Click to view details or wait for completion notification.
Next Steps
Inbox & Archive
Learn about flagging and workflow navigation
Status System
Understand the dynamic status system
Labels
Organize sessions with hierarchical labels