paperclipai/paperclip · error · Error
Company is required for agent profiles
Error message
Company is required for agent profiles
What it means
Thrown at the start of the agent-profile connection flow if chooseCompany(...) returns null even though it was called with optional:false. It is a defensive guard after a selection that, by contract, should never yield null.
Source
Thrown at cli/src/commands/client/connect.ts:126
tokenCreatedAt: key.createdAt,
}, opts.context);
setCurrentProfile(profileName, opts.context);
p.outro(pc.green(`Connected profile '${profileName}' as board.`));
return {
ok: true,
profile: profileName,
persona: "board",
apiBase,
companyId: company?.id ?? null,
key: publicKeyResult(key),
exports: buildExports({ apiBase, companyId: company?.id, agentId: undefined, envName: apiKeyEnvVarName, token: key.token }),
};
}
const company = await chooseCompany(companies, opts.companyId ?? resolvedProfile.profile.companyId, {
optional: false,
});
if (!company) throw new Error("Company is required for agent profiles");
const agents = (await boardApi.get<Agent[]>(apiPath`/api/companies/${company.id}/agents`)) ?? [];
if (agents.length === 0) throw new Error(`Company '${company.name}' has no agents to connect.`);
const agent = await chooseAgent(agents, resolvedProfile.profile.agentId);
const tokenName = opts.tokenName?.trim() || `cli-agent-${new Date().toISOString()}`;
const key = await boardApi.post<CreatedAgentKey>(apiPath`/api/agents/${agent.id}/keys`, createAgentKeySchema.parse({ name: tokenName }));
if (!key) throw new Error("Failed to create agent token");
upsertProfile(profileName, {
apiBase,
companyId: company.id,
persona: "agent",
agentId: agent.id,
agentName: agent.name,
apiKeyEnvVarName,
tokenName: key.name,
tokenId: key.id,
tokenCreatedAt: key.createdAt,
}, opts.context);
setCurrentProfile(profileName, opts.context);View on GitHub (pinned to 67001ec6eb)
Solutions
- Verify the board credential returns at least one company via GET /api/companies before running connect.
- If you genuinely hit this, file a bug: with optional:false the throw should be unreachable.
Defensive patterns
Strategy: validation
Validate before calling
// Before calling connect, ensure the board credential can see companies.
const companies = (await boardApi.get('/api/companies')) ?? [];
if (companies.length === 0) {
throw new Error('Create a company in the board UI before connecting an agent profile.');
} Prevention
- Always create at least one company before running `paperclipai connect`.
- Smoke-test the board credential with GET /api/companies first.
When it happens
Trigger: Effectively unreachable: chooseCompany(companies, preferredCompanyId, {optional:false}) throws on an empty companies list and returns companies[0] for a single-item list, so a null return cannot occur through its documented paths.
Common situations: Encountered only if chooseCompany's contract is violated (e.g., a future refactor changes its return semantics) or the companies array is mutated to an unexpected shape mid-call.
Related errors
- Agent selection failed
- `paperclipai connect` is interactive. For scripts, pass --ap
- Failed to create board token
- Company '${company.name}' has no agents to connect.
- Failed to create agent token
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/8e65aeba365d3c06.
Report an issue: GitHub.