# CSV add row number

`csv-add-row-number` · version 1.0.0 · CSV & tables · free, no key needed

Prepend a 1-based row_number column of canonical integer strings.

**Use when you need to: csv add row number · csv row numbers · enumerate csv rows.**

## Supported

- csv add row number
- csv row numbers
- enumerate csv rows

## Not supported

- 0-based
- gap fill
- sort

## Behavior

- Reuse baseline CSV parser/stringifier and limits.
- column_name defaults to row_number. Must be a non-empty string within header byte limit.
- If column_name already exists, reject.
- Insert the new column at index 0. Values are "1", "2", ... canonical integers.
- Empty document -> csv "". Header-only -> new header plus original headers and zero data rows.
- Adding the column must not exceed max_columns.

## Input

- `csv` (string, required): max length 256000
- `column_name` (string, optional): min length 1; max length 256

## Output

- `csv` (string, required)
- `rows_in` (integer, required)

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256

## Example

Request input:

```json
{
  "csv": "k\na\nb\n"
}
```

Response:

```json
{
  "result": {
    "csv": "row_number,k\n1,a\n2,b\n",
    "rows_in": 2
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-add-row-number",
  "version": "1.0.0",
  "input": {
    "csv": "k\na\nb\n"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/csv-add-row-number/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"csv":"k\na\nb\n"}'
```

The machine-readable contract is at [/v1/tools/csv-add-row-number/versions/1.0.0](/v1/tools/csv-add-row-number/versions/1.0.0).

### CLI

```sh
node cli.mjs run csv-add-row-number 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [CSV row diff](/tools/csv-row-diff): Compare two CSV documents with identical headers by unique key tuples and report added, removed, and changed rows.
- [CSV slice rows](/tools/csv-slice-rows): Take a contiguous window of CSV data rows by offset and limit, keeping the header.
- [CSV anti join](/tools/csv-anti-join): Keep left CSV rows whose exact key tuples do not appear in the right document.
- [CSV concat](/tools/csv-concat): Concatenate CSV documents that share identical headers, preserving document and row order.
- [CSV dedupe](/tools/csv-dedupe): Remove duplicate CSV data rows while preserving the first occurrence.
- [CSV group count](/tools/csv-group-count): Count CSV rows by exact named-column tuples in first-seen order.
