---
title: "List repository files"
method: POST
path: "/api/v2/code/listFiles"
tags: ["Code"]
---

# List repository files

`POST /api/v2/code/listFiles`

## Request

- Base URL: `https://zeropath.com`
- URL: `https://zeropath.com/api/v2/code/listFiles`
- Auth: API key in header `X-ZeroPath-API-Token-Id` and API key in header `X-ZeroPath-API-Token-Secret`

List files and directories under a repository path. Use this to explore the repository structure before reading specific files with `code.read`. Returns file names, types (file or directory), and sizes. Supports pagination via cursor for large directories. Supports GitHub and GitLab repositories (not Bitbucket).

## Request body

- CodeListFilesRequest
  - `organizationId` string: Organization that owns the repository.
  - `repositoryId` string, required: Repository to list files from.
  - `ref` string: Branch, tag, or commit SHA to list files from. Omit to use the repository's default branch.
  - `path` string: Directory path relative to the repository root to list contents of (e.g. "src/services"). Omit or pass empty string to list the repository root.
  - `cursor` string: Opaque pagination cursor returned as `nextCursor` from a previous response. Pass this to fetch the next page of results.
  - `limit` integer: Maximum number of file/directory entries to return per page. Defaults to 100.

## Response `200`

Directory entries

- CodeListFilesResponse
  - `provider` 'github' | 'gitlab', required: Repository provider that served the request. Only providers with native code-inspection APIs are supported.
  - `repositoryId` string, required
  - `ref` string, nullable, required
  - `path` string, required
  - `hasMore` boolean, required
  - `nextCursor` string, nullable, required
  - `items` CodeListFilesItem[], required
    - `path` string, required
    - `name` string, required
    - `type` 'file' | 'dir', required
    - `size` integer, nullable, required

## Other responses

- `400`: Error Response
- `401`: Error Response
- `403`: Error Response
- `404`: Error Response

---

[API](https://skmtc.dev/zeropath/apis/zeropath-api.md) - [All operations](https://skmtc.dev/zeropath/apis/zeropath-api/llms.txt) - [OpenAPI document](https://skmtc.dev/zeropath/apis/zeropath-api/revisions/126e9c80ba0d?raw)
