> ## Documentation Index
> Fetch the complete documentation index at: https://docs.checkfu.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Checkfu is open source (https://github.com/checkfu/checkfu) and runs in the reader's own Cloudflare account. There is no shared hosted base URL: `checkfu deploy` prints the deployment's API URL (`https://<api-worker>.workers.dev` or the CHECKFU_API_DOMAIN hostname, exported as `CHECKFU_BASE_URL` for the CLI, SDK, and curl) and MCP URL (`.../mcp`). Local development serves the API on http://localhost:1337 and MCP on http://localhost:1338/mcp.
> Authenticated HTTP requests send the deployment's CHECKFU_API_KEY as `Authorization: Bearer $CHECKFU_API_KEY` (or `x-api-key`) and `Content-Type: application/json` for JSON bodies. Pass `Idempotency-Key` on retriable writes.
> Core workflow: create an Agent (`POST /v1/agents`) and an Environment (`POST /v1/environments`), create a Session that references both (`POST /v1/sessions`), send a `user.message` event (`POST /v1/sessions/{session_id}/events`), and follow `GET /v1/sessions/{session_id}/events/stream` until `session.status_idle`.
> Other resources: Memory stores (`/v1/memory_stores`), Files (`/v1/files`), Artifacts (`/v1/artifacts`), Vaults and credentials (`/v1/vaults`), Provider credentials (`/v1/provider_credentials`), Automations (`/v1/automations`), Inbound bindings (`/v1/inbound_bindings`), and Webhooks (`/v1/webhooks`). The deployment serves its OpenAPI 3.1 specification at `GET /openapi.json`.

# Work on a GitHub repository

> Mount a GitHub repository in a Session so the agent can fetch and push with a scoped token.

Mount a repository when you create a Session. Checkfu clones it into `/workspace` so the agent can use `git` normally, while keeping your token out of the agent's container and attaching it only on outbound traffic to that repository.

## Mount the repository

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import Checkfu from "@checkfu/sdk"

const client = new Checkfu()

const session = await client.waitForPending(
	await client.sessions.create({
		agent: process.env.AGENT_ID!,
		environment_id: process.env.ENVIRONMENT_ID!,
		resources: [
			{
				type: "github_repository",
				url: "https://github.com/acme/api",
				authorization_token: process.env.GITHUB_TOKEN!,
				checkout: { type: "branch", name: "main" },
			},
		],
		initial_events: [
			{
				type: "user.message",
				content: [
					{
						type: "text",
						text: "Fix the failing test in /workspace/api on a branch named fix/flaky-test, then commit and push it.",
					},
				],
			},
		],
	}),
)

for await (const event of await client.sessions.events.stream(session.id)) {
	if (event.type === "agent.message") console.log(event.content.map((block) => block.text).join(""))
	if (event.type === "session.error") console.error(event.error.type, event.error.message)
	if (event.type === "session.status_idle" || event.type === "session.status_terminated") break
}
```

The token needs read access to the repository, plus write access if you want the agent to push. Set `access: "read_only"` on the resource to block pushes (see [Create a session](https://docs.checkfu.com/api-reference/sessions/create-a-session.md)).

The Session's Environment must allow `github.com`. The default `unrestricted` networking does; under `limited` networking, add `github.com` to `allowed_hosts`. See [Environments](https://docs.checkfu.com/concepts/environments.md).

## What the agent can do

`origin` points to the `https://github.com/...` URL, so `git fetch`, `pull`, and `push` work normally through `bash`. The initial clone is shallow (`--depth 1`).

Checkfu attaches the token only to HTTPS requests targeting the mounted repository on `github.com`. Other repositories and `api.github.com` do not receive it, so the agent cannot open a pull request with it. Open the PR from your app after the push, or attach a GitHub MCP server to the Agent.

## Rotate the token

GitHub App installation tokens expire quickly. To replace a token, set `SESSION_ID` to the live Session and `NEW_GITHUB_TOKEN` to the replacement token. Use the same SDK client and set `repositoryUrl` to the full URL of the mounted repository.

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
const sessionId = process.env.SESSION_ID
const token = process.env.NEW_GITHUB_TOKEN
const repositoryUrl = "https://github.com/acme/api"
if (!sessionId || !token) {
	throw new Error("Set SESSION_ID and NEW_GITHUB_TOKEN before rotating the token.")
}

const { data } = await client.sessions.resources.list(sessionId)
const [repository, duplicate] = data.filter(
	(resource) =>
		resource.type === "github_repository" &&
		resource.url.toLowerCase() === repositoryUrl.toLowerCase(),
)
if (repository === undefined) {
	throw new Error(`The repository ${repositoryUrl} is not mounted in Session ${sessionId}.`)
}
if (duplicate !== undefined) {
	throw new Error(
		`Session ${sessionId} lists more than one mount for ${repositoryUrl}. Use the intended mount ID.`,
	)
}
await client.sessions.resources.update(sessionId, repository.id, { authorization_token: token })
```

The next git request uses the new token. Archiving the Session discards both the clone and the token, so make sure the agent pushes before you archive.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.