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

# GitHub token

> Switch GitHub tokens at runtime in Laravel Copilot SDK for per-user authentication in stdio or TCP mode sessions.

## Runtime switching of GitHub tokens

Use this when you want to run Copilot CLI with a per-user GitHub token from Socialite or a similar authentication flow.

<Note>
  Personal Access Tokens need the `Copilot Requests` permission. The same requirement likely applies to Socialite-based user tokens.
  If you cannot get a usable Socialite token, ask users to provide a PAT directly.
</Note>

This approach is available only in stdio mode.
You cannot switch this in TCP mode because the Copilot CLI process stays running.
If you set `github_token` or `use_logged_in_user` in TCP mode (`cli_url`), an error is raised.

<Note>
  The "Per-session GitHub token (v0.3.0+)" section below is available in TCP mode as well.
</Note>

## `github_token` option

This is an official SDK option.
The SDK passes the token to CLI through `COPILOT_SDK_AUTH_TOKEN`.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;

$config = array_merge(
    config('copilot'),
    [
        'github_token' => $user->github_token,
    ]
);

$response = Copilot::useStdio($config)->run(prompt: '...');
Copilot::stop(); // Dispose of the client carrying the user token
```

## `use_logged_in_user` option

When you set `github_token`, `use_logged_in_user` is automatically set to `false`.
This makes CLI ignore stored OAuth and `gh` CLI credentials and use only the explicit token.

You can also set `use_logged_in_user` to `true` explicitly:

```php theme={null}
$config = [
    'github_token' => $user->github_token,
    'use_logged_in_user' => true, // Explicitly enabled
];
```

If you set `use_logged_in_user` to `false` without `github_token`, the SDK adds `--no-auto-login`, so CLI does not auto-login.

## Per-session GitHub token (v0.3.0+)

Using the `gitHubToken` field in `SessionConfig`, you can specify a different GitHub token per session within the same CLI process (multi-tenant support).

This token is passed as a parameter in the `session.create` JSON-RPC call, so it is **available in both stdio mode and TCP mode**. Even in TCP mode where the CLI is already running, you can switch tokens per session.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\SessionConfig;

$response = Copilot::run(
    prompt: '...',
    config: new SessionConfig(gitHubToken: $user->github_token),
);
```

TCP mode example:

```php theme={null}
// CLI server is already running (TCP mode)
// You can pass a different user token per session
$response = Copilot::useTcp(url: 'tcp://127.0.0.1:12345')->run(
    prompt: '...',
    config: new SessionConfig(gitHubToken: $user->github_token),
);
```

This works independently from the client-level `github_token` (the token used when launching the CLI process).
Use this when you want to switch user tokens on a per-session basis.

<Info>
  For the latest updates, see the [GitHub repository](https://github.com/invokable/laravel-copilot-sdk).
</Info>


## Related topics

- [GitHub Actions - GitHub Copilot SDK for Laravel](/en/packages/laravel-copilot-sdk/github-actions.md)
- [Authentication - GitHub Copilot SDK for Laravel](/en/packages/laravel-copilot-sdk/auth.md)
- [Laravel Cloud - GitHub Copilot SDK for Laravel](/en/packages/laravel-copilot-sdk/laravel-cloud.md)
- [GitHub Copilot SDK for Laravel](/en/packages/laravel-copilot-sdk/index.md)
- [Laravel Package Skeleton — Official Package Starter Template](/en/blog/package-skeleton-introduction.md)
