Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 18:30 UTC
feat(cli): add --no-browser flag to link command
Adds a --no-browser flag to `composio link` (and `composio dev connected-accounts link`) that prints the authorization URL instead of auto-opening the browser, while still waiting for the connection to become ACTIVE. Also respected on the unmanaged-auth dashboard fallback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sarah Simionescu committed
Jul 13, 2026 at 15:08 UTC
b003baaf1f48cd5824bb058e94c06bbf4b9b0b03
3 files changed
+64
-14
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+36
-13
@@ -51,6 +51,13 @@ const noWait = Options.boolean('no-wait').pipe(
51
Options.withDescription('Do not wait for authorization; only print link info')
52
);
53
54
+const noBrowser = Options.boolean('no-browser').pipe(
55
+ Options.withDefault(false),
56
+ Options.withDescription(
57
+ 'Do not open the browser automatically; print the URL to open manually'
58
+ )
59
+);
60
+
61
const alias = Options.text('alias').pipe(
62
Options.withDescription(
63
'Alias to assign to the connected account. Required when creating an additional account for the same toolkit/auth config.'
@@ -82,7 +89,8 @@ const waitForActiveConnection = (
89
ui: TerminalUI,
90
client: RawComposioClient,
91
connectedAccountId: string,
85
- redirectUrl: string
92
+ redirectUrl: string,
93
+ noBrowser: boolean
94
) =>
95
Effect.gen(function* () {
96
yield* showRedirectUrl(ui, redirectUrl);
@@ -98,6 +106,8 @@ const waitForActiveConnection = (
106
if (!urlSchemeValid) {
107
yield* ui.log.warn(`Redirect URL has an unexpected scheme: ${redirectUrl}`);
108
yield* ui.log.info('Open the URL manually if you trust the source.');
109
+ } else if (noBrowser) {
110
+ yield* ui.log.info('Open the URL above in your browser to authorize.');
111
} else {
112
yield* Effect.tryPromise(() => open(redirectUrl, { wait: false })).pipe(
113
Effect.catchAll(error =>
@@ -178,7 +188,7 @@ const validateLinkResponse = (
188
});
189
});
190
181
-const handleNoManagedAuth = (ui: TerminalUI, toolkitSlug: string) =>
191
+const handleNoManagedAuth = (ui: TerminalUI, toolkitSlug: string, noBrowser: boolean) =>
192
Effect.gen(function* () {
193
const userContext = yield* ComposioUserContext;
194
const webURL = userContext.data.webURL.replace(/\/+$/, '');
@@ -202,12 +212,14 @@ const handleNoManagedAuth = (ui: TerminalUI, toolkitSlug: string) =>
212
const dashboardUrl = `${webURL}/${encodeURIComponent(orgName)}/~/connect/apps/${encodeURIComponent(toolkitSlug)}?open=true`;
213
214
yield* ui.log.warn(
205
- `Composio does not manage auth for "${toolkitSlug}" — opening the dashboard to connect manually.`
215
+ `Composio does not manage auth for "${toolkitSlug}" — ${noBrowser ? 'open the dashboard' : 'opening the dashboard'} to connect manually.`
216
);
217
208
- yield* Effect.tryPromise(() => open(dashboardUrl, { wait: false })).pipe(
209
- Effect.catchAll(() => ui.log.warn('Could not open the browser automatically.'))
210
- );
218
+ if (!noBrowser) {
219
+ yield* Effect.tryPromise(() => open(dashboardUrl, { wait: false })).pipe(
220
+ Effect.catchAll(() => ui.log.warn('Could not open the browser automatically.'))
221
+ );
222
+ }
223
224
yield* ui.note(dashboardUrl, 'Dashboard URL');
225
yield* ui.output(dashboardUrl);
@@ -468,6 +480,7 @@ const handleLegacyAuthConfigLink = (params: {
480
readonly requestedUserId: Option.Option<string>;
481
readonly projectName: Option.Option<string>;
482
readonly noWait: boolean;
483
+ readonly noBrowser: boolean;
484
readonly alias: Option.Option<string>;
485
readonly ui: TerminalUI;
486
readonly clientSingleton: {
@@ -593,7 +606,13 @@ const handleLegacyAuthConfigLink = (params: {
606
return;
607
}
608
596
- yield* waitForActiveConnection(params.ui, client, connectedAccountId, redirectUrl);
609
+ yield* waitForActiveConnection(
610
+ params.ui,
611
+ client,
612
+ connectedAccountId,
613
+ redirectUrl,
614
+ params.noBrowser
615
+ );
616
});
617
618
const runConnectedAccountsLink = (params: {
@@ -602,6 +621,7 @@ const runConnectedAccountsLink = (params: {
621
userId: Option.Option<string>;
622
projectName: Option.Option<string>;
623
noWait: boolean;
624
+ noBrowser: boolean;
625
alias: Option.Option<string>;
626
list: boolean;
627
rootOnly: boolean;
@@ -673,6 +693,7 @@ const runConnectedAccountsLink = (params: {
693
requestedUserId: params.userId,
694
projectName: params.projectName,
695
noWait: params.noWait,
696
+ noBrowser: params.noBrowser,
697
alias: aliasOption,
698
ui,
699
clientSingleton,
@@ -740,7 +761,7 @@ const runConnectedAccountsLink = (params: {
761
const slug = extractSlug(error);
762
763
if (slug === 'ToolRouterV2_NoManagedAuth') {
743
- yield* handleNoManagedAuth(ui, toolkitSlug);
764
+ yield* handleNoManagedAuth(ui, toolkitSlug, params.noBrowser);
765
return Option.none();
766
}
767
@@ -802,7 +823,7 @@ const runConnectedAccountsLink = (params: {
823
},
824
}).pipe(Effect.catchAll(() => Effect.void));
825
} else {
805
- yield* waitForActiveConnection(ui, client, connAccountId, redirectUrl);
826
+ yield* waitForActiveConnection(ui, client, connAccountId, redirectUrl, params.noBrowser);
827
yield* appendCliSessionHistory({
828
orgId: resolvedProject.projectType === 'CONSUMER' ? resolvedProject.orgId : undefined,
829
consumerUserId:
@@ -820,14 +841,15 @@ const runConnectedAccountsLink = (params: {
841
842
export const connectedAccountsCmd$Link = Command.make(
843
'link',
823
- { toolkit, authConfig, userId, projectName, noWait, alias, list },
824
- ({ toolkit, authConfig, userId, projectName, noWait, alias, list }) =>
844
+ { toolkit, authConfig, userId, projectName, noWait, noBrowser, alias, list },
845
+ ({ toolkit, authConfig, userId, projectName, noWait, noBrowser, alias, list }) =>
846
runConnectedAccountsLink({
847
toolkit,
848
authConfig,
849
userId,
850
projectName,
851
noWait,
852
+ noBrowser,
853
alias,
854
list,
855
rootOnly: false,
@@ -852,14 +874,15 @@ export const connectedAccountsCmd$Link = Command.make(
874
875
export const rootConnectedAccountsCmd$Link = Command.make(
876
'link',
855
- { toolkit, noWait, alias, list },
856
- ({ toolkit, noWait, alias, list }) =>
877
+ { toolkit, noWait, noBrowser, alias, list },
878
+ ({ toolkit, noWait, noBrowser, alias, list }) =>
879
runConnectedAccountsLink({
880
toolkit,
881
authConfig: Option.none(),
882
userId: Option.none(),
883
projectName: Option.none(),
884
noWait,
885
+ noBrowser,
886
alias,
887
list,
888
rootOnly: true,
ts/packages/cli/src/commands/root-help.ts
+5
-1
@@ -528,7 +528,7 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
528
],
529
}),
530
link: {
531
- usage: 'composio link [<toolkit>] [--no-wait] [--alias text] [--list]',
531
+ usage: 'composio link [<toolkit>] [--no-wait] [--no-browser] [--alias text] [--list]',
532
description:
533
'Connect an external account (GitHub, Gmail, Slack, etc.) so tools can act on your behalf. Opens a browser for OAuth authorization and waits for confirmation.',
534
args: [{ name: '<toolkit>', description: 'Toolkit slug to link (e.g. "github", "gmail")' }],
@@ -544,6 +544,10 @@ const SUBCOMMAND_HELP: Record<string, SubcommandHelp | TaggedValue<SubcommandHel
544
name: '--no-wait',
545
description: 'Print link info and exit without waiting for authorization',
546
},
547
+ {
548
+ name: '--no-browser',
549
+ description: 'Do not open the browser automatically; print the URL to open manually',
550
+ },
551
{
552
name: '--list',
553
description:
ts/packages/cli/test/src/commands/connected-accounts/connected-accounts.link.cmd.test.ts
+23
@@ -125,6 +125,29 @@ describe('CLI: composio dev connected-accounts link', () => {
125
);
126
});
127
128
+ layer(
129
+ TestLive({
130
+ baseConfigProvider: testConfigProvider,
131
+ connectedAccountsData: makeConnectedAccountsData(),
132
+ fixture: 'global-test-user-id',
133
+ })
134
+ )('[Given] --no-browser [Then] waits for ACTIVE without opening the browser', it => {
135
+ it.scoped('prints the URL and waits without calling open', () =>
136
+ Effect.gen(function* () {
137
+ yield* cli(['link', 'gmail', '--no-browser']);
138
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
139
+ const output = lines.join('\n');
140
+ const parsed = extractJsonObject(output);
141
+
142
+ expect(parsed).not.toBeNull();
143
+ expect(parsed?.status).toBe('success');
144
+ expect(parsed?.connected_account_id).toBe('con_test_link');
145
+ expect(output).toContain('https://app.composio.dev/link?token=lt_test_token');
146
+ expect(vi.mocked(open)).not.toHaveBeenCalled();
147
+ })
148
+ );
149
+ });
150
+
151
layer(
152
TestLive({
153
baseConfigProvider: testConfigProvider,