Skip to content

feat(setup): name the project token environment variable - #214

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/name-project-token-env-var
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog/name-project-token-env-var

Conversation

@posthog

@posthog posthog Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Why

The SDK watcher loop found drift between the setup spec and the SDKs: the spec settles what the project credential is called on every configuration surface it names (options object, provider props, manifest / Info.plist key), but says nothing about the environment variable an SDK reads when it is initialized without an explicit token — and the SDKs that read one disagree.

Source changes

  • posthog-php#311 — PostHog::init() and the Laravel package now read POSTHOG_PROJECT_TOKEN, falling back to the deprecated POSTHOG_API_KEY. The PR calls this a gap in the spec rather than a divergence from it.
  • @posthog/mcp (posthog-js) already reads POSTHOG_PROJECT_TOKEN.
  • posthog-rs (src/lib.rs), the posthog-rails logs setup and install generator template, and the @posthog/ai integrations still read only POSTHOG_API_KEY.

What changed

New Project token environment variable name requirement in setup:

  • where an SDK reads the token from the environment, the variable is POSTHOG_PROJECT_TOKEN;
  • an SDK that already reads POSTHOG_API_KEY keeps it as a deprecated fallback under the existing "Deprecated project credential alias" rules, with the new name winning when both are set;
  • a blank or whitespace-only value falls back as if unset;
  • reading no environment variable at all stays conformant — the requirement names the variable, it does not require one.

Proposed, applied and archived on this branch per AGENTS.md: openspec/changes/archive/2026-11-12-name-project-token-env-var/. openspec validate setup --type spec --strict reports no errors (only the pre-existing requirement-length warnings).

Uncertain / needs review

  • Only posthog-php and @posthog/mcp ship the new name today. Adopting this requirement means posthog-rs, posthog-ruby and @posthog/ai add POSTHOG_PROJECT_TOKEN ahead of their old variable — flagged as a follow-up in tasks.md, not done here. If the preference is to leave environment variables outside the contract, this change should be dropped rather than narrowed.
  • The scenarios are written in the spec's own style but have no harness step bindings yet.

Created with PostHog Desktop

🤖 Generated with Claude Code

The setup spec settles the project token's name on every configuration surface it names, but
not on the environment variable an SDK reads when it is initialized without an explicit token.
posthog-php now reads POSTHOG_PROJECT_TOKEN with POSTHOG_API_KEY as a deprecated fallback, and
@posthog/mcp reads POSTHOG_PROJECT_TOKEN, while posthog-rs and the posthog-rails logs setup read
only POSTHOG_API_KEY. Pin POSTHOG_PROJECT_TOKEN as the name, keep POSTHOG_API_KEY as a deprecated
fallback under the existing alias rules, and treat a blank value as unset.

Tested: openspec validate setup --type spec --strict (no errors; pre-existing length warnings
only), then openspec archive.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 3ed34237-1d4d-4d16-b517-7f4622b1c9f5
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.

0 participants