Downloading code
Download a repository archive as a stream or get an authenticated clone URL.
There are two ways to get repository contents: repos.downloadArchive streams a zip or tar.gz
archive at a ref, or you clone an authenticated remote. For cloning, repos.getCloneUrl returns a URL
with the credential embedded — treat it as a secret and never log it — while
repos.getCloneCredentials returns that credential next to a credential-free URL.
Downloading an archive
repos.downloadArchive resolves a ref to a snapshot and returns an Archive whose stream is a
Web-standard ReadableStream<Uint8Array>:
repo?string
The repository, in the provider path form.
stringref?string
Branch, tag, or SHA to snapshot.
stringformat?'zip' | 'tar.gz'
Archive format. Defaults to 'zip'. Must be in capabilities.archiveFormats.
'zip' | 'tar.gz'const archive = await client.repos.downloadArchive({
repo: 'capawesome-team/repo-sdk',
ref: 'v1.0.0',
format: 'zip',
});
// archive: { stream: ReadableStream<Uint8Array>, contentType?: string, filename?: string }
Because it’s a stream, you can pipe it straight to disk without buffering the whole archive in memory:
import { createWriteStream } from 'node:fs';
import { Writable } from 'node:stream';
const archive = await client.repos.downloadArchive({
repo: 'capawesome-team/repo-sdk',
ref: 'v1.0.0',
format: 'tar.gz',
});
const file = createWriteStream(archive.filename ?? 'archive.tar.gz');
await archive.stream.pipeTo(Writable.toWeb(file));
For the per-provider format rules and when buffering beats streaming, see downloading repository archives programmatically.
Getting a clone URL
repos.getCloneUrl returns a CloneUrl you can hand to git clone:
url?string
The clone URL with the resolved credential embedded.
stringexpiresAt?Date
When the embedded credential expires (e.g. GitHub App tokens, ~1h).
Dateconst clone = await client.repos.getCloneUrl({ repo: 'capawesome-team/repo-sdk' });
// clone: { url, expiresAt? }
Expiring credentials
expiresAt is set when the embedded token has a lifetime — most notably GitHub App installation tokens
(~1 hour). Re-fetch the clone URL once it’s past expiresAt rather than caching it indefinitely.
Azure DevOps with Entra auth
Both an OAuth accessToken and an Entra ID tokenProvider embed the token in the URL with the
oauth2 username (https://oauth2:<token>@dev.azure.com/...). Entra tokens are short-lived
(typically ~1 hour) and the URL carries no expiresAt, so fetch the clone URL just before cloning
rather than storing it.
Getting clone credentials
repos.getCloneCredentials returns the same credential split from the URL, so you can feed it to a
git credential helper instead of persisting a tokenized remote in .git/config:
expiresAt?Date
When the credential expires (e.g. GitHub App tokens, ~1h).
Datepassword?string | null
The secret. Null when the provider carries the token in username, or when access is anonymous.
string | nullurl?string
The clone URL, without any embedded credential.
stringusername?string | null
The username the provider expects. Null for anonymous access.
string | nullconst { url, username, password } = await client.repos.getCloneCredentials({
repo: 'capawesome-team/repo-sdk',
});
// url: 'https://github.com/capawesome-team/repo-sdk.git'
username and password are raw values — percent-encode them yourself if you put them back into a
URL. getCloneUrl is exactly that: these credentials embedded as userinfo.
Two shapes need a branch. Gitea passes the token as the username with no password, so password is
null. A git-http remote configured without auth clones anonymously, so both are null.
Next: Managing webhooks
Register and manage repository webhooks.