home / skills / brettatoms / agent-skills / clojure-symbols

clojure-symbols skill

/clojure-symbols

This skill helps you locate, inspect, and edit Clojure symbols using clj-kondo and REPL introspection for definitions, usages, and renaming.

npx playbooks add skill brettatoms/agent-skills --skill clojure-symbols

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

Files (4)
SKILL.md
3.7 KB
---
name: clojure-symbols
description: Find and edit Clojure symbols using clj-kondo and REPL introspection. Use when finding Clojure function definitions, var usages, namespace contents, renaming Clojure symbols, replacing function bodies, or working with .clj/.cljc/.cljs files.
allowed-tools: Bash, Read, Edit, Task
---

# Clojure Symbols Skill

Use **clj-kondo** for static analysis and **clj-nrepl-eval** for REPL introspection to find Clojure symbols.

For non-Clojure languages, use the `code-symbols` skill instead.

## Prerequisites

### clj-kondo

```bash
# Arch Linux
sudo pacman -S clj-kondo

# Homebrew
brew install borkdude/brew/clj-kondo

# Script
curl -sLO https://raw.githubusercontent.com/clj-kondo/clj-kondo/master/script/install-clj-kondo
chmod +x install-clj-kondo && ./install-clj-kondo
```

### clj-nrepl-eval

Discover running nREPL servers:
```bash
clj-nrepl-eval --discover-ports
```

## Quick Reference

| Task | Tool | Command |
|------|------|---------|
| List symbols in file | clj-kondo | `clj-kondo --lint file.clj --config '{...}'` |
| Find definition | clj-kondo | Filter `var-definitions` by name |
| Find usages | clj-kondo | Filter `var-usages` by name |
| Get var metadata | REPL | `(meta #'ns/var)` |
| Get source | REPL | `(clojure.repl/source fn)` |

## Core clj-kondo Commands

**Note:** JSON keys use hyphens (e.g., `var-definitions`), so use bracket notation in jq.

### Find Symbol Definition

```bash
clj-kondo --lint src components bases \
  --config '{:output {:format :json}, :analysis {:var-definitions true}}' \
  | jq '.analysis["var-definitions"][] | select(.name == "my-function")'
```

### Find Symbol Usages

```bash
clj-kondo --lint src components bases \
  --config '{:output {:format :json}, :analysis {:var-usages true}}' \
  | jq '.analysis["var-usages"][] | select(.name == "my-function")'
```

### List Symbols in File

```bash
clj-kondo --lint path/to/file.clj \
  --config '{:output {:format :json}, :analysis {:var-definitions true}}' \
  | jq '.analysis["var-definitions"]'
```

### Output Fields

**var-definitions:**
- `filename`, `row`, `col`, `end-row`, `end-col` - Location
- `ns`, `name` - Identity
- `defined-by` - Defining form (e.g., `clojure.core/defn`)
- `fixed-arities`, `doc`, `private`

**var-usages:**
- `from`, `to` - Source and target namespaces
- `name`, `arity` - Symbol name and call arity
- `from-var` - Containing function
- `row`, `col` - Location

## Core REPL Commands

```bash
# Get var metadata
clj-nrepl-eval -p PORT "(meta #'my.namespace/my-function)"

# Get source code
clj-nrepl-eval -p PORT "(clojure.repl/source my-function)"

# List namespace contents
clj-nrepl-eval -p PORT "(dir my.namespace)"

# Search by pattern
clj-nrepl-eval -p PORT "(clojure.repl/apropos \"pattern\")"
```

## Common Workflow

### Find Definition and All Usages

```bash
# Find definition
clj-kondo --lint . \
  --config '{:output {:format :json}, :analysis {:var-definitions true}}' \
  | jq '.analysis["var-definitions"][] | select(.name == "target-fn") | {ns, name, filename, row}'

# Find all usages
clj-kondo --lint . \
  --config '{:output {:format :json}, :analysis {:var-usages true}}' \
  | jq '.analysis["var-usages"][] | select(.name == "target-fn") | {from, "from-var", filename, row}'
```

### Find Usages of a Namespace

```bash
clj-kondo --lint bases components \
  --config '{:output {:format :json}, :analysis {:var-usages true}}' \
  | jq '.analysis["var-usages"][] | select(.to == "my.namespace") | {from, name, filename, row}'
```

## Additional References

- **clj-kondo details**: See [references/kondo.md](references/kondo.md) for full analysis options
- **REPL introspection**: See [references/repl.md](references/repl.md) for REPL commands
- **Editing/renaming**: See [references/editing.md](references/editing.md) for rename workflows

Overview

This skill helps you find, inspect, and edit Clojure symbols using clj-kondo for static analysis and a connected REPL for runtime introspection. It is designed for locating definitions, usages, namespace contents, and performing safe renames or code replacements across .clj/.cljc/.cljs files. It combines fast codebase-wide searches with live metadata and source retrieval from a running nREPL.

How this skill works

clj-kondo analyzes source files and emits JSON analysis (var-definitions, var-usages, etc.) that you can filter to locate definitions and call sites. A connected nREPL lets you query metadata, fetch source forms, and run apropos-style searches for dynamic confirmation. Use clj-kondo for bulk, offline queries and the REPL to validate behavior and get authoritative source/metadata before editing.

When to use it

  • Locate where a function or var is defined across a repo
  • List all call sites for a symbol before refactoring
  • Inspect namespace contents and available vars interactively
  • Fetch authoritative source or metadata from a running REPL
  • Perform safe renames or replace function bodies across multiple files

Best practices

  • Run clj-kondo with JSON output and filter results with jq for precise queries
  • Confirm symbol identity (namespace + name) before editing to avoid false positives
  • Use REPL (meta and source) to verify runtime bindings and macros before changing code
  • Limit clj-kondo lint targets to relevant directories to speed analysis
  • Stage refactors in small commits and run test suite after automated edits

Example use cases

  • Find the defn for my.namespace/target-fn and open its file at the reported row/col
  • List all var-usages named my-fn to audit call sites before renaming
  • Use the REPL to (meta #'my.namespace/my-var) and clojure.repl/source to review implementation
  • Replace a function body: locate def, fetch source from REPL, apply edits, then run tests
  • Discover where a namespace is referenced across modules to assess impact of API changes

FAQ

Do I need clj-kondo installed locally?

Yes. clj-kondo runs locally to produce the static analysis JSON used for symbol discovery.

How do I find the authoritative source for a var?

Use a connected nREPL and call (clojure.repl/source your-var) or (meta #'your-ns/your-var) to get runtime source and metadata.