similar

A search command for finding existing functions that are similar to a plain-language description. It searches an indexed codebase by meaning or by matching words.

In plain words
What is it for?
Use it before adding functionality, optionally limiting the search to selected files, directories, or filename patterns.
Why use it?
It helps you discover reusable code before writing another function that does the same job. This reduces duplicated implementations.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/agentis-tools/ctx/similar
Clone the repo
git clone --depth 1 https://github.com/agentis-tools/ctx
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 544 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00544
Opus 5 $0.00000 $0.00272
Sonnet 5 $0.00000 $0.00109
Haiku 4.5 $0.00000 $0.00054

Measured 2d ago against content hash b5bf078f24c6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

similar scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/commands/similar.md · 66 lines

How it starts

The opening of the file, as written. The whole thing — 66 lines — stays where its author put it; the contents beside it link to each section on GitHub.

ctx similar

Find existing functions similar to a description before writing new ones.

Synopsis

ctx similar "<query>" [PATTERNS]... [OPTIONS]

Description

The similar command searches the index for functions that already do what you are about to write. Run it before adding a new function: reusing (or extending) an existing implementation is the cheapest way to avoid duplication that ctx duplicates and ctx score would flag later.

By default the search is semantic (embedding-based, requires ctx embed); --keyword falls back to FTS5 keyword search over names, signatures, and doc comments.

Optional positional patterns restrict candidates by file path. Literal files, directories, and globs are ORed together. With no patterns, . searches the whole indexed repository.

Options

Option Description Default
--limit <N> Maximum number of results 10
--keyword Use keyword (FTS5) search instead of embeddings false
--openai Use OpenAI embeddings instead of the local model (requires OPENAI_API_KEY) false
--json Machine-readable output (global flag) false

Exit Codes

Code Meaning
0 Success (informational command)
2 Operational error (missing index, missing embeddings for semantic mode)

Examples

# Before writing a retry helper, see what already exists
ctx similar "retry an operation with exponential backoff"

# Keyword mode (no embeddings needed)
ctx similar "parse config file" --keyword

# Search only command sources and shared tests
ctx similar "parse config file" src/commands/ "tests/**/*_cli.rs" --keyword

# More candidates, OpenAI embeddings
ctx similar "validate user input" --limit 20 --openai

# Machine-readable (standard envelope: ctx_version, command, generated_at, data)
ctx similar "token counting" --json

Caveats

  • Semantic mode requires embeddings: run ctx embed (local model) or ctx embed --openai first; without them, use --keyword.
  • Results rank by meaning, not correctness - always read the candidate before reusing it.

Read the full file on GitHub · 66 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 66 lines · 0 tokens per session scan A b5bf078f24c6

Subscribe to this mod's changes

similar is a command published in the GitHub repository agentis-tools/ctx (11 stars, last pushed 15d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 544 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.