smart

A command that selects the code files most relevant to a written task by combining meaning-based search with links between functions.

In plain words
What is it for?
Use it after indexing and generating embeddings to prepare a task-focused file set within a token limit.
Why use it?
It reduces the amount of unrelated code an agent must inspect while keeping connected callers and called functions in view.

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/smart
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 1,052 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.01052
Opus 5 $0.00000 $0.00526
Sonnet 5 $0.00000 $0.00210
Haiku 4.5 $0.00000 $0.00105

Measured yesterday against content hash 5b15ecede70c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

smart 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 yesterday.

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/smart.md · 146 lines

How it starts

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

ctx smart

Intelligently select files relevant to a task description using embeddings and call graph analysis.

Synopsis

ctx smart <TASK> [PATTERNS]... [OPTIONS]

Description

The smart command analyzes your task description and automatically selects the most relevant files from your codebase. It combines:

  • Semantic search - Finds symbols related to your task using embeddings
  • Call graph expansion - Includes callers and callees of matched symbols
  • Token budgeting - Fits selection within your token limit

Optional positional patterns scope the entire selection pipeline. Literal files, directories, and globs are ORed together; semantic matches and call-graph expansion both stay within that scope. With no patterns, . selects the whole repository.

Prerequisites

Before using ctx smart, you must:

  1. Index your codebase: ctx index
  2. Generate embeddings: ctx embed

Options

Option Description Default
--max-tokens <N> Maximum tokens in output 8000
--depth <N> Call graph expansion depth 2
--top <N> Top semantic matches to consider 10
--explain Show why each file was selected false
--dry-run Show selection without file contents false
--count-only Count the selected, budgeted files without preview or context output false
--encoding <ENCODING> Tokenizer used for selection and counting (cl100k_base, o200k_base, or p50k_base) cl100k_base
--stats Print count timing to stderr with --count-only false

Examples

Basic Usage

# Select files for adding a new feature
ctx smart "add user authentication"

# Review files for fixing a bug
ctx smart "fix the login timeout issue"

# Search and expand only within Rust source and one contract file
ctx smart "change request validation" "src/**/*.rs" tests/contracts.rs

With Token Budget

# Limit to 4000 tokens for smaller context
ctx smart "implement caching" --max-tokens 4000

# Measure exactly that selected pack using the target model's tokenizer
ctx smart "implement caching" --max-tokens 4000 --count-only --encoding o200k_base

Read the full file on GitHub · 146 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. yesterday First seen · 146 lines · 0 tokens per session scan A 5b15ecede70c

Subscribe to this mod's changes

smart 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 1,052 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.