1Code Documentation
repository·main·Indexed 26 days ago
https://github.com/21st-dev/1codeAn open-source coding agent client and UI for parallel work with AI agents like Claude Code and Codex. Features include a Cursor-like interface, Git worktree isolation, MCP integration, and remote sandbox execution via API. Built as a local-first Electron application using tRPC, Drizzle ORM, and SQLite.
What's inside 1Code
- 21st Agents is a local-first Electron desktop application designed for AI-powered code assistance. It allows users to create chat sessions linked to local project folders, interact with Claude in either 'Plan' (read-only) or 'Agent' (full permissions) modes, and monitor real-time tool execution such as bash commands, file edits, and web searches.
Fix common re-render patterns
mainUse these patterns to resolve common re-render issues identified by WDYR:
Pattern 1: Deeply equal objects/arrays with different references
Problem:
diffType: "deepEquals"indicates objects are identical in value but new references are created every render. Fix: Wrap creation inuseMemo.Pattern 2: Inline Objects in Render
Problem: Creating objects directly in the component body. Fix: Memoize the object using
useMemo.Pattern 3: Callback Reference Changes
Problem: Defining arrow functions inline in props. Fix: Use
useCallbackto maintain a stable function reference.Pattern 4: useEffect with Object Dependencies
Problem: Passing an inline object to a
useEffectdependency array. Fix: Memoize the object or use primitive values as dependencies.Manage MCP Servers and Plugins
main1Code provides full Model Context Protocol (MCP) lifecycle management through the UI.
Capabilities:
- Server Management: Toggle, configure, and delete MCP servers directly from the interface.
- Plugin Marketplace: Browse and install plugins with one click.
- Tool Interaction: View MCP tool calls with formatted inputs and outputs.
- Direct Referencing: Use
@mentions in the chat input to reference MCP servers.
Run 1Code in development mode
mainTo start a development environment, install dependencies, download the required agent binaries, and run the dev command.
bun install bun run claude:download # First time only bun run codex:download # First time only bun run devConfigure 1Code Automations
mainAutomations allow you to trigger agents from external events. Note that automations require a Pro or Max subscription.
Supported Triggers:
- @1code Triggers: Tag
@1codein GitHub, Linear, or Slack to start an agent. - Git Event Triggers: Run automations on
push,PR, or any other git event.
Configuration Options:
- Conditions & Filters: Control the specific criteria required for an automation to fire.
- Silent Mode: Toggle whether the agent responds to the trigger for background automations.
- @1code Triggers: Tag
Install 1Code from source
mainTo build 1Code for free, you must install the required agent binaries (Claude and Codex) during the build process.
Prerequisites:
- Bun
- Python 3.11 (recommended for native module rebuilds)
setuptools(required if using Python 3.12+ viapip install setuptools)- Xcode Command Line Tools (macOS users)
Build Steps:
- Install dependencies.
- Download the required agent binaries.
- Build and package the application for your target platform.
# Prerequisites: Bun, Python 3.11, setuptools, Xcode Command Line Tools (macOS) bun install bun run claude:download # Download Claude binary (required!) bun run codex:download # Download Codex binary (required!) bun run build bun run package:mac # or package:win, package:linuxEnable WDYR debugging
mainTo debug infinite re-render loops and unnecessary re-renders in the desktop app using the Why Did You Render (WDYR) library, follow these steps:
- Open
src/renderer/wdyr.ts. - Set
const WDYR_ENABLED = true. - Run
bun run dev. - Reproduce the issue; re-render logs will appear in the console.
bun run dev- Open
Configure JSX import source for WDYR
mainFor WDYR to track all components (not just those wrapped in
React.memoorPureComponent), you must configure it as the JSX import source inelectron.vite.config.tsduring development mode.This is a critical configuration step for full coverage.
react({ jsxImportSource: isDev ? "@welldone-software/why-did-you-render" : undefined, })Use the 1code CLI to open projects
mainYou can launch 1code directly from your terminal by passing a directory path as an argument. This allows you to open specific projects immediately.
Usage:
- Open the current directory:
1code . - Open a specific project:
1code /path/to/project
1code . # or 1code /path/to/project- Open the current directory:
Troubleshoot WDYR issues
mainWDYR Not Logging
- Verify
WDYR_ENABLED = trueinsrc/renderer/wdyr.ts. - Ensure you restarted the dev server after changes.
- Confirm
jsxImportSourceis correctly set inelectron.vite.config.ts. - Ensure
wdyr.tsis the first import insrc/renderer/main.tsx.
Too Many Logs
Adjust the threshold and window in
src/renderer/wdyr.ts:const THRESHOLD = 10 // Increase to reduce noise const TIME_WINDOW = 1000 // Time window in msCrash Before Logs Appear
If the app crashes before WDYR can log, try:
- Adding a
debuggerstatement at the top of the suspected component. - Using the React DevTools Profiler to identify the looping component.
- Verify
Run coding agents via the 1Code API
mainYou can run coding agents programmatically by sending a POST request to the 1Code API. Point the agent to a repository and provide a prompt. The agent will run in an isolated remote sandbox, perform the task, and automatically open a Pull Request.
Endpoint:
POST https://1code.dev/api/v1/tasksAuthentication: Bearer Token (Authorization: Bearer YOUR_API_KEY)Features:
- Remote Sandboxes: Isolated cloud environments with cloned repos and installed dependencies.
- Git & PR Integration: Automatic commits, branch pushing, and PR creation.
- Async Execution: Fire-and-forget execution with status polling support.
- Follow-up Messages: Ability to send additional instructions to an active task.
curl -X POST https://1code.dev/api/v1/tasks \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "repository": "https://github.com/your-org/your-repo", "prompt": "Fix the failing CI tests" }'Claude Integration Modes
mainThe application integrates with the
@anthropic-ai/claude-codeSDK using dynamic imports. It supports two distinct operational modes:- Plan Mode: A read-only mode for planning and analysis.
- Agent Mode: A mode with full permissions for executing tools like bash commands and file edits.