# Search and read with the CLI

> Find code, read files, trees and symbols, and look up dependencies and security findings from the terminal.

Source: https://docs.corfedo.ai/connect/cli/search-and-read/

The CLI offers the API's search and read operations, limited to what the selected profile may read.

## Before you begin

The CLI is [installed](https://docs.corfedo.ai/connect/cli/) and [signed in](https://docs.corfedo.ai/connect/cli/sign-in-and-profiles/). `corfedo repositories list` names the repositories you can read.

## Search

`search` finds code. Describe a behavior, name identifiers, quote exact text or write a pattern:

```sh
corfedo search --query 'where are retries configured for HttpClient'
corfedo search --query 'payment refund validation repo:github.com/acme/payments'
corfedo search --query '"connection refused" OR /Search(Code|Async)/ file:^src/'
```

[Search syntax](https://docs.corfedo.ai/reference/search-syntax/) describes the query language.

`symbols` finds where a name is declared:

```sh
corfedo symbols RetryPolicy
corfedo symbols Search --match contains --kind method --repo 'github.com/acme/*'
```

`--match` is `exact` (the default), `contains` or `regex`. Quote `--repo` globs so your shell does not expand them.

## Read

```sh
corfedo read github.com/acme/payments src/Refunds/RefundPolicy.cs --lines 1:40
corfedo tree acme/payments src/Refunds
corfedo outline acme/payments src/Refunds/RefundPolicy.cs
```

| Command | What it shows |
| --- | --- |
| `read REPO PATH` | A file's text, whole or `--lines START:END` (`START:` reads to the end) |
| `tree REPO [DIR]` | The folders and files directly in a directory, from the root by default |
| `outline REPO PATH` | The declarations in a file with their lines |
| `chunks REPO PATH --span START:END` | Snippets around byte ranges that search results return |

`REPO` is the canonical name, such as `github.com/acme/payments`, or `acme/payments` when only one repository you can read has that name.

Every result starts with a `repo path @revision` header. Pass `--rev` with that commit, or a unique prefix of at least seven characters, to read the same commit as an earlier result. If it is no longer served, the command reports `stale`.

## Look up names

`scope lookup` suggests repository names for `repo:` filters. `completions` suggests file name, path or symbol prefixes. Both take a [request file](https://docs.corfedo.ai/connect/cli/scripting/#requests-from-a-file).

## Dependencies and security findings

These commands need the **Dependencies** or **Security findings** permission. A package is written `ecosystem/name`, such as `npm/react`.

```sh
corfedo dependencies acme/payments --vulnerable
corfedo packages usage npm/lodash
corfedo packages uses npm/lodash --origin installed --version 4.17.20
corfedo security findings --repo acme/payments --severity critical
corfedo security advisory GHSA-35jh-r3h4-6jhm
```

| Command | What it shows |
| --- | --- |
| `dependencies REPO` | The packages a repository uses, with the files they are used in |
| `packages usage PACKAGE` | How many repositories use a package, per version, and what the analysis covered |
| `packages uses PACKAGE` | Each repository, version and kind of use, with its files and findings |
| `security findings` | Vulnerability findings, most severe first |
| `security finding REPO ID` | One finding. Use it for a finding an answer cites as `acme/payments finding 193`. |
| `security package PACKAGE` | Findings of a package, per version |
| `security advisories`, `security advisory ID` | Advisories, or one advisory by ID or alias |

`dependencies` exits 6 when the repository's dependencies are not analyzed yet, and 7 when they were read only in part.

## More results

Commands that list results print one page by default. To read every page, pass `--all` with JSON lines output:

```sh
corfedo search --query '"RetryPolicy"' --all --format jsonl
```

## Related

- [MCP tools](https://docs.corfedo.ai/connect/mcp/tools/) offer the same operations to a coding agent.
- [Ask from the CLI](https://docs.corfedo.ai/connect/cli/ask/) lets Corfedo AI investigate for you.
