1Code Documentation

repository·main·Indexed 26 days ago

https://github.com/21st-dev/1code

An 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.

Tokens
8.4K
Snippets
15
Records
81
Agent score
88%

What's inside 1Code

  1. Overview of 21st Agents

    main
    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.
  2. Fix common re-render patterns

    main

    Use 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 in useMemo.

    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 useCallback to maintain a stable function reference.

    Pattern 4: useEffect with Object Dependencies

    Problem: Passing an inline object to a useEffect dependency array. Fix: Memoize the object or use primitive values as dependencies.

  3. Manage MCP Servers and Plugins

    main

    1Code 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.
  4. Run 1Code in development mode

    main

    To 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 dev
  5. Configure 1Code Automations

    main

    Automations allow you to trigger agents from external events. Note that automations require a Pro or Max subscription.

    Supported Triggers:

    • @1code Triggers: Tag @1code in 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.
  6. Install 1Code from source

    main

    To 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+ via pip install setuptools)
    • Xcode Command Line Tools (macOS users)

    Build Steps:

    1. Install dependencies.
    2. Download the required agent binaries.
    3. 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:linux
  7. Enable WDYR debugging

    main

    To debug infinite re-render loops and unnecessary re-renders in the desktop app using the Why Did You Render (WDYR) library, follow these steps:

    1. Open src/renderer/wdyr.ts.
    2. Set const WDYR_ENABLED = true.
    3. Run bun run dev.
    4. Reproduce the issue; re-render logs will appear in the console.
    bun run dev
  8. Configure JSX import source for WDYR

    main

    For WDYR to track all components (not just those wrapped in React.memo or PureComponent), you must configure it as the JSX import source in electron.vite.config.ts during development mode.

    This is a critical configuration step for full coverage.

    react({
      jsxImportSource: isDev
        ? "@welldone-software/why-did-you-render"
        : undefined,
    })
  9. Use the 1code CLI to open projects

    main

    You 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
  10. Troubleshoot WDYR issues

    main

    WDYR Not Logging

    1. Verify WDYR_ENABLED = true in src/renderer/wdyr.ts.
    2. Ensure you restarted the dev server after changes.
    3. Confirm jsxImportSource is correctly set in electron.vite.config.ts.
    4. Ensure wdyr.ts is the first import in src/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 ms

    Crash Before Logs Appear

    If the app crashes before WDYR can log, try:

    1. Adding a debugger statement at the top of the suspected component.
    2. Using the React DevTools Profiler to identify the looping component.
  11. Run coding agents via the 1Code API

    main

    You 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/tasks Authentication: 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"
      }'
  12. Claude Integration Modes

    main

    The application integrates with the @anthropic-ai/claude-code SDK using dynamic imports. It supports two distinct operational modes:

    1. Plan Mode: A read-only mode for planning and analysis.
    2. Agent Mode: A mode with full permissions for executing tools like bash commands and file edits.