clj-replace

Replace Clojure or Babashka code by S-expression structure while preserving formatting.

31|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/humorless/clj-native-agent --skill clj-replace
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clj-replace
Source: https://github.com/humorless/clj-native-agent/tree/main/skills/clj-replace
Command: npx skills add https://github.com/humorless/clj-native-agent --skill clj-replace

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

clj-replace fixes brittle code edits by enabling format-agnostic replacement of Clojure or Babashka code when whitespace changes make str_replace fail.

Core Features & Use Cases

  • Structural replacement via S-expressions: compares Clojure code by parsed structure rather than literal text, so formatting differences do not block matches.
  • Preserves original formatting: replaces matched nodes while keeping the file’s existing whitespace and style.
  • Ambiguity detection with actionable errors: reports exact line/column locations and fails when the old pattern matches multiple S-expressions, prompting you to provide a more specific old-string.
  • Typical use cases: rename function parameters or local bindings after cljfmt/zprint/zprint changes indentation; update multi-line forms; perform reliable structural refactors where text-based matching is unreliable.

Quick Start

Run a structural rename by telling your AI to invoke clj-replace as: bb /path/to/clj-replace.bb path/to/file.clj "old-string" "new-string".

Frequently Asked Questions about clj-replace

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace Clojure code when whitespace changes make str_replace fail?

To replace Clojure code after whitespace changes break str_replace, use structural replacement via S-expressions. This approach compares parsed code structure rather than literal text, ensuring formatting differences do not block matches while preserving original formatting.

Why does text-based code replacement break after running a Clojure formatter like cljfmt?

Text-based code replacement breaks after running a Clojure formatter because tools like cljfmt or zprint change indentation and line breaks. Structural replacement matches S-expression nodes instead of literal strings, bypassing these whitespace inconsistencies.

How do I rename function parameters or local bindings in multi-line Clojure forms?

To rename function parameters or local bindings in multi-line Clojure forms, apply structural edits using S-expression matching. Provide the filename, old-string, and new-string to parse and match code structure while preserving existing whitespace and style.

Does clj-replace work with Babashka scripts for structural refactoring?

Yes, clj-replace works with Babashka scripts for structural refactoring. It parses and matches Clojure or Babashka code structure format-agnostically, requiring only the filename plus old-string and new-string parameters to execute reliable edits.

What happens if my old-string pattern matches multiple S-expressions in Clojure?

If your old-string pattern matches multiple S-expressions, the tool reports ambiguity with exact line and column locations. It fails safely and prompts you to provide a more specific old-string to ensure a precise structural replacement.