Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/21st-dev/1code/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The 1Code Desktop application uses a tRPC API for internal communication between the Electron main process and renderer process. This API is not exposed externally but powers all desktop functionality.
This API is for internal use and extension development only. It is not a public API and may change without notice.

Architecture

The Desktop API uses tRPC for type-safe communication:
  • Main Process: Electron main process runs the tRPC server
  • Renderer Process: React app acts as the tRPC client
  • Transport: IPC (Inter-Process Communication) via Electron

API Routers

The Desktop API is organized into routers by domain:

Projects

Manage project folders and git repositories

Chats

Create and manage chat sessions and workspaces

Agents

Interact with Claude and Codex agents

Usage Example

From the renderer process:
import { trpc } from '@/lib/trpc';

// Query example
const projects = await trpc.projects.list.query();

// Mutation example
const newProject = await trpc.projects.create.mutate({
  path: '/path/to/project',
  name: 'My Project'
});

// Subscription example (streaming)
trpc.claude.chat.subscribe(
  {
    subChatId: 'sub_123',
    chatId: 'chat_456',
    prompt: 'Fix the tests',
    cwd: '/path/to/project'
  },
  {
    onData: (chunk) => {
      console.log('Received:', chunk);
    },
    onError: (error) => {
      console.error('Error:', error);
    }
  }
);

Type Safety

All Desktop API methods are fully type-safe with TypeScript:
// Types are inferred automatically
const project = await trpc.projects.get.query({ id: 'proj_123' });
// project is typed as Project | null

if (project) {
  console.log(project.name); // TypeScript knows this is a string
  console.log(project.path); // TypeScript knows this is a string
}

Error Handling

The Desktop API uses standard tRPC error handling:
try {
  const result = await trpc.chats.create.mutate({
    projectId: 'proj_123',
    name: 'New Chat'
  });
} catch (error) {
  if (error.data?.code === 'NOT_FOUND') {
    console.error('Project not found');
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Database Schema

The Desktop API stores data in a local SQLite database using Drizzle ORM:
  • projects - Project folders and git info
  • chats - Chat sessions (workspaces)
  • subChats - Individual conversation threads within a chat
  • anthropicAccounts - Claude Code OAuth accounts
  • claudeCodeCredentials - Legacy Claude authentication

Source Code

The Desktop API implementation is located in the source code:
src/main/lib/trpc/routers/
├── projects.ts       # Projects router
├── chats.ts         # Chats router
├── claude.ts        # Claude agent router
├── codex.ts         # Codex agent router
├── agents.ts        # Agent utilities
└── index.ts         # Router composition

Next Steps

Projects API

Project management methods

Chats API

Chat and workspace methods

Agents API

Claude and Codex streaming