Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

OpenCode Proxy

A pair of Cloudflare Workers that give developers at Initial Capacity zero-config access to AI models, GitHub tooling, and a shared code-review agent through OpenCode, authenticated via Cloudflare Access SSO.

Set up

  1. Install dependencies

    brew install anomalyco/tap/opencode cloudflared
  2. Authenticate

    opencode auth login https://opencode.icap.dev

    This opens your browser for SSO. After authenticating, OpenCode automatically configures itself with providers, models, and the GitHub MCP server — no manual config required.

  3. Run OpenCode

    opencode

What you get

  • Shared ic-* model providers routed through IC's Cloudflare AI Gateway. Provider API keys stay server-side.
  • A preconfigured GitHub MCP server for repo, issue, PR, and org-wide code search workflows.
  • A built-in @code-reviewer subagent and /review slash command tuned to the IC Codex.

Verify setup

After logging in, these commands should work:

opencode models
opencode mcp list

You should see IC providers such as ic-anthropic, ic-gemini, ic-openai, and ic-workers-ai, plus a github MCP server at https://github-mcp.icap.dev/mcp.

Then launch OpenCode and confirm the IC-specific tools are available:

opencode
  • Run /review in any git repo to confirm the reviewer is present.
  • Ask for a GitHub action like List the open pull requests in opencode-proxy.

If model or MCP requests start failing with auth errors, re-run:

opencode auth login https://opencode.icap.dev

First things to try

Once opencode is running, these are good first prompts for a new IC user:

  1. Understand the repo you're in.

    How does authentication work in this repo?
    
  2. Confirm the GitHub MCP server is wired up.

    List the open pull requests in opencode-proxy.
    
  3. Try org-wide code search.

    Search code across the organization for "cloudflared access login"
    
  4. Run the IC-specific reviewer.

    /review
    

Reviewing code

Every session ships with a @code-reviewer subagent and a /review slash command. The reviewer knows the IC Codex — Initial Capacity's engineering principles codified as ~40 machine-readable rules — and cites specific rule IDs when flagging findings.

Run it on the current branch's diff against origin/main:

/review

Or invoke the agent directly with your own context:

@code-reviewer review the changes I just staged

The reviewer is a subagent — it runs in an isolated child session and posts categorized findings (Architecture, Code quality, Testing) with severity tags (critical, important, suggestion, nit) and rule citations like IC-TEST-009. The reviewer's scope is strictly the Codex: it only flags violations of a specific IC rule and says nothing about concerns the Codex doesn't cover. See Code review agent below for the internals.

Architecture

Two Workers are deployed:

WorkerDomainPurpose
opencode-proxyopencode.icap.devAI model proxy, discovery endpoint, Codex endpoint, agent + command config
github-mcpgithub-mcp.icap.devGitHub MCP server

Discovery and authentication

When a developer runs opencode auth login, OpenCode fetches https://opencode.icap.dev/.well-known/opencode. This single endpoint returns everything OpenCode needs: how to authenticate, which providers to use, and which MCP servers to connect to.

sequenceDiagram
participant Dev as Developer
participant OC as opencode
participant Proxy as opencode.icap.dev
participant CF as Cloudflare Access
Dev->>OC: opencode auth login https://opencode.icap.dev
OC->>Proxy: GET /.well-known/opencode
Proxy-->>OC: auth command + provider config + mcp config
OC->>CF: cloudflared access login (opens browser)
CF-->>OC: signed JWT → stored as CF_ACCESS_TOKEN
Note over OC: Configured with providers,<br/>models, and MCP servers
Loading

AI model proxy

All model requests are routed through the opencode-proxy worker, which validates the Cloudflare Access JWT and forwards to AI Gateway. Provider API keys are stored in AI Gateway (BYOK) — they never touch developer machines. OpenCode sends the Cloudflare Access JWT using the auth header expected by each SDK: x-api-key for Anthropic, x-goog-api-key for Gemini, and Authorization: Bearer for OpenAI-compatible clients.

