Skip to content

modapi link; init links an existing project or creates one (v0.4.0) - #14

Merged
chrisdengso merged 2 commits into
mainfrom
cli-link
Oct 23, 2026
Merged

chrisdengso merged 2 commits into
mainfrom
cli-link

Conversation

@chrisdengso

@chrisdengso chrisdengso commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

modapi link [project]: connect this directory to a project you already have.

  • Makes a new key for the project with POST /projects/{id}/api-keys (moderation-api/api#454). The key is named CLI · <directory> · <computer>. It writes MODAPI_SECRET_KEY and MODAPI_WEBHOOK_SECRET to the env file (.env.local for Next.js, else .env) and adds the file to .gitignore.
  • Name the project by ID or name (case-insensitive). A name matching several projects is refused, with the list. Without a project, it shows a picker in a terminal and lists the projects otherwise.
  • If the env file already has a key for another project, it asks first (--force in scripts). If the key is already for that project, it changes nothing.

init no longer always creates a project.

  • In a terminal it asks "Link an existing project, or create a new one?" with your projects listed. With no projects, it creates one as before.
  • Agents and scripts choose with --project <id or name> or --new. Without either, and with projects to choose from, init exits 2 and lists them, so the agent asks the user instead of guessing.
  • An env file that already has a working key still changes nothing (--force to link or create anyway).
  • Shared code: checkEnvFileWritable (refuse a committed env file before making anything) and writeProjectEnv.

Setup skill: moved to moderation-api/skills in #13; its link-or-create update goes there separately.

Tests

  • New: init with projects and no flag asks the agent to choose (exit 2, no writes); init --project forum links by name, case-insensitive, with key name CLI · …; --project and --new together are refused; an ambiguous name; replacing another project's key needs --force; linking the same project makes no key.
  • The existing init tests are updated for the project-list call. go test ./... passes.
  • Live, read-only, with the modapi login session: projects list uses the login key through the fallback from Find the key from .env or modapi login; clearer doctor output #11, and init -o json lists the organization's 6 projects with the --project / --new hints. I did not create a key in production.

Release: this branch is on top of the v0.4.0 regen commit (the new projects api-keys create command). Merging it releases v0.4.0 with link, the key fallback and the new doctor output, and supersedes #12.

🤖 Generated with Claude Code

chrisdengso and others added 2 commits October 23, 2026 16:15
- `modapi link [project]` connects this directory to a project you already
  have: it makes a new key for the project (POST /projects/{id}/api-keys,
  named after this computer and directory) and writes MODAPI_SECRET_KEY and
  MODAPI_WEBHOOK_SECRET to the env file. Without a project it lists them to
  pick from. It asks before replacing a key for another project (--force in
  scripts) and changes nothing when the key is already for that project.
- `init` no longer always creates a project. When the organization has
  projects it asks whether to link one or create a new one. Agents and
  scripts choose with --project <id or name> or --new; without either, init
  stops and lists the projects.
- The setup skill asks the user which project to use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chrisdengso
chrisdengso merged commit 2188bf8 into main Oct 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant