Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ repos:
- id: deptry
pass_filenames: false
always_run: true
entry: bash -c "uv run --frozen --all-extras --dev deptry src --ignore DEP001 --extend-exclude 'codegen-examples/.*'"
entry: bash -c "uv run --frozen --all-extras --dev deptry src --ignore DEP001 --per-rule-ignores 'DEP002=pyright|mini-racer|hatch-vcs|pyinstrument|pip|python-levenshtein|python-semantic-release|pytest-snapshot|numpy|modal|langgraph-prebuilt' --extend-exclude 'codegen-examples/.*'"

- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 39.264.0
Expand Down
6 changes: 5 additions & 1 deletion docs/cli/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ iconType: "solid"
The Graph-sitter CLI helps you:

- Parse a local repository into graph summary data
- Inspect files and trace call relationships from the command line
- Diagnose parse time, memory use, and graph size for a local repository
- Initialize Graph-sitter in your repository
- Create and run codemods
- Run one-shot transformations by import path
- Run one-shot transformations and focused renames

<Note>
For installation instructions, see our [Getting
Expand Down Expand Up @@ -68,6 +69,9 @@ graph-sitter create my-codemod .
<Card title="parse" icon="diagram-project" href="/cli/parse">
Parse a repository and print graph summary counts.
</Card>
<Card title="graph" icon="diagram-project" href="/cli/graph">
Inspect files, trace usages, trace callees, and rename symbols.
</Card>
<Card title="diagnose" icon="gauge" href="/cli/diagnose">
Report parse time, memory use, and graph size for a repository.
</Card>
Expand Down
141 changes: 141 additions & 0 deletions docs/cli/graph.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: "Graph Commands"
sidebarTitle: "graph"
icon: "diagram-project"
iconType: "solid"
---

Graph-sitter includes high-level CLI commands for inspecting local code structure,
tracing call relationships, and applying focused renames without writing custom
codemods.

```bash
graph-sitter inspect src/app.py
graph-sitter using src/app.py:handler --depth 2
graph-sitter usages src/app.py:helper --depth 2
graph-sitter rename src/app.py:helper --to execute_helper --write
```

## Target Syntax

Use `FILE:SYMBOL` for functions, classes, methods, and other named symbols:

```bash
graph-sitter using src/app.py:handler
graph-sitter usages src/app.py:Service.run
graph-sitter rename src/app.py:handler --to run_handler --write
```

The CLI also accepts `FILE::SYMBOL` and dotted shorthand such as
`src/app.py.handler` when it can resolve the file unambiguously.

## inspect

`inspect` prints source-file structure: line count, imports, classes, functions,
and function call summaries.

```bash
graph-sitter inspect FILE [PATH] [OPTIONS]
```

Options:

- `--level summary|functions|calls|full`: Choose how much detail to print.
Defaults to `functions`.
- `--format summary|json`: Choose human-readable or machine-readable output.
- `--max-functions N`: Limit function rows. Defaults to `200`.
- `--max-calls N`: Limit call names per function. Defaults to `20`.

Examples:

```bash
graph-sitter inspect src/app.py .
graph-sitter inspect src/app.py . --level calls
graph-sitter inspect src/app.py . --level full --format json
```

## using

`using` traces outbound calls from a target. With `--depth 2`, the output
includes the target's direct callees and the callees those functions call.

```bash
graph-sitter using TARGET [PATH] [OPTIONS]
```

Options:

- `--depth N`: Recursion depth through resolved outbound calls. Defaults to `1`.
- `--max-results N`: Maximum call edges to print. Defaults to `200`.
- `--format summary|json`: Choose human-readable or machine-readable output.

Example:

```bash
graph-sitter using src/app.py:handler . --depth 3 --format json
```

## usages

`usages` traces inbound call sites for a target. With `--depth 2`, the output
includes direct callers and callers of those callers.

```bash
graph-sitter usages TARGET [PATH] [OPTIONS]
```

Options:

- `--depth N`: Recursion depth through inbound callers. Defaults to `1`.
- `--max-results N`: Maximum call edges to print. Defaults to `200`.
- `--format summary|json`: Choose human-readable or machine-readable output.

Example:

```bash
graph-sitter usages src/app.py:helper . --depth 2
```

## rename

`rename` resolves a target symbol and renames it across Graph-sitter's resolved
references. A plain command is a dry run; pass `--write` to modify files.

```bash
graph-sitter rename TARGET [PATH] --to NEW_NAME [OPTIONS]
```

Options:

- `--to NEW_NAME`: Required new symbol name.
- `--check`: Preview target and reference counts without writing. This is the
default.
- `--write`: Apply the rename and write files to disk.
- `--format summary|json`: Choose human-readable or machine-readable output.

Examples:

```bash
graph-sitter rename src/app.py:helper . --to execute_helper
graph-sitter rename src/app.py:helper . --to execute_helper --write
```

## Shared Options

All graph commands accept the same parse controls as `parse`:

- `--backend python|rust|auto`: Choose the graph backend.
- `--fallback python|error`: Choose fallback behavior when the Rust backend is
unavailable. Defaults to `python` for these commands.
- `--language auto|python|typescript`: Choose the repository language.
- `--subdir PATH`: Limit parsing to a repository-relative subdirectory or file.
Repeat to include multiple paths.

## With uvx

```bash
uvx --python 3.13 graph-sitter inspect src/app.py .
uvx --python 3.13 graph-sitter using src/app.py:handler . --depth 2 --format json
uvx --python 3.13 graph-sitter usages src/app.py:helper . --depth 2
uvx --python 3.13 graph-sitter rename src/app.py:helper . --to execute_helper --write
```
19 changes: 19 additions & 0 deletions docs/cli/uvx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ temporary environment.

```bash
uvx --python 3.13 graph-sitter parse .
uvx --python 3.13 graph-sitter inspect src/app.py .
uvx --python 3.13 graph-sitter usages src/app.py:handler . --depth 2
uvx --python 3.13 graph-sitter transform ./codemods/rename.py:rename . --check
uvx --python 3.13 graph-sitter run rename-function . --check
```
Expand Down Expand Up @@ -86,6 +88,23 @@ Write JSON to a file when another tool consumes the graph summary:
uvx --python 3.13 graph-sitter parse . --format json --output graph-sitter-index.json
```

## Graph Queries

The high-level graph commands do not require `.codegen` initialization.

```bash
uvx --python 3.13 graph-sitter inspect src/app.py .
uvx --python 3.13 graph-sitter using src/app.py:handler . --depth 2 --format json
uvx --python 3.13 graph-sitter usages src/app.py:helper . --depth 2
uvx --python 3.13 graph-sitter rename src/app.py:helper . --to execute_helper --write
```

Use `--subdir` for large repositories:

```bash
uvx --python 3.13 graph-sitter using src/app.py:handler ./monorepo --subdir packages/app --depth 2
```

## Transform

`transform` runs a one-shot Python transform by file path or import path. It
Expand Down
8 changes: 8 additions & 0 deletions src/graph_sitter/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
from graph_sitter.cli.commands.diagnose.main import diagnose_command
from graph_sitter.cli.commands.doctor.main import doctor_command
from graph_sitter.cli.commands.init.main import init_command
from graph_sitter.cli.commands.inspect.main import inspect_command
from graph_sitter.cli.commands.list.main import list_command
from graph_sitter.cli.commands.lsp.lsp import lsp_command
from graph_sitter.cli.commands.notebook.main import notebook_command
from graph_sitter.cli.commands.parse.main import parse_command
from graph_sitter.cli.commands.rename.main import rename_command
from graph_sitter.cli.commands.reset.main import reset_command
from graph_sitter.cli.commands.run.main import run_command
from graph_sitter.cli.commands.start.main import start_command
from graph_sitter.cli.commands.style_debug.main import style_debug_command
from graph_sitter.cli.commands.transform.main import transform_command
from graph_sitter.cli.commands.update.main import update_command
from graph_sitter.cli.commands.usages.main import usages_command
from graph_sitter.cli.commands.using.main import using_command

click.rich_click.USE_RICH_MARKUP = True
install(show_locals=True)
Expand All @@ -32,6 +36,10 @@ def main():
main.add_command(doctor_command)
main.add_command(diagnose_command)
main.add_command(parse_command)
main.add_command(inspect_command)
main.add_command(usages_command)
main.add_command(using_command)
main.add_command(rename_command)
main.add_command(run_command)
main.add_command(transform_command)
main.add_command(create_command)
Expand Down
Loading
Loading