sequenceDiagram
participant OC as opencode
participant Proxy as opencode.icap.dev
participant GW as Cloudflare AI Gateway
participant API as Provider API
OC->>Proxy: POST /v1/anthropic/v1/messages<br/>x-api-key: <CF_ACCESS_JWT>
Proxy->>Proxy: Validate JWT (Cloudflare Access)
Proxy->>GW: POST /v1/{account}/{gateway}/anthropic/v1/messages<br/>cf-aig-authorization: Bearer <AIG_TOKEN>
GW->>API: Forward with provider API key (BYOK)
API-->>GW: Response
GW-->>Proxy: Response
Proxy-->>OC: Response
Loading

Four providers are available:

OpenCode providerGateway pathSDK
ic-anthropicanthropic@ai-sdk/anthropic
ic-geminigoogle-ai-studio@ai-sdk/google
ic-openaiopenai@ai-sdk/openai
ic-workers-aicompat@ai-sdk/openai-compatible

Models are fetched from models.dev hourly by a cron trigger and cached in Workers KV. If discovery sees a provider missing from KV, it refreshes the catalog once on demand so newly added providers show up immediately instead of waiting for the next cron run. The discovery endpoint includes the full model catalog so OpenCode can populate the model picker without any external calls.

GitHub MCP server

The github-mcp worker exposes a remote MCP server at https://github-mcp.icap.dev/mcp. It is advertised via the discovery endpoint and picked up automatically when a developer logs in.

Authentication uses the same Cloudflare Access JWT passed as x-api-key. GitHub API calls are made with a server-side installation token from a GitHub App — no personal tokens, no credentials on developer machines.

sequenceDiagram
participant OC as opencode
participant MCP as github-mcp.icap.dev
participant GH as GitHub API
OC->>MCP: MCP request<br/>x-api-key: <CF_ACCESS_JWT>
MCP->>MCP: Validate JWT (Cloudflare Access)
MCP->>MCP: Get installation token<br/>(cached 50 min)
MCP->>GH: API request<br/>Authorization: Bearer <installation_token>
GH-->>MCP: Response
MCP-->>OC: MCP tool result
Loading

Available tools:

ToolDescription
list_reposList repositories in the org, sorted by most recently updated. Paginated — use page and per_page to navigate results.
search_codeSearch code across repositories in the organization
get_file_contentGet the content of a file from a repository
list_issuesList issues for a repository
get_issueGet details of a specific issue including comments
list_pull_requestsList pull requests for a repository
get_pull_requestGet details of a specific pull request including the diff

Example prompts:

List the most recently updated repos in the organization.
Show the open pull requests for opencode-proxy.
Get issue 123 in opencode-proxy and summarize the discussion.
Search code across the organization for "cloudflared access login".

IC Codex

The IC Codex is the machine-readable form of kt.dev — Initial Capacity's opinionated engineering principles — split into ~40 rules with stable IDs. Each rule lives in its own markdown file under codex/rules/ with frontmatter declaring its id, category (architecture, code, testing), and severity. The full corpus is published at https://opencode.icap.dev/.well-known/codex as JSON.

curl -s https://opencode.icap.dev/.well-known/codex | jq '.rules[] | {id, title, severity}'

