home / skills / oimiragieo / agent-studio / preserve-existing-code-rule

preserve-existing-code-rule skill

/.claude/skills/_archive/dead/preserve-existing-code-rule

This skill helps preserve existing code and functionality while reviewing and refactoring to meet standards.

npx playbooks add skill oimiragieo/agent-studio --skill preserve-existing-code-rule

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
1.5 KB
---
name: preserve-existing-code-rule
description: This rule instructs the AI to preserve existing code and functionalities, avoiding unnecessary removal of code.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.*'
best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Preserve Existing Code Rule Skill

<identity>
You are a coding standards expert specializing in preserve existing code rule.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

- Don't remove unrelated code or functionalities. Pay attention to preserving existing structures.
  </instructions>

<examples>
Example usage:
```
User: "Review this code for preserve existing code rule compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill enforces a preserve-existing-code rule that prioritizes keeping current code and behavior intact when reviewing, refactoring, or suggesting changes. It helps developers avoid accidental removal of functionality and reduces regressions by recommending minimal, safe edits. The focus is on clarity, compatibility, and incremental improvements.

How this skill works

The skill analyzes code changes, diffs, or proposed edits to detect removals or replacements of unrelated code and flags risky modifications. It highlights areas where behavior might change, suggests non-destructive alternatives, and explains why preserving existing structures is important. When refactoring, it proposes incremental transformations and tests to validate unchanged behavior.

When to use it

  • During code reviews to prevent accidental deletions or scope creep
  • When refactoring legacy code where behavior must remain stable
  • Before merging pull requests that contain large or cross-cutting changes
  • When automating code suggestions to ensure safe, minimal edits
  • When adopting new patterns without breaking existing APIs

Best practices

  • Prefer additive changes over removals: add wrappers or deprecations before deleting code
  • Document intent for any code that looks unused before removal
  • Write or update tests to cover preserved behaviors before refactoring
  • Limit scope of edits in a single change set to make reviews easier
  • Provide migration steps and compatibility shims when changing public interfaces

Example use cases

  • Review a pull request that replaces utility functions and flag unrelated deletions
  • Refactor a module by extracting helpers without removing original exports; mark them deprecated
  • Suggest adding integration tests when a change touches shared infrastructure code
  • Recommend wrapping legacy functions with new interfaces before removing the originals
  • Audit automated code modification tools to ensure they do not remove unrelated files or logic

FAQ

What counts as "unrelated code"?

Code that is outside the stated scope of the change, not referenced by updated logic, or serving independent features. If unsure, treat it as related until verified.

How do I safely remove deprecated code?

Document the deprecation, provide alternatives, add deprecation warnings, ensure tests cover the old behavior, and schedule removal in a clearly communicated future release.