Repository navigation
Per-project GitHub account, for T3 Code and the agents it starts #15383
TonybynMp4
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
I'm logged into two GitHub accounts in
gh, a personal one and a work one. Most of my GitHub work is personal, but some open source repos we use at work need the work account.More than once, an agent running in T3 Code opened a pull request or an issue under the wrong account. Agents call
ghthemselves, andghuses whichever account is active. T3 Code starts every agent with the same environment, so nothing ties a project to an account. Some agents also rungh auth switchwhen a call fails, which changes the account for every session after it.Wrong-account posts are public and hard to undo. Pull requests can't be deleted at all, and issues only by a repo admin, so the post usually stays up while I repost from the right account.
What exists
GH_TOKENset, used as the work projects' default model, works today. But it's chosen per thread, not enforced per project: picking the other instance in the model picker brings the wrong account back. It also means pasting a copy of the token into settings, once per provider.GH_TOKENis the right variable, and it would still mean storing a token.Proposal
A GitHub account setting in project settings. It lists the accounts
gh auth statusreports for the project's host, plus "Default (activeghaccount)", which keeps today's behavior.When a project has an account selected:
gh auth token --hostname <host> --user <login>. This is the Per-project GitHub CLI account selection #13103 part, built on fix(pull-requests): scope GitHub reads and viewers to each workspace #14218's per-credential reads.GH_TOKEN(GH_ENTERPRISE_TOKENon Enterprise hosts) in the provider process's environment, from the same lookup. Every command the agent runs inherits it.GH_TOKENtakes priority over the active account, soghacts as the chosen account even after agh auth switch. MCP servers that read a token from their environment can reference the same variable. The agent isn't told anything and can't skip a step.This needs no new plumbing in the adapters. Every adapter already adds per-session variables to the provider process at spawn, for the agent device tools (
withAgentDeviceEnvironmentinapps/server/src/mcp/McpProviderSession.ts). The token would go in the same place.T3 Code doesn't store the token. It's read from
ghwhen a session starts, so the keyring stays the source of truth and token rotation needs no settings change.Changing the account
The account is looked up when a session starts, so existing threads pick up the setting the next time their agent starts. After an update, that's the first message in each thread, since the server restart stops every agent process.
Changing the setting while sessions are running must not leave any turn on the old account, except the one already in progress. T3 Code already restarts a thread's session at the start of a turn when its runtime mode, working directory, or provider instance changed, and resumes the conversation (
ProviderCommandReactor). The session would also record the account it started with, and a mismatch would trigger the same restart:Moving a thread to another project works the same way: its next turn uses the new project's account.
If the selected account is no longer logged in, settings and the PR view say so, and new turns in that project fail with that message. T3 Code doesn't fall back to the active account, because that fallback is the exact failure this setting is meant to prevent.
Out of scope
includeIf).glabreadsGITLAB_TOKEN, so the same shape could work later.Questions for maintainers
gh auth tokenand get the active account's token, so this narrows access more than it widens it.t3.json), or as a per-project override in Source Control settings, as Per-project GitHub CLI account selection #13103 suggests?I'm happy to implement this, with focused tests, once #14218 lands. I can also test #14218 with two real accounts in the meantime, since its PR notes that hasn't been done.
All reactions