February 9, 2025

The System Prompt of Cline (An Open-Source AI Coding Agent)

With the rising popularity of AI coding tools like Cursor, Windsurf, and Cline, you may wonder how these coding agents were built. While the engineering behind them is complex, one way to gain a better understanding is by examining the system prompt of Cline.

The original system prompt can be found here, which is very long and complex:

Output from the tokenizer:

This long system prompt is attached to every message sent to LLM APIs (OpenAI/Claude/DeepSeek…) with your code, which might be why using your own APIs instead of purchasing credits from Windsurf or Cursor could actually cost more (see Windsurf blog):

…many people will say something along the lines of “let me bring my own API key or pay per token and forget all this credit system nonsense.” We believe there may be some underestimation on how many tokens we are processing on every reasoning step through the combination of knowledge retrieval, encoding of developer actions, and long history, all to give the magic that users feel with Cascade. We are only a couple weeks post-launch and already processing hundreds of billions of tokens with just Claude 3.5 Sonnet every single day. We get nice discounts from these API providers and pass all of the savings from those discounts to our users. So, it is probably not a great idea for users to take these costs on themselves without these discounts…

After studying the system prompt, I think it only does the following three things:

The following shows a more detailed summary of each section but I suggest you go over the original system prompt details to better understand coding agents’ behavior.

Summary of the System Prompt

1. Tool Use

Describes how tools function, emphasizing a step-by-step execution approach where each tool is used sequentially and requires user approval.

2. Tool Use Formatting

Defines the XML-style syntax for invoking tools, ensuring consistency and proper parsing during execution.

3. Tools

Lists available tools, their descriptions, parameters, and usage examples. Covers system commands, file operations, searching, and external resource interaction.

  1. execute_command – Runs a CLI command on the system.
  2. read_file – Reads the contents of a file.
  3. write_to_file – Writes or overwrites a file with specified content.
  4. replace_in_file – Replaces specific sections of a file using a search-and-replace mechanism.
  5. search_files – Performs a regex search across files in a directory.
  6. list_files – Lists files and directories within a specified path.
  7. list_code_definition_names – Extracts and lists function and class definitions from source code.
  8. browser_action – Controls a Puppeteer-controlled browser for automation tasks.
  9. ask_followup_question – Requests additional user input for clarification.
  10. attempt_completion – Finalizes and presents the result of a completed task.
  11. use_mcp_tool – Uses a tool provided by a connected MCP server.
  12. access_mcp_resource – Accesses a resource from an MCP server.

4. Tool Use Guidelines

Outlines best practices for using tools, including selecting the right tool for the task, confirming success before proceeding, and ensuring iterative execution.

5. MCP Servers

Explains the Model Context Protocol (MCP) system, which enables external servers to provide additional tools and resources. Covers how to create, modify, and integrate MCP servers.

6. Editing Files

Distinguishes between write_to_file and replace_in_file, guiding when to use each for optimal efficiency while maintaining file integrity.

7. Act Mode vs. Plan Mode

Defines two operational modes:

8. Capabilities

Lists available system functionalities, including CLI execution, file management, search, and web interactions.

9. Rules

Specifies constraints and guidelines, such as respecting the working directory, avoiding unnecessary user questions, and ensuring precise code modifications.

10. System Information

Provides details about the operating system, shell, home directory, and current working directory for environment-specific tool execution.

11. Objective

Outlines the structured approach to task completion:

  1. Analyze the task and define clear goals.
  2. Use tools sequentially, making decisions based on prior results.
  3. Think critically before tool invocation, ensuring all necessary information is available.
  4. Finalize tasks using attempt_completion, avoiding unnecessary back-and-forth.