Rules are compiled at build time from codex/rules/*.md into src/codex.generated.ts by scripts/build-codex.mjs. See codex/README.md for the authoring format.

Code review agent

Every OpenCode session at IC picks up a code-reviewer subagent and a /review slash command via the discovery payload. The agent's system prompt is compiled at build time from agents/code-reviewer.md with the full IC Codex inlined as an appendix, so the reviewer always has the current rule corpus in context.

sequenceDiagram
participant Dev as Developer
participant OC as opencode (session)
participant CR as @code-reviewer (subtask)
participant GW as AI Gateway
Dev->>OC: /review
OC->>CR: spawn subtask with template<br/>(git diff + AGENTS.md)
CR->>GW: inference w/ IC Codex in system prompt
GW-->>CR: categorized findings
CR-->>OC: structured review
OC-->>Dev: rendered output
Loading

The reviewer runs as a subagent (read-only, edit: deny, webfetch: allow) and produces findings grouped by Codex category — Architecture, Code quality, Testing — with severity tags and rule citations. Every finding must map to a specific IC-* rule; concerns the Codex doesn't cover are intentionally out of scope. This keeps the reviewer predictable: as the Codex grows, so does the scope of the review.

Source files:

PathPurpose
agents/code-reviewer.mdAgent frontmatter + system prompt
commands/review.md/review slash command template
scripts/build-agents.mjsCompiles both into src/agents.generated.ts, inlining the Codex into the agent prompt

The compiled agent and command are served in the config.agent and config.command blocks of the discovery payload, so every developer gets them automatically on next session — no local configuration.

Project structure

opencode-proxy/
├── src/ # opencode-proxy worker
│ ├── index.ts # Routes, scheduled handler
│ ├── discovery.ts # .well-known/opencode payload
│ ├── models.ts # Model catalog (KV cache)
│ ├── gateway.ts # AI Gateway proxy
│ ├── auth.ts # JWT middleware + extractToken
│ ├── jwt.ts # Cloudflare Access JWT verification
│ ├── logging.ts # Request logging middleware
│ ├── codex.ts # IC Codex catalog (DI wrapper)
│ ├── agents.generated.ts # Compiled agents + commands
│ └── landing.ts # HTML landing page
├── codex/ # IC Codex source
│ ├── README.md # Rule authoring format
│ └── rules/ # One markdown file per rule
├── agents/ # OpenCode agent definitions (markdown)
│ └── code-reviewer.md
├── commands/ # OpenCode slash command definitions (markdown)
│ └── review.md
├── scripts/ # Build scripts (Node ESM)
│ ├── build-codex.mjs # codex/rules/ → src/codex.generated.ts
│ ├── build-agents.mjs # agents/ + commands/ → src/agents.generated.ts
│ └── lib/frontmatter.mjs # Shared YAML frontmatter parser
├── github-mcp/ # github-mcp worker
│ ├── index.ts # Worker entry point + auth
│ ├── tools.ts # MCP tool definitions
│ └── github-app.ts # GitHub App installation token (cached)
├── test/ # Test suite (vitest + Workers pool)
├── wrangler.jsonc # opencode-proxy config
└── wrangler.github-mcp.jsonc # github-mcp config

Development

npm test# run all tests
npm run typecheck # typecheck all projects
npm run format # format all code with prettier
npm run dev # opencode-proxy local dev
npm run dev:github-mcp # github-mcp local dev
npm run build:config # regenerate codex + agents (runs automatically on pre-hooks)

To test locally with OpenCode, start the local dev server (npm run dev) and run:

opencode auth login http://localhost:8787

Editing Codex rules, the agent prompt, or the /review command means editing markdown files:

  • Add or change a rule: codex/rules/IC-<CATEGORY>-<NNN>.md (see codex/README.md).
  • Change the reviewer's behavior: agents/code-reviewer.md.
  • Change the /review template: commands/review.md.

The pre-hooks on npm test, npm run typecheck, npm run deploy, and npm run dev regenerate src/codex.generated.ts and src/agents.generated.ts automatically, so you never need to run the build script by hand.

Deployment

Deployments are handled by the CI/CD pipeline (.github/workflows/pipeline.yml) on push to main. Do not run npm run deploy locally.

The following repository secrets must be set in GitHub for deployments to succeed:

  • CF_TOKEN: A Cloudflare API token with permission to edit Workers and KV.

Cloudflare Access configuration and AI Gateway keys (CF_AIG_TOKEN) are managed directly in the Cloudflare dashboard.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages