# fileWriteLineLimit in DesktopCommanderMCP: How It Prevents Token Waste and Claude Message Limits

> Learn how DesktopCommanderMCP's fileWriteLineLimit prevents token waste and Claude message limits by capping file modifications. Optimize your LLM token usage.

- Repository: [Eduard Ruzga/DesktopCommanderMCP](https://github.com/wonderwhy-er/DesktopCommanderMCP)
- Tags: deep-dive
- Published: 2026-07-19

---

**The `fileWriteLineLimit` setting caps file modifications at 50 lines per operation to stop LLMs from wasting tokens on redundant whole-file rewrites and to prevent Claude's per-message token limits from truncating work.**

DesktopCommanderMCP is a Model Context Protocol server that gives AI agents controlled access to the local filesystem through tools like `write_file` and `apply_diff`. The `fileWriteLineLimit` configuration parameter acts as a server-side ceiling on how many lines a single edit operation may span, directly addressing the problem of AI assistants consuming excessive tokens by rewriting entire files when only small changes are needed.

## What Is fileWriteLineLimit?

`fileWriteLineLimit` is a configurable option defined in [`src/config-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-manager.ts) that sets the maximum number of lines a single `write_file` operation can modify. The default value is **50 lines**, which is applied when the configuration key is absent. This limit is read from the global configuration object in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) at lines 53-56, where the edit handler validates requests before execution.

## How fileWriteLineLimit Prevents Token Waste

The setting optimizes AI-agent behavior through two specific mechanisms that target common token inefficiencies.

### Discouraging Whole-File Rewrites

When an AI rewrites an entire file instead of applying a targeted edit, it consumes model tokens for every line, including unchanged content that does not need regeneration. By enforcing the `fileWriteLineLimit` cap, the server forces the model to break large changes into smaller, line-bounded edits, dramatically reducing the volume of token-heavy text transmitted between the client and LLM. According to the repository documentation in [`README.md`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/README.md) (lines 49-53), this approach minimizes token waste by ensuring the AI only sends the specific lines that actually change.

### Avoiding Claude UX Message Limits

Claude and similar large language models impose strict per-message token ceilings. If an edit response exceeds this threshold, the "Continue" button may fail and partially generated work is lost. Chunking edits to stay within the `fileWriteLineLimit` ensures each response remains under the message cap, preserving partial progress and allowing the user to resume from the last successful chunk (as noted in [`README.md`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/README.md) lines 52-57).

### The Warning Mechanism

When a requested edit exceeds the configured maximum, the edit routine in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) (lines 96-101) emits a warning and recommends splitting the operation into smaller pieces. This runtime check compares the line counts of both the search and replacement text using `Math.max(searchLines, replaceLines)`, halting the operation if the result exceeds the ceiling.

## Configuring fileWriteLineLimit

You can inspect and modify this limit using the server's built-in configuration tools.

### Reading the Current Limit

Use the `get_config` tool to retrieve the full server configuration and inspect the current value:

```javascript
// Returns the full server config; look at fileWriteLineLimit
get_config({});

```

### Modifying the Limit

Adjust the setting with `set_config_value` to allow larger edits or enforce stricter granularity:

```javascript
// Allow larger edits (e.g., 1000 lines)
set_config_value({ "key": "fileWriteLineLimit", "value": 1000 });

// Or enforce more granular edits (e.g., 25 lines)
set_config_value({ "key": "fileWriteLineLimit", "value": 25 });

```

## Implementation Details

The enforcement logic resides primarily in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts). The handler retrieves the configuration via `configManager.getConfig()` and applies a default of 50 if the key is undefined:

```typescript
const config = await configManager.getConfig();
const MAX_LINES = config.fileWriteLineLimit ?? 50;   // default 50

// After computing the number of lines in the search/replace text:
if (Math.max(searchLines, replaceLines) > MAX_LINES) {
  // Emit a warning and suggest chunking the edit
}

```

Additional relevant files include [`src/handlers/filesystem-handlers.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/handlers/filesystem-handlers.ts), which reads the limit for low-level filesystem operations, and [`src/server.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/server.ts), where the option is listed in the server's help output. Documentation in both [`README.md`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/README.md) and [`FAQ.md`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/FAQ.md) explains the rationale for the default value and provides user guidance.

## Summary

- **Default Behavior**: `fileWriteLineLimit` defaults to **50 lines** as defined in [`src/config-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-manager.ts), with a fallback in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) (lines 55-56).
- **Token Efficiency**: The cap prevents AI models from wasting tokens by rewriting entire files, forcing granular, line-bounded edits instead.
- **Safety Mechanism**: It prevents Claude's per-message token limits from truncating large edits and losing work.
- **Configuration**: Modify via `set_config_value` or read via `get_config` at runtime.
- **Enforcement**: Validated in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) (lines 53-56 and 96-101) with runtime warnings for oversized operations.

## Frequently Asked Questions

### What is the default value of fileWriteLineLimit?

The default `fileWriteLineLimit` is **50 lines**. This value is hardcoded as a fallback in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) (lines 55-56) when the configuration key is absent from the global config.

### How do I increase the fileWriteLineLimit for large refactoring tasks?

Use the `set_config_value` tool to raise the ceiling temporarily or permanently. For example, `set_config_value({ "key": "fileWriteLineLimit", "value": 1000 })` allows edits spanning up to 1000 lines, though you should revert to a lower value afterward to maintain token efficiency.

### Why does DesktopCommanderMCP warn me when my edit is too large?

The warning is generated in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) (lines 96-101) when your edit exceeds the configured line limit. This prevents accidental whole-file rewrites that waste tokens and helps ensure your edit stays within Claude's per-message token ceiling, avoiding truncated responses.

### Where is the fileWriteLineLimit setting stored?

The setting is stored in the global configuration managed by [`src/config-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-manager.ts). It persists across sessions and is read by the edit handler in [`src/tools/edit.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/edit.ts) and filesystem handlers in [`src/handlers/filesystem-handlers.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/handlers/filesystem-handlers.ts) whenever a write operation is initiated.