|
| 1 | +--- |
| 2 | +title: "Graph Commands" |
| 3 | +sidebarTitle: "graph" |
| 4 | +icon: "diagram-project" |
| 5 | +iconType: "solid" |
| 6 | +--- |
| 7 | + |
| 8 | +Graph-sitter includes high-level CLI commands for inspecting local code structure, |
| 9 | +tracing call relationships, and applying focused renames without writing custom |
| 10 | +codemods. |
| 11 | + |
| 12 | +```bash |
| 13 | +graph-sitter inspect src/app.py |
| 14 | +graph-sitter using src/app.py:handler --depth 2 |
| 15 | +graph-sitter usages src/app.py:helper --depth 2 |
| 16 | +graph-sitter rename src/app.py:helper --to execute_helper --write |
| 17 | +``` |
| 18 | + |
| 19 | +## Target Syntax |
| 20 | + |
| 21 | +Use `FILE:SYMBOL` for functions, classes, methods, and other named symbols: |
| 22 | + |
| 23 | +```bash |
| 24 | +graph-sitter using src/app.py:handler |
| 25 | +graph-sitter usages src/app.py:Service.run |
| 26 | +graph-sitter rename src/app.py:handler --to run_handler --write |
| 27 | +``` |
| 28 | + |
| 29 | +The CLI also accepts `FILE::SYMBOL` and dotted shorthand such as |
| 30 | +`src/app.py.handler` when it can resolve the file unambiguously. |
| 31 | + |
| 32 | +## inspect |
| 33 | + |
| 34 | +`inspect` prints source-file structure: line count, imports, classes, functions, |
| 35 | +and function call summaries. |
| 36 | + |
| 37 | +```bash |
| 38 | +graph-sitter inspect FILE [PATH] [OPTIONS] |
| 39 | +``` |
| 40 | + |
| 41 | +Options: |
| 42 | + |
| 43 | +- `--level summary|functions|calls|full`: Choose how much detail to print. |
| 44 | + Defaults to `functions`. |
| 45 | +- `--format summary|json`: Choose human-readable or machine-readable output. |
| 46 | +- `--max-functions N`: Limit function rows. Defaults to `200`. |
| 47 | +- `--max-calls N`: Limit call names per function. Defaults to `20`. |
| 48 | + |
| 49 | +Examples: |
| 50 | + |
| 51 | +```bash |
| 52 | +graph-sitter inspect src/app.py . |
| 53 | +graph-sitter inspect src/app.py . --level calls |
| 54 | +graph-sitter inspect src/app.py . --level full --format json |
| 55 | +``` |
| 56 | + |
| 57 | +## using |
| 58 | + |
| 59 | +`using` traces outbound calls from a target. With `--depth 2`, the output |
| 60 | +includes the target's direct callees and the callees those functions call. |
| 61 | + |
| 62 | +```bash |
| 63 | +graph-sitter using TARGET [PATH] [OPTIONS] |
| 64 | +``` |
| 65 | + |
| 66 | +Options: |
| 67 | + |
| 68 | +- `--depth N`: Recursion depth through resolved outbound calls. Defaults to `1`. |
| 69 | +- `--max-results N`: Maximum call edges to print. Defaults to `200`. |
| 70 | +- `--format summary|json`: Choose human-readable or machine-readable output. |
| 71 | + |
| 72 | +Example: |
| 73 | + |
| 74 | +```bash |
| 75 | +graph-sitter using src/app.py:handler . --depth 3 --format json |
| 76 | +``` |
| 77 | + |
| 78 | +## usages |
| 79 | + |
| 80 | +`usages` traces inbound call sites for a target. With `--depth 2`, the output |
| 81 | +includes direct callers and callers of those callers. |
| 82 | + |
| 83 | +```bash |
| 84 | +graph-sitter usages TARGET [PATH] [OPTIONS] |
| 85 | +``` |
| 86 | + |
| 87 | +Options: |
| 88 | + |
| 89 | +- `--depth N`: Recursion depth through inbound callers. Defaults to `1`. |
| 90 | +- `--max-results N`: Maximum call edges to print. Defaults to `200`. |
| 91 | +- `--format summary|json`: Choose human-readable or machine-readable output. |
| 92 | + |
| 93 | +Example: |
| 94 | + |
| 95 | +```bash |
| 96 | +graph-sitter usages src/app.py:helper . --depth 2 |
| 97 | +``` |
| 98 | + |
| 99 | +## rename |
| 100 | + |
| 101 | +`rename` resolves a target symbol and renames it across Graph-sitter's resolved |
| 102 | +references. A plain command is a dry run; pass `--write` to modify files. |
| 103 | + |
| 104 | +```bash |
| 105 | +graph-sitter rename TARGET [PATH] --to NEW_NAME [OPTIONS] |
| 106 | +``` |
| 107 | + |
| 108 | +Options: |
| 109 | + |
| 110 | +- `--to NEW_NAME`: Required new symbol name. |
| 111 | +- `--check`: Preview target and reference counts without writing. This is the |
| 112 | + default. |
| 113 | +- `--write`: Apply the rename and write files to disk. |
| 114 | +- `--format summary|json`: Choose human-readable or machine-readable output. |
| 115 | + |
| 116 | +Examples: |
| 117 | + |
| 118 | +```bash |
| 119 | +graph-sitter rename src/app.py:helper . --to execute_helper |
| 120 | +graph-sitter rename src/app.py:helper . --to execute_helper --write |
| 121 | +``` |
| 122 | + |
| 123 | +## Shared Options |
| 124 | + |
| 125 | +All graph commands accept the same parse controls as `parse`: |
| 126 | + |
| 127 | +- `--backend python|rust|auto`: Choose the graph backend. |
| 128 | +- `--fallback python|error`: Choose fallback behavior when the Rust backend is |
| 129 | + unavailable. Defaults to `python` for these commands. |
| 130 | +- `--language auto|python|typescript`: Choose the repository language. |
| 131 | +- `--subdir PATH`: Limit parsing to a repository-relative subdirectory or file. |
| 132 | + Repeat to include multiple paths. |
| 133 | + |
| 134 | +## With uvx |
| 135 | + |
| 136 | +```bash |
| 137 | +uvx --python 3.13 graph-sitter inspect src/app.py . |
| 138 | +uvx --python 3.13 graph-sitter using src/app.py:handler . --depth 2 --format json |
| 139 | +uvx --python 3.13 graph-sitter usages src/app.py:helper . --depth 2 |
| 140 | +uvx --python 3.13 graph-sitter rename src/app.py:helper . --to execute_helper --write |
| 141 | +``` |
0 commit comments