|
| 1 | +# cli-anything-samgeo |
| 2 | + |
| 3 | +CLI harness for [segment-geospatial](https://github.com/opengeos/segment-geospatial) — segment geospatial imagery using SAM models from the command line. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Python 3.10+ |
| 8 | +- segment-geospatial: `pip install segment-geospatial[all]` |
| 9 | +- PyTorch with CUDA (recommended) or CPU |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +cd agent-harness |
| 15 | +pip install -e . |
| 16 | +``` |
| 17 | + |
| 18 | +This installs the `cli-anything-samgeo` command in your PATH. |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +```bash |
| 23 | +# Create a project |
| 24 | +cli-anything-samgeo project new -n my-seg -o project.json -s image.tif |
| 25 | + |
| 26 | +# Run automatic segmentation |
| 27 | +cli-anything-samgeo --project project.json segment automatic -o masks.tif |
| 28 | + |
| 29 | +# Convert masks to vectors |
| 30 | +cli-anything-samgeo --project project.json vector convert masks.tif output.gpkg |
| 31 | + |
| 32 | +# Export as GeoJSON |
| 33 | +cli-anything-samgeo --project project.json export render output.geojson -f geojson |
| 34 | + |
| 35 | +# All commands support --json for machine-readable output |
| 36 | +cli-anything-samgeo --json model list |
| 37 | +``` |
| 38 | + |
| 39 | +## Command Groups |
| 40 | + |
| 41 | +| Command | Description | |
| 42 | +|---------|-------------| |
| 43 | +| `project` | Create, open, inspect projects | |
| 44 | +| `model` | List, inspect, check SAM models | |
| 45 | +| `segment` | Automatic, point, box, text segmentation | |
| 46 | +| `data` | Download tiles, raster info, reproject, split | |
| 47 | +| `vector` | Convert masks to vectors, inspect, filter | |
| 48 | +| `export` | Export masks to various formats | |
| 49 | +| `session` | Session status and history | |
| 50 | + |
| 51 | +## Interactive REPL |
| 52 | + |
| 53 | +Run without arguments to enter the interactive REPL: |
| 54 | + |
| 55 | +```bash |
| 56 | +cli-anything-samgeo |
| 57 | +``` |
| 58 | + |
| 59 | +## JSON Output |
| 60 | + |
| 61 | +Add `--json` before any command for machine-readable output: |
| 62 | + |
| 63 | +```bash |
| 64 | +cli-anything-samgeo --json data info image.tif |
| 65 | +cli-anything-samgeo --json model list |
| 66 | +``` |
| 67 | + |
| 68 | +## Using with Claude Code |
| 69 | + |
| 70 | +This CLI ships with a `SKILL.md` file that lets Claude Code discover and use all |
| 71 | +commands automatically. There are two ways to enable it. |
| 72 | + |
| 73 | +### Option 1: Add SKILL.md to your CLAUDE.md |
| 74 | + |
| 75 | +Append a reference to the skill file in your project or user `CLAUDE.md`: |
| 76 | + |
| 77 | +```markdown |
| 78 | +# In your CLAUDE.md |
| 79 | +Read the skill file at /path/to/agent-harness/cli_anything/samgeo/skills/SKILL.md |
| 80 | +for the full cli-anything-samgeo command reference. Use `--json` for all |
| 81 | +cli-anything-samgeo commands so output is machine-readable. |
| 82 | +``` |
| 83 | + |
| 84 | +Replace `/path/to/` with the actual absolute path. Claude Code reads `CLAUDE.md` |
| 85 | +at the start of every conversation, so it will know the CLI exists and how to |
| 86 | +call it. |
| 87 | + |
| 88 | +### Option 2: Point Claude Code at the skill on the fly |
| 89 | + |
| 90 | +In any Claude Code conversation, paste: |
| 91 | + |
| 92 | +``` |
| 93 | +Read agent-harness/cli_anything/samgeo/skills/SKILL.md and use that CLI |
| 94 | +to segment this satellite image. |
| 95 | +``` |
| 96 | + |
| 97 | +Claude Code will read the skill file, learn the command syntax, and start |
| 98 | +using `cli-anything-samgeo` with `--json` output. |
| 99 | + |
| 100 | +### Example Claude Code session |
| 101 | + |
| 102 | +Once Claude Code knows about the skill, you can give it natural-language tasks: |
| 103 | + |
| 104 | +``` |
| 105 | +> Segment all buildings in satellite.tif and export the results as a GeoPackage. |
| 106 | +
|
| 107 | +# Claude Code will run: |
| 108 | +cli-anything-samgeo --json project new -n buildings -o project.json -s satellite.tif -t sam2 |
| 109 | +cli-anything-samgeo --json --project project.json segment automatic -o masks.tif |
| 110 | +cli-anything-samgeo --json vector convert masks.tif buildings.gpkg |
| 111 | +``` |
| 112 | + |
| 113 | +``` |
| 114 | +> Download OpenStreetMap tiles for downtown Portland and tell me about the image. |
| 115 | +
|
| 116 | +# Claude Code will run: |
| 117 | +cli-anything-samgeo --json data download-tiles -o portland.tif -b "-122.68,45.51,-122.66,45.53" -z 17 |
| 118 | +cli-anything-samgeo --json data info portland.tif |
| 119 | +``` |
| 120 | + |
| 121 | +### Tips for Claude Code usage |
| 122 | + |
| 123 | +- The `--json` flag is essential — it gives Claude Code structured output it can |
| 124 | + parse and reason about, rather than human-formatted tables. |
| 125 | +- The `--project` flag must appear *before* the command group (e.g., |
| 126 | + `--project proj.json segment automatic`, not `segment automatic --project proj.json`). |
| 127 | +- Claude Code can chain multiple commands in sequence to build full pipelines |
| 128 | + (download → segment → vectorize → export). |
| 129 | +- Use `model check sam2` to let Claude Code verify a model backend is installed |
| 130 | + before attempting segmentation. |
| 131 | + |
| 132 | +## Running Tests |
| 133 | + |
| 134 | +```bash |
| 135 | +cd agent-harness |
| 136 | +python -m pytest cli_anything/samgeo/tests/ -v -s |
| 137 | +``` |
| 138 | + |
| 139 | +## Supported Models |
| 140 | + |
| 141 | +| Type | Models | Install | |
| 142 | +|------|--------|---------| |
| 143 | +| SAM v1 | vit_h, vit_l, vit_b | `pip install segment-geospatial` | |
| 144 | +| SAM 2 | hiera-tiny/small/base-plus/large | `pip install segment-geospatial[samgeo2]` | |
| 145 | +| SAM 3 | facebook/sam3 | `pip install segment-geospatial[samgeo3]` | |
| 146 | +| FastSAM | FastSAM-x, FastSAM-s | `pip install segment-geospatial[fast]` | |
| 147 | +| HQ-SAM | vit_h, vit_l, vit_b, vit_tiny | `pip install segment-geospatial[hq]` | |
| 148 | +| LangSAM | text-based (SAM2 backend) | `pip install segment-geospatial[text]` | |
0 commit comments