Replacing 12K LoC with a 200 LoC Skill — David Gomes, Cursor

David Gomes from Cursor explains their transition from a complex, 15,000-line Git WorkTrees feature to a lightweight, flexible solution built on Markdown prompts. He details how 'Skills' and 'Sub-agents' recreated parallel coding workflows, and discusses the trade-offs, failure modes, and lessons learned from shifting product logic from hard code to natural language instructions.

5 min read
Replacing 12K LoC with a 200 LoC Skill — David Gomes, Cursor
source: https://www.youtube.com/watch?v=WE_Gnowy3uw

The core idea presented is treating Markdown as the new code. This talk chronicles the journey of replacing a complex, code-heavy feature in the Cursor application with a streamlined version powered almost entirely by a single Markdown-based “Skill”.

The Original Feature: Git WorkTrees in Cursor

Git WorkTrees are essentially separate checkouts of a repository, allowing for parallel work without interference. In Cursor, this feature enabled multiple agents to work on different tasks simultaneously in isolated environments.

Key capabilities of the original implementation included:

  • Agent Isolation: Each agent operated within its own work tree. Any commands, linting, or file modifications were scoped to that specific checkout, preventing conflicts with the primary branch or other agents.
  • Parallel Workflows: Users could create grids of agents working in parallel. An agent could be instructed to open a pull request directly from its work tree, containing only the changes it produced.
  • “Best of N” Comparison: A powerful feature that allowed users to assign the same task to multiple different models (e.g., GPT-4, Opus, Composer). Each model would work in its own work tree, and the user could then compare the resulting implementations, even previewing visual changes for front-end projects, to select the best approach.

The Complexity of the Code-Based Approach

The initial implementation, released in October of the previous year, was a significant engineering effort that involved:

  • Manual Management: Writing extensive code for creating, managing, and cleaning up work trees.
  • Agent Scoping: Ensuring agents were strictly confined to their work trees and could not “escape” to modify other files.
  • Setup Scripts: A system for users to configure scripts that run automatically when an agent begins work in a new tree.
  • Judging Logic: A separate “judge” to evaluate the outputs from the “Best of N” feature and suggest the best implementation.
  • System Reminders: Changes to the core agent harness to help it stay on track within a work tree context.

This complexity amounted to roughly 15,000 lines of code that had to be maintained.

The New Approach: Markdown, Skills, and Sub-agents

The team decided to replace this entire feature by leveraging two existing primitives in Cursor: Skills and Sub-agents. The goal was to reimplement the functionality of WorkTrees and “Best of N” using only Markdown prompts.

The new workflow is initiated through simple slash commands:

  • /worktree [task]: Starts an agent in an isolated work tree to perform the given task.
  • /best-of-n [task]: Instructs a parent agent to create multiple sub-agents, one for each specified model. Each sub-agent creates its own work tree and works on the task.
  • /apply-worktree & /delete-worktree: Commands to merge changes from a work tree into the primary checkout or to clean it up.

The logic for these commands is defined in simple Markdown prompts. For example, the /best-of-n skill instructs the parent agent to:

  1. Create a sub-agent for each specified model.
  2. Have each sub-agent create and operate within its own work tree.
  3. Wait for all sub-agents to complete their tasks.
  4. Provide a comparative analysis of the different implementations in a table format, helping the user choose the best solution.

A key challenge is ensuring the model stays within its designated work tree. This is handled through “aggressive prompting” within the skill’s instructions.

Pros of the New Implementation

  • Reduced Maintenance: The most significant benefit was deleting ~15,000 lines of code, drastically reducing the maintenance burden for an advanced feature not used by the entire user base.
  • Increased Flexibility: Users can now decide to switch to a work tree midway through a chat session using the slash command, a capability that wasn’t practical with the old UI.
  • Multi-Repo Support: The previous implementation did not support projects with multiple repositories (e.g., separate front-end and back-end repos). The new, skill-based approach handles this seamlessly, creating a work tree for each repo.
  • Superior “Best of N” Experience: The parent agent now has full context of what each sub-agent did. This allows for a much richer comparison and enables the user to ask the parent agent to “stitch together” the best parts from different model implementations.

Cons and Challenges

The transition was not without its drawbacks, and user feedback has been mixed.

  • Reliability Issues: The previous system physically prevented the agent from modifying files outside its work tree. The new system relies on the model adhering to the prompt’s instructions. This “vibes-based” approach can fail, especially over long sessions, where a model might “forget” its context and start working on the primary checkout.
  • Perceived Slowness: Users now see the agent executing commands to create the work tree in the chat, which can feel like it’s wasting time on setup, even if the actual time taken is comparable.
  • Poor Discoverability: The feature is now hidden behind a slash command, making it harder for new users to discover compared to the previous, more explicit UI dropdown.

Future Improvements and What’s Next

To address the reliability issues, the team is focusing on two main areas:

  1. Evals: Using tools like BrainTrust to build an evaluation suite. The evals run the Cursor CLI headlessly to test whether models correctly perform tasks within their work trees and, crucially, whether they incorrectly modify files in the primary checkout. Early results show that less capable models like Haiku often fail, while more advanced models like Composer and Grok perform better.
  2. Reinforcement Learning (RL): The team is adding work tree-related tasks to the RL training pipeline for their in-house model, Composer. This will train the model to be inherently better at staying on track in these scenarios.

For the future of Cursor 3.0, the plan is:

  • Native Implementation: A more complete, native WorkTrees feature will be built into the new, more agent-centric UI of Cursor 3.0, providing a better experience for power users.
  • Explore Other Primitives: The team is researching parallelization techniques beyond Git WorkTrees, aiming for solutions that are faster, use less disk space, and are not dependent on Git.

Share post

Stay In The Loop! Subscribe to Our Newsletter.

Get updates straight to your inbox. No spam, just useful content.

Recommended for You

The Future of Coding: AI Agents & the Next Tech Revolution // Ricky Doar

The Future of Coding: AI Agents & the Next Tech Revolution // Ricky Doar

Ricky Doar, VP of Solutions at Cursor, shares best practices for leveraging AI in software development, focusing on effective problem decomposition, context management, and navigating both new and legacy codebases. He highlights common anti-patterns, such as over-reliance on AI, and offers strategies for debugging, model steerability, and building effective agent harnesses.

[FULL WORKSHOP] AI Coding For Real Engineers - Matt Pocock, AI Hero (@mattpocockuk )

[FULL WORKSHOP] AI Coding For Real Engineers - Matt Pocock, AI Hero (@mattpocockuk )

A workshop on building a complete AI-assisted development workflow, covering how to translate ambiguous requirements into agent-ready plans and run autonomous coding agents to ship production-ready features.