resolveMode treated --api-key as a non-interactive marker and
short-circuited to MCP, but --api-key is equally valid for CLI +
Skills mode (which authenticates skill downloads). Users who
preferred CLI mode were silently locked into MCP unless they
also passed --cli.
Remove options.apiKey from the auto-MCP OR-chain. --mcp / --cli /
--stdio / --oauth / -y still skip the prompt; --api-key alone now
falls through to the interactive mode picker.
* fix(cli): wire --antigravity and remove broken --universal in setup
The setup command advertised --universal and --antigravity flags but
neither was wired through getSelectedAgents, so passing them silently
fell back to auto-detection and wrote to the wrong directory (see #2695).
Remove --universal from setup entirely, and add a full Antigravity
SetupAgent config: skills under .agent/skills, MCP config at
~/.gemini/antigravity/mcp_config.json with serverUrl for HTTP, and
detection of .agent or ~/.gemini/antigravity.
* fix(cli): align antigravity setup with official Google docs
After verifying against Google Codelabs / Google Cloud Community
docs, correct the Antigravity config:
- MCP global path: ~/.gemini/config/mcp_config.json (Antigravity 2.0
shared config, replacing the older ~/.gemini/antigravity/ path
which an outdated github/github-mcp-server install guide cited).
- HTTP key: httpUrl (Gemini convention; antigravity is Gemini-based).
The previous serverUrl was sourced from the same outdated guide.
- Rule: append to GEMINI.md / ~/.gemini/GEMINI.md (Antigravity reads
Gemini-family rules, not a vendor-specific file).
- Project MCP: none documented; projectPaths is empty and setupAgent
/ remove falls back to globalPaths so --project --mcp still writes
to the correct location.
Skills stay at .agent/skills to keep the in-repo IDE_PATHS convention
consistent across setup, skill, and generate commands.
* chore(cli): move Antigravity to 5th in agent selection list
Match the natural ordering users expect in the checkbox prompt:
Claude Code, Cursor, OpenCode, Codex, Antigravity, Gemini CLI.
* fix(cli): antigravity HTTP key is serverUrl, not httpUrl
Antigravity rejects the entry with "serverURL or command must be
specified" when given httpUrl. Switch the HTTP entry back to
serverUrl (the github-mcp-server install guide had this right even
though its file path was outdated).
Also tighten the empty-projectPaths fallback in remove.ts: it
incorrectly leaked global state into project-scope detection,
making `remove --project` report Antigravity whenever a global
~/.gemini/config/mcp_config.json existed. Project-scope detect/
remove now no-ops for agents with no project-level MCP, while
setup still falls back to the global path so --project --mcp
--antigravity writes to the file Antigravity actually reads.
* fix(cli): wire --antigravity into the remove command
Symmetric to the setup fix: --antigravity was missing from
UninstallOptions and getSelectedAgents, so users had no CLI path
to undo a `ctx7 setup --antigravity` install.
* Add JSON output for skills list
* test(cli): resolve tempDir via realpath for macOS compatibility
On macOS, os.tmpdir() returns /var/folders/... but process.cwd()
reports the symlink-resolved /private/var/folders/... after chdir.
The JSON output uses the resolved cwd, so the test assertion mismatched
the unresolved tempDir on macOS.
* chore: add changeset for skills list --json
---------
Co-authored-by: Fahreddin Özcan <ozcanfahrettinn@gmail.com>
* fix(cli): declare @inquirer/core as direct dependency
selectOrInput.ts imports from @inquirer/core directly, but the package
was only resolvable as a transitive of @inquirer/prompts. Under pnpm's
isolated linker this fails with ERR_MODULE_NOT_FOUND at startup.
Fixes#2651
* chore: add changeset
* fix(cli): validate skill names to prevent path traversal on install
Adds boundary validation and containment checks so a remote SKILL.md
with a malicious name field (e.g. `name: ..`) cannot escape the skills
root during `ctx7 skills install`. Previously, the value flowed from
parseSkillFrontmatter to installSkillFiles unchecked, and the existing
traversal guard only verified files stayed inside the attacker-chosen
directory rather than the real skills root, enabling arbitrary file
writes outside `.claude/skills` (e.g. `.claude/settings.json` for
hook-driven RCE). symlinkSkill had the same trust issue and could
`rm(recursive: true)` arbitrary directories.
* chore: add changeset for skill name validation
* chore: soften changeset wording
readJsonConfig only caught file-read errors, not JSON.parse errors.
During `ctx7 remove`, the detector iterates every agent's well-known
config path; an unparseable JSON file at any of them (e.g. a
hand-edited ~/.claude.json) crashed the command with an unhandled
SyntaxError before it could do anything.
Wrap the readJsonConfig call in hasMcpConfig with a try/catch that
logs a warning naming the path and parse error and skips that agent.
Keep readJsonConfig itself strict so write paths in setup and
uninstallMcp continue to surface failures via their existing handling.
* fix(cli): support Windows backslash in skill installation path check
* chore(cli): add changeset for Windows path check fix
* style(cli): format Windows path guard
---------
Co-authored-by: Fahreddin Özcan <ozcanfahrettinn@gmail.com>
* feat(cli): add Gemini CLI support to setup command
Adds Gemini CLI as a supported agent in `ctx7 setup`. Configures MCP
server in `.gemini/settings.json` using `httpUrl` (Gemini's HTTP
streaming transport), appends rules to `GEMINI.md`, and installs skills
to `.gemini/skills/`. Also adds a permission fix tip when skill
installation fails with EACCES.
* chore: add changeset for Gemini CLI setup
* fix(cli): use GITHUB_TOKEN for skill downloads to avoid rate limits
Closes#2363
* chore: add changeset for gh ratelimit fix
* fix(cli): fallback to gh auth token for skill downloads
Supports private repos and users with gh CLI but no env vars set.
Closes#2369
* feat(cli): support installing skills from private/unindexed repos
When the Context7 backend doesn't know about a repo, the CLI now falls
back to fetching the repo tree from GitHub directly, parsing SKILL.md
frontmatter locally, and downloading skill files. Uses GitHub API status
codes to differentiate non-existent repos from repos without skills.
Closes#2369
* fix(setup): allow re-selecting already configured agents and overwrite existing MCP config
Previously, agents with existing Context7 MCP config were disabled in the
selection prompt with "(already configured)" and their config was never
updated. This made it impossible to reconfigure an agent (e.g. rotate API
key or fix a broken URL) without manually editing config files.
Now all agents are always selectable, existing config is overwritten with
fresh entries on re-setup, and TOML replacement correctly handles
sub-sections like http_headers.
* fix(setup): eliminate double file read and whitespace drift in TOML overwrite
Inline the server existence check into appendTomlServer to avoid reading
the file twice. Normalize whitespace around the replaced block so repeated
re-configurations do not accumulate blank lines.
* chore: add patch changeset for setup reconfiguration fix
* fix(setup): resolve all OpenCode config file variants for MCP setup
OpenCode supports 4 config file names (opencode.json, opencode.jsonc,
.opencode.json, .opencode.jsonc) but setup only checked opencode.json
and opencode.jsonc. Users with dotfile variants were never detected as
"already configured" and setup would create a duplicate opencode.json.
Changed mcp.projectPath/globalPath (single string) to
mcp.projectPaths/globalPaths (string[]) so agents can declare all valid
config paths. resolveMcpPath now takes the full candidates array and
returns the first existing file, falling back to the first entry.
Closes#2313
* chore: add patch changeset for OpenCode config variant fix
* refactor(setup): update rule template to be selective with examples
Based on eval benchmarks showing that selective rules with explicit
should/should-not examples achieve 98% recall with 0 false positives,
vs the previous broad rule.
Split RULE_CONTENT into MCP_RULE_CONTENT and CLI_RULE_CONTENT to
support both MCP and CLI setup modes with appropriate tool references.
* feat(setup): install CLI rule alongside skill in ctx7 setup --cli
Previously, CLI setup mode only installed the find-docs skill (66% trigger
rate). Now it also installs a rule file with ctx7 CLI instructions for each
selected agent, matching the MCP setup behavior.
Benchmarks show skill + rule achieves 96-98% trigger rate vs 66% skill-only.
* feat(find-docs): update skill description to improve trigger rate
Replace passive description with pushy version that explicitly names common
libraries and counters Claude's undertriggering tendency.
Eval results: 66% -> 98% clean recall, 72% -> 92% with-context recall.
* chore(setup): remove deprecated RULE_CONTENT export and alwaysApply frontmatter
alwaysApply is not a Claude Code feature (it's Cursor-specific). Claude Code
rules without paths frontmatter load unconditionally by default. Remove the
deprecated alias now that all callers use MCP_RULE_CONTENT or CLI_RULE_CONTENT.
* refactor(setup): fetch rules from GitHub, add alwaysApply for Cursor
- Rule source of truth in rules/context7-mcp.md and rules/context7-cli.md
- templates.ts fetches from GitHub raw (master then main)
- getRuleContent(mode, agent) adds alwaysApply frontmatter for Cursor
- CLI setup now logs rule install failures instead of silently swallowing
* refactor(setup): add Codex agent, remove needsAlwaysApply field, use shared installRule
- Add Codex agent config with AGENTS.md append support
- Remove needsAlwaysApply field (hardcoded cursor check in templates.ts)
- CLI setup uses shared installRule instead of inline CLI_RULE_PATHS
- installRule handles both file-based (Claude/Cursor/OpenCode) and
append-based (Codex/AGENTS.md) rule installation
* refactor(setup): unify CLI setup with MCP agent picker, group output by agent
- CLI setup now uses the same agent picker as MCP setup (no auto-detection)
- Output grouped by agent instead of repeating find-docs for each path
- Removed unused promptForInstallTargets/getTargetDirs imports
* fix(setup): add branch fallback URL for rule fetch, show error on rule failure
* fix(setup): OpenCode uses AGENTS.md, fix append logic for existing files
- OpenCode rule changed from .opencode/rules/ to AGENTS.md (append type)
since OpenCode reads AGENTS.md natively, not a rules directory
- Fixed append logic: proper spacing for empty/non-empty files, clean
idempotent replacement on re-run, preserves existing content
* test(setup): add tests for rule install, MCP config, and AGENTS.md append
* chore(setup): remove unused mergeInstructions and instructionsGlob
* fix: lint formatting, add changeset
* fix(setup): Codex global rule goes to ~/.codex/AGENTS.md
* fix(setup): align CLI output format with MCP output
* feat(setup): add --codex flag for MCP and CLI setup
* docs(rules): align trigger language with skill, use npx ctx7@latest in CLI rule
* docs(rules): prefer ctx7 over web search for library docs
* docs(find-docs): prefer skill over web search in description
* docs(rules): consolidate trigger language, add selection criteria
* docs(rules): add query quality guidance and auth env var to CLI rule
* cleanup
* fix: remove branch URL, add offline fallback matching rule files exactly
* fix(setup): support opencode.jsonc, strip JSON comments, fix detect path
- readJsonConfig now strips // and /* */ comments before parsing (JSONC support)
- resolveMcpPath checks for .jsonc variant when .json is specified
- OpenCode detect paths include both opencode.json and opencode.jsonc
- Fixed OpenCode project path from .opencode.json to opencode.json
* fix(setup): fix JSONC comment stripping to preserve URLs in strings
The regex-based comment stripper was matching // inside string values
(e.g., https:// URLs), corrupting the JSON. Replaced with a character-
level parser that skips string literals before stripping comments.
* fix(setup): Codex uses TOML config.toml, detect .opencode.json variant
- Codex MCP writes to ~/.codex/config.toml using [mcp_servers.context7]
TOML sections instead of JSON (matches Codex docs and add-mcp tool)
- OpenCode detection checks opencode.json, opencode.jsonc, and .opencode.json
- Added TOML server block writer with idempotent append
- stripJsonComments now handles URLs in strings correctly
* test(setup): add JSONC, TOML, and resolveMcpPath tests
12 new tests covering:
- JSONC: comment stripping preserves URLs, block comments, plain JSON
- resolveMcpPath: .jsonc resolution, .json fallback, non-json passthrough
- TOML: buildTomlServerBlock output, http_headers, readTomlServerExists,
appendTomlServer (empty file, preserve existing, idempotent)
* fix(setup): Codex MCP needs type=http, fix checkbox disabled item selection
- Codex TOML entry now includes type = "http" (required by Codex)
- Checkbox cursor starts on first non-disabled item
- Checkbox navigation skips disabled items
* fix: address PR review feedback on rules and skill description
- Surface libraryId format (/org/project) in step 2 where selection happens
- Suggest retrying with alternate names/queries instead of just punctuation
- MCP rule: explicitly require resolve-library-id unless /org/repo provided
- Skill description: explicitly warn against relying on training data for APIs
* fix: consistent /org/project format in MCP rule
* fix: revert opencode detection paths to original
* fix(cli): use ~/.agents/skills for global universal skill installs
The universal global path was ~/.config/agents/skills, but the
canonical standard (used by Vercel's skills CLI and OpenAI Codex)
is ~/.agents/skills. This aligns context7 with the broader ecosystem.
Fixes#2276
* chore: add changeset for global skills path fix
* fix(cli): remove shell:true from spawn in generate command
Removes shell:true from the child_process.spawn() call that opens
the user's editor. The editor path and preview file path are already
passed as separate arguments, so shell interpolation is unnecessary.
Using shell:true allows shell metacharacters in EDITOR or file paths
to be interpreted, which is a command injection vector.
Fixes#2240
This contribution was developed with AI assistance (Claude Code).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: add changeset for shell:true removal
---------
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Fahreddin Özcan <ozcanfahrettinn@gmail.com>
* fix(cli): prevent directory traversal in skill file installation
installSkillFiles() used path.join() with unsanitized file paths from
GitHub API responses. A malicious skill repository could include files
with "../" sequences in their paths, allowing writes outside the
intended skill directory.
Changes:
- installer.ts: use path.resolve() and verify the resolved path stays
within the skill directory boundary before writing
- github.ts: reject file paths containing ".." at download time as an
additional defense-in-depth check
* chore: add changeset for directory traversal fix
* fix: format installer.ts to pass prettier lint
---------
Co-authored-by: Fahreddin Özcan <ozcanfahrettinn@gmail.com>
* fix(cli): add token refresh support and centralize auth constants
Expired OAuth tokens are now automatically refreshed via getValidAccessToken()
instead of silently failing. CLI_CLIENT_ID moved to constants.ts to avoid
duplication across auth.ts and setup.ts.
* refactor(cli): internalize baseUrl and clientId in refreshAccessToken
Make refreshAccessToken a private function that resolves getBaseUrl()
and CLI_CLIENT_ID internally instead of requiring them as parameters.
* test(cli): add unit tests for auth utilities and commands
Add comprehensive vitest test suite covering OAuth PKCE flow, token
persistence, token refresh, and CLI auth commands (login/logout/whoami).
* chore: add changeset for CLI auth improvements
* refactor: move CLI auth tests to src/__tests__/
Move auth test files from colocated __tests__ directories to a
centralized src/__tests__/ directory, adjusting mock import paths
accordingly.
* feat(cli): add teamspace name to whoami command
Replace direct Clerk userinfo call with new /api/dashboard/whoami
endpoint that returns name, email, and active teamspace in one request.
* chore: add changeset for whoami teamspace feature
* feat(cli): enumerate popularity and trust in skill search results
Replace raw install counts with star-based popularity rating (★☆☆/★★☆/★★★)
and numeric trust scores with High/Medium/Low labels in skill search,
install, and suggest commands. Show install range and raw trust score
in the hover description. Also reorder setup command to show CLI before MCP.
* feat(cli): use 4-star popularity scale matching install count ranges
* fix(cli): replace hardcoded "docs" with "find-docs" in setup output
* chore: add changeset for skill search enumeration and find-docs rename
* refactor(skills): consolidate skills under /skills with canonical sources
- Rename skills/docs → skills/find-docs (name: find-docs)
- Rename skills/ctx7-cli → skills/context7-cli (name: context7-cli)
- Add skills/context7-mcp as canonical MCP skill source
- Rename plugin skill folders to context7-mcp and unify name to context7-mcp
- MCP setup now downloads context7-mcp skill from GitHub instead of using hardcoded SKILL_CONTENT
- Remove SKILL_CONTENT from templates.ts — skills/context7-mcp/SKILL.md is the single source of truth
- Add Error Handling section to find-docs skill for quota errors
- Update agents.ts skill name: documentation-lookup → context7-mcp
- Update docs/clients/cli.mdx and setup references accordingly
* chore: add changeset for skills consolidation
* fix(skills): update plugin skill frontmatter name and setup docs to context7-mcp
* feat(cli): add CLI mode to ctx7 setup with docs skill installation
- Add MCP vs CLI mode selection prompt at the start of setup
- CLI mode authenticates user and installs docs skill via promptForInstallTargets
- Add --cli, --universal, --antigravity flags to setup command
- --yes skips the detected-locations confirmation prompt
- Default CLI install scope to global (override with --project)
- Fix checkbox selected choices to render in green (consistent with select prompt)
- Move Claude Code above Universal in IDE selection order
- Add forceUniversal=false option to promptForInstallTargets for setup flow
- Add yes? to AddOptions to support auto-confirm in promptForInstallTargets
* chore: add changeset for ctx7 setup CLI mode
* feat(cli): rename CLI mode to CLI + Skills, add --mcp flag, remove recommended label
* feat(cli): add --api-key support to CLI mode and update docs
- Pass apiKey through to resolveCliAuth in CLI mode setup
- Store provided API key as bearer token for subsequent API calls
- Update cli.mdx and setup.md to reflect both MCP and CLI + Skills modes
* docs: update setup docs to reflect --api-key for both modes and --cursor for CLI
- --api-key works in both MCP and CLI + Skills mode (not MCP-only)
- --oauth clarified as MCP-only
- Added --cursor to CLI + Skills mode examples (Cursor has a skills directory)
- Updated auth table row for ctx7 setup
* fix(cli): improve library ID validation and add telemetry headers
- Validate /owner/repo format locally before spinner starts, showing
consistent error + hint for both "react" and "/react" inputs
- Send X-Context7-Source, X-Context7-Client-IDE, X-Context7-Client-Version,
and X-Context7-Transport headers on library/docs requests so CLI
appears in the admin telemetry dashboard