The Deska blog
Comment Spam: Teaching Agents Restraint
Learn how to stop comment spam and keep your codebase clean when working with AI coding agents like Claude Code and Codex.
· 11 min read
The rise of autonomous coding tools has introduced a frustrating new phenomenon known as comment spam, where AI agents insist on narrating every trivial line of logic they write. While early experiments in AI-assisted coding focused on simply getting the logic right, the current challenge involves teaching these agents the restraint required for professional production environments. High quality code relies on clarity and brevity, yet many agents default to an over-explained style that treats every variable assignment like a major architectural event. Addressing this requires a combination of strict system prompting, better context management, and tools that allow developers to monitor agent behavior in real time.
The Anatomy of Comment Spam
Comment spam occurs when an LLM applies natural language explanations to code that is already self-explanatory. This usually manifests in three distinct ways. First, there is the redundant labeling of standard syntax, such as a comment above a loop stating that the loop iterates over a list. Second, there is the narrative style where the agent explains its own thought process within the source file, which belongs in a commit message or a chat log rather than the codebase. Finally, there is the "obvious" documentation where every getter and setter receives a Javadoc or TSDoc block that merely repeats the function name in sentence form.
This behavior stems from the training data of many large language models. Educational content, tutorials, and beginner-level repositories often over-comment to help learners. When an agent like Claude Code or Codex CLI is tasked with a transformation, it may default to this instructional persona unless specifically told otherwise.
Why Agents Over-Comment
To solve the problem of comment spam, developers must understand why agents feel the need to be so chatty. The primary reason is often a lack of confidence in the prompt context. If an agent is unsure if the developer understands the underlying logic, it over-compensates by adding explanations.
Another factor is the reward mechanism inherent in many LLM architectures. Models are often fine-tuned to be helpful and verbose. In a chat interface, verbosity feels like value. In a source file, verbosity is technical debt. This misalignment creates a situation where the agent "hallucinates" the need for documentation where none is required.
Contextual Noise and Token Limits
When an agent fills a file with unnecessary comments, it isn't just a matter of aesthetics. It impacts the technical performance of the agent itself.
- Every comment takes up tokens in the context window.
- Large blocks of comments can distract the model from relevant logic located further down in the file.
- Over-commented files make it harder for subsequent agent passes to identify the core logic.
Strategies for Better Restraint
Managing an agent's output requires a multi-layered approach to quality control. You cannot rely on the agent to inherently know your team's style guide without explicit instruction.
System Prompt Engineering
The most effective way to reduce comment spam is at the system prompt level. Instead of a general instruction to write code, use specific constraints regarding documentation. You might instruct the agent to never comment on "what" the code is doing, but only "why" a non-obvious decision was made. Telling an agent to follow the principles of Clean Code or to mimic the style of a specific well-regarded library can also help set the right tone.
Interactive Supervision in the Workspace
Monitoring an agent as it writes is crucial for catching bad habits early. Using a specialized environment like Deska allows you to see the agent's output in real time through dedicated panels. Within the Deska canvas, you can place your editor side by side with the agent terminal. This visual layout makes it easy to spot when an agent begins to pollute a file with redundant explanations.
Because Deska runs agents like Claude Code or OpenCode as independent panels, you can use Ask Deska to intervene. If you notice a trend toward verbosity, you can issue a voice or chat command to update the agent's instructions for the remainder of the session.
Tooling and Environments
The choice of developer tool significantly impacts how you manage agent quality. Many traditional IDE extensions hide the agent's internal thought process, showing only the final file diff. This makes it difficult to understand why the agent decided to add specific comments.
A local-first approach, like the one used in the Deska desktop app, ensures that all files and agent sessions stay on your machine. This is important when you are tuning agents for high-quality output, as your custom system prompts and configuration files are not stored on a third-party server. You can manage your own API keys for various models through a BYOK (Bring Your Own Key) model, which gives you more control over which version of a model you are using. Some versions of models are notably more prone to comment spam than others.
Comparing Agent Behaviors
Different agents have different "personalities" when it comes to code documentation. While they all differ in approach, some patterns emerge during regular use.
| Agent Type | Typical Comment Style | Control Mechanism |
|---|---|---|
| Claude Code | Often concise but can get chatty on complex logic | System prompt overrides |
| Codex CLI | Tends to follow the style of existing files closely | Contextual examples |
| OpenCode | Highly configurable but needs strict guardrails | Configuration files |
By running these agents side by side in a multi-panel workspace, you can compare how each handles a specific refactoring task. You might find that one agent requires significantly less supervision to maintain a clean codebase than another.
Integrating Mobile Monitoring
Sometimes, long-running agent tasks are better monitored away from the desk. If you have assigned a large-scale refactoring task to an agent, you can use a mobile app to check the progress. The Deska mobile app allows you to monitor sessions through a secure relay. If you see the agent starting to add comment spam across dozens of files, you can pause the operation or adjust the instructions remotely before the technical debt accumulates.
FAQ
How do I stop AI agents from adding comments?
The most effective method is to modify your system prompt to include a rule such as "Do not add comments unless the logic is highly non-intuitive." You should also provide examples of your preferred coding style in the context window so the agent has a reference for the desired level of brevity.
Why does Claude Code add so many comments?
LLMs like Claude are trained to be helpful assistants. In a coding context, this often translates to explaining the code as it is written. This can be mitigated by using a more technical persona in your instructions and specifically requesting a "production-ready" output style without instructional prose.
Can I strip agent comments automatically?
Yes, you can use post-processing scripts or linters to remove comments, but this is a reactive solution. It is better to solve the problem at the source by tuning the agent's behavior. Using a workspace that supports terminals alongside your code editor allows you to quickly run linting commands to check for documentation density.
Improving Your Workflow
The goal of using AI agents is to increase productivity, not to spend hours deleting redundant text. By selecting the right tools and refining your prompting strategy, you can enjoy the benefits of autonomous coding without the burden of comment spam. If you are looking for a workspace designed to handle multiple agents while keeping your code local and secure, you can explore the options available in the Deska ecosystem. The transition to AI-assisted development requires new habits, and restraint is one of the most important skills to teach your digital collaborators.
To begin building a more disciplined agent workflow on Mac, Windows, or Linux, you can download the free desktop app and start organizing your workspace today.