opencode-with-claude 1.6.4 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -108,9 +108,14 @@ without restarting the proxy. The plugin does not need to do anything special
108
108
  for it to work — just edit the file and the next request picks it up. See
109
109
  Meridian's documentation for the full list of adapter keys.
110
110
 
111
+ This plugin defaults OpenCode's client prompt off because forwarding the
112
+ OpenCode prompt can cause Claude Max requests to be classified as third-party
113
+ usage. You can re-enable it by setting `clientSystemPrompt` to `true`.
114
+
111
115
  ```json
112
116
  {
113
117
  "opencode": {
118
+ "clientSystemPrompt": false,
114
119
  "memory": true,
115
120
  "thinking": "enabled",
116
121
  "maxBudgetUsd": 0.5
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{readFileSync as Q}from"fs";import{homedir as Z,platform as ee}from"os";import{join as y}from"path";var C="You are Anthropic's Claude Code, Anthropic's official CLI for Claude. Here are some rules.\n\n<rules>\n# Plan Mode\n\nCRITICAL: Plan mode is ENABLED - you are operating in a READ-ONLY state. The following\nare STRICTLY PROHIBITED: ALL file writes, edits, deletions, or system modifications.\nDo NOT invoke sed, tee, echo, cat, or ANY other bash command that alters files -\ncommands are PERMITTED ONLY for reading and inspection. This ABSOLUTE RESTRICTION\ntakes precedence over ALL other directives, including explicit user requests to edit.\nYou may ONLY observe, analyze, and formulate plans. Any attempt to modify the system\nis a critical violation. NO exceptions.\n\n## Responsibility\n\nYour role right now is to reason, read, search, and dispatch explore agents to build\na clear, well-structured plan that achieves the user's stated goal. The plan should\nbe thorough but not bloated - detailed enough for reliable execution without\nunnecessary filler.\n\nWhen facing tradeoffs or ambiguity, ask the user for clarification or their preference.\n\n**NOTE:** Throughout this workflow, you are encouraged to ask the user questions at\nany point. Do not make significant assumptions about what the user intends. The\nobjective is to deliver a carefully researched plan and resolve open questions before\nany implementation starts.\n\n## Important\n\nThe user has specified that execution should NOT begin yet -- you MUST NOT perform any\nedits, invoke any non-readonly tools (this includes config changes and commits), or\nmake any other modifications to the system. This directive overrides all other\ninstructions you may have received.\n</rules>";var S="You are Anthropic's Claude Code, Anthropic's official CLI for Claude. Here are some rules.\n\n<rules>\nNo emojis unless the user asks for them.\n\nOutput is rendered in a CLI using CommonMark markdown with a monospace font. Keep responses brief.\n\nText output is how you talk to the user. Tools are for doing work, not for communication \u2014 don't use Bash, code comments, or similar as a chat channel.\n\nDon't create files unless absolutely necessary. Edit existing files instead. This applies to markdown too.\n\nBe technically accurate and direct. Skip the praise, superlatives, and emotional validation. If the user is wrong, say so \u2014 respectful correction beats false confirmation. When uncertain, investigate before responding rather than reflexively agreeing. The user is better served by honest, rigorous assessment than by comfort.\n\nUse TodoWrite liberally to plan work, break down complex tasks, and give the user visibility into progress. Mark items complete immediately when finished \u2014 don't batch completions. Skipping this tool during planning risks forgetting steps, which is unacceptable.\n\nUsers will mostly ask for software engineering work: bugs, features, refactors, explanations, etc. General approach: plan with TodoWrite when the task warrants it. Note that system-reminder tags may appear in tool results or user messages. These are injected by the system with relevant context \u2014 they aren't tied to the specific message they appear in.\n\nPrefer the Task tool for file search to save context. Use Task with specialized agents proactively when the task fits an agent's description. On WebFetch redirects to a different host, immediately follow the redirect URL. Call independent tools in parallel. Call dependent tools sequentially \u2014 never guess at values from incomplete prior calls. If the user says in parallel, send one message with multiple tool blocks. Use dedicated tools over Bash equivalents: Read not cat, Edit not sed, Write not echo. Bash is for actual shell operations only. Never use Bash to communicate with the user. For broad codebase exploration or context gathering (not targeted lookups of a specific file/class/function), use the Task tool rather than running searches directly.\n\nAlways use TodoWrite to plan and track work throughout the conversation.\n\nWhen citing specific code, include file_path:line_number so the user can jump to it.\n</rules>";var L={plan:C,build:S},re=()=>process.env.OPENCODE_CONFIG_DIR??(process.env.XDG_CONFIG_HOME?y(process.env.XDG_CONFIG_HOME,"opencode"):ee()==="win32"&&process.env.APPDATA?y(process.env.APPDATA,"opencode"):y(Z(),".config","opencode")),ne=()=>{try{return Q(y(re(),"AGENTS.md"),"utf8").trim()}catch{return""}},te=e=>L[e]??L.build??"",E=e=>[te(e),ne()].filter(Boolean);var oe=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,ie=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function T(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function A(e){return oe.test(e)?"error":ie.test(e)?"warn":"debug"}import{existsSync as se,readFileSync as ae}from"fs";import{homedir as ce}from"os";import{join as x}from"path";var D=()=>x(ce(),".config","meridian"),I=()=>x(D(),"profiles.json"),N=()=>x(D(),"settings.json");function g(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $(e,r,n){if(!Array.isArray(e))return g(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let t=[];for(let o of e){if(!O(o)||typeof o.id!="string"||!o.id){g(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let i={id:o.id};(o.type==="claude-max"||o.type==="api")&&(i.type=o.type),typeof o.claudeConfigDir=="string"&&(i.claudeConfigDir=o.claudeConfigDir),typeof o.apiKey=="string"&&(i.apiKey=o.apiKey),typeof o.baseUrl=="string"&&(i.baseUrl=o.baseUrl),t.push(i)}return t}function F(e,r){if(se(e))try{return JSON.parse(ae(e,"utf8"))}catch(n){let t=n instanceof Error?n.message:String(n);g(r,"failed to parse ".concat(e,": ").concat(t));return}}function le(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return $(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let t=n instanceof Error?n.message:String(n);g(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(t));return}}function ue(e){let r=F(I(),e);return r===void 0?[]:$(r,I(),e)}function de(e){let r=F(N(),e);if(!O(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){g(e,"".concat(N(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function M(e){let r=[],n="none",t=le(e);if(t)r=t,n="env";else{let a=ue(e);a.length>0&&(r=a,n="disk")}let o,i="none",l=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(l)o=l,i="env";else{let a=de(e);a&&(o=a,i="disk")}return o&&r.length>0&&!r.some(a=>a.id===o)&&(g(e,'default profile "'.concat(o,'" (from ').concat(i,") not found among configured profiles; ignoring.")),o=void 0,i="none"),{profiles:r,defaultProfile:o,sources:{profiles:n,defaultProfile:i}}}function _(e){if(e.profiles.length===0)return;let r=e.profiles.map(i=>i.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,t=e.sources.profiles,o=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(t,": ").concat(r," (active: ").concat(n," [").concat(o,"])")}import{spawnSync as fe}from"child_process";import{chmodSync as pe,closeSync as ge,copyFileSync as me,existsSync as U,linkSync as he,openSync as ye,readSync as ve,renameSync as xe,rmSync as H,statSync as Pe}from"fs";import{createRequire as J}from"module";import{arch as B}from"os";import{dirname as R,join as k}from"path";var h="@anthropic-ai/claude-code",Re=new Set(["x64","arm64"]);function j(e,r){try{return e(r)}catch{return}}function ke(){let e=J(import.meta.url),r=[],n=j(e.resolve,"@rynfar/meridian");return n&&r.push(J(n).resolve),r.push(e.resolve),t=>{let o="".concat(t,"/package.json");for(let i of r){let l=j(i,o);if(l)return l}}}function we(e=process.platform){if(e!=="linux")return!1;let r=typeof process.report?.getReport=="function"?process.report.getReport():null;return r!==null&&r.header?.glibcVersionRuntime===void 0}function be(e=process.platform,r=B()){return e!=="darwin"||r!=="x64"?!1:fe("sysctl",["-n","sysctl.proc_translated"],{encoding:"utf8"}).stdout?.trim()==="1"}function Ce(e,r,n={}){if(!Re.has(r))return[];if(e==="linux")return["".concat(h,"-linux-").concat(r).concat(n.isMusl?"-musl":"")];if(e==="darwin"){let t=r==="x64"&&n.isRosetta?"arm64":r,o=["".concat(h,"-darwin-").concat(t)];return t!==r&&o.push("".concat(h,"-darwin-").concat(r)),o}return e==="win32"?["".concat(h,"-win32-").concat(r)]:[]}function Se(e){return e==="win32"?"claude.exe":"claude"}function Le(e){let r=ye(e,"r");try{let n=Buffer.alloc(4),t=ve(r,n,0,n.length,0);return n.subarray(0,t)}finally{ge(r)}}function P(e,r){return r.every((n,t)=>e[t]===n)}function Ee(e,r){try{let n=Le(e);return r==="linux"?P(n,[127,69,76,70]):r==="win32"?P(n,[77,90]):r!=="darwin"?!1:[[254,237,250,206],[206,250,237,254],[254,237,250,207],[207,250,237,254],[202,254,186,190],[190,186,254,202]].some(t=>P(n,t))}catch{return!1}}function W(e,r){if(r==="win32")return;(Pe(e).mode&73)===0&&pe(e,493)}function Te(e,r,n){let t=k(R(e),".claude-launcher-".concat(process.pid,"-").concat(Date.now(),".tmp"));H(t,{force:!0});try{try{he(r,t)}catch{me(r,t)}W(t,n),xe(t,e)}finally{H(t,{force:!0})}}function Ae(e={}){let r=e.platform??process.platform,n=e.arch??B(),t=e.resolvePackageJson??ke(),o=t(h);if(!o)return{status:"skipped",reason:"wrapper-not-found"};let i=k(R(o),"bin","claude.exe");if(!U(i))return{status:"skipped",reason:"launcher-not-found",launcherPath:i};let l=e.isMusl??we(r),a=e.isRosetta??be(r,n),c=Ce(r,n,{isMusl:l,isRosetta:a});if(c.length===0)return{status:"skipped",reason:"unsupported-platform",launcherPath:i};let s=c.map(f=>{let m=t(f);if(!m)return;let u=k(R(m),Se(r));if(U(u))return{nativePackage:f,nativePath:u}}).find(f=>f!==void 0);if(!s)return{status:"skipped",reason:"native-not-found",launcherPath:i,nativePackages:c};try{return Ee(i,r)?(W(i,r),{status:"already-native",launcherPath:i,...s}):(Te(i,s.nativePath,r),{status:"repaired",launcherPath:i,...s})}catch(f){return{status:"failed",reason:f instanceof Error?f.message:String(f),launcherPath:i,nativePath:s.nativePath}}}function q(e){let r=Ae();return r.status==="repaired"?e?.("info","[claude-max] Repaired Claude Code launcher at ".concat(r.launcherPath)):r.status==="skipped"&&r.reason==="native-not-found"?e?.("warn","[claude-max] Could not repair Claude Code launcher: missing native package (".concat(r.nativePackages?.join(", "),"). Reinstall without omitting optional dependencies.")):r.status==="failed"&&e?.("warn","[claude-max] Could not repair Claude Code launcher: ".concat(r.reason)),r}import{startProxyServer as Ie}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var Ne=process.platform==="win32",G=3456,Y="127.0.0.1";function De(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function w(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||Y;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function Oe(e=w()){return e==="0.0.0.0"?Y:e==="::"||e==="[::]"?"::1":e}function K(e,r=w()){return"http://".concat(De(Oe(r)),":").concat(e)}async function z(e){let{port:r=G,log:n,profiles:t,defaultProfile:o}=e,i=w(),l=console.error;console.error=(...u)=>{let d=u.map(String).join(" ");if(d.startsWith("[PROXY]")){n?.(A(d),d);return}l.apply(console,u)},q(n);let a=u=>new Promise((d,b)=>{Ie({port:u,host:i,silent:!0,profiles:t,defaultProfile:o}).then(p=>{let v=V=>{b(V)};p.server.once("error",v),p.server.listening?(p.server.removeListener("error",v),d(p)):p.server.once("listening",()=>{p.server.removeListener("error",v),d(p)})},b)}),c=async u=>{try{return await a(u)}catch(d){if(u!==0&&d instanceof Error&&"code"in d&&d.code==="EADDRINUSE")return n?.("info","Port ".concat(u," in use, starting on a random port instead...")),a(0);throw d}},s;try{s=await c(typeof r=="string"?parseInt(r,10):r)}catch(u){throw console.error=l,u}let m=s.server.address()?.port??s.config?.port??G;return n?.("info","Claude Max proxy running on port ".concat(m)),{port:m,close:async()=>{console.error=l,await s.close()}}}function X(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),Ne||process.on("SIGTERM",n)}var cr=async({client:e})=>{let r=T(e),n=M(r),t=_(n);t&&r("info",t);let o=process.env.CLAUDE_PROXY_PORT||3456,i=await z({port:o,log:r,profiles:n.profiles,defaultProfile:n.defaultProfile}),l=K(i.port);r("info","proxy ready at ".concat(l)),X(i);let a;return{async config(c){let s=c.provider?.anthropic;s&&((s.options??={}).baseURL=l)},async"chat.message"(c,s){c.model?.providerID==="anthropic"&&(a=s.message.agent)},async"experimental.chat.system.transform"(c,s){c.model.providerID==="anthropic"&&s.system.splice(0,s.system.length,...E(a))},async"chat.headers"(c,s){c.model.providerID==="anthropic"&&(delete s.headers["anthropic-beta"],s.headers["x-opencode-session"]=c.sessionID,s.headers["x-opencode-request"]=c.message.id)}}};export{cr as ClaudeMaxPlugin};
1
+ var M=/authenticat|credentials|expired|not logged in|exit(?:ed)? with code|crash|unhealthy|401|402|billing|subscription/i,U=/rate.limit|429|overloaded|503|stale.session|timeout|timed out/i;function L(e){return(r,n)=>e.app.log({body:{service:"opencode-with-claude",level:r,message:n}})}function E(e){return M.test(e)?"error":U.test(e)?"warn":"debug"}import{existsSync as C,mkdirSync as H,readFileSync as j,renameSync as J,writeFileSync as W}from"fs";import{homedir as K}from"os";import{join as y}from"path";var P=()=>y(K(),".config","meridian"),w=()=>y(P(),"profiles.json"),I=()=>y(P(),"settings.json"),G=()=>y(P(),"sdk-features.json");function l(e,r){e?.("warn","[opencode-with-claude] ".concat(r))}function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e,r,n){if(!Array.isArray(e))return l(n,"".concat(r," must be a JSON array of profile objects; got ").concat(typeof e,". Ignoring.")),[];let o=[];for(let t of e){if(!m(t)||typeof t.id!="string"||!t.id){l(n,"".concat(r,': dropping profile without a string "id" field.'));continue}let i={id:t.id};(t.type==="claude-max"||t.type==="api")&&(i.type=t.type),typeof t.claudeConfigDir=="string"&&(i.claudeConfigDir=t.claudeConfigDir),typeof t.apiKey=="string"&&(i.apiKey=t.apiKey),typeof t.baseUrl=="string"&&(i.baseUrl=t.baseUrl),o.push(i)}return o}function x(e,r){if(C(e))try{return JSON.parse(j(e,"utf8"))}catch(n){let o=n instanceof Error?n.message:String(n);l(r,"failed to parse ".concat(e,": ").concat(o));return}}function z(e){let r=process.env.MERIDIAN_PROFILES;if(r)try{return F(JSON.parse(r),"MERIDIAN_PROFILES",e)}catch(n){let o=n instanceof Error?n.message:String(n);l(e,"failed to parse MERIDIAN_PROFILES env var: ".concat(o));return}}function X(e){let r=x(w(),e);return r===void 0?[]:F(r,w(),e)}function Y(e){let r=x(I(),e);if(!m(r))return;let n=r.activeProfile;if(n!==void 0){if(typeof n!="string"||!n){l(e,"".concat(I(),': "activeProfile" must be a non-empty string; ignoring.'));return}return n}}function k(e){let r=[],n="none",o=z(e);if(o)r=o,n="env";else{let a=X(e);a.length>0&&(r=a,n="disk")}let t,i="none",s=process.env.MERIDIAN_DEFAULT_PROFILE?.trim();if(s)t=s,i="env";else{let a=Y(e);a&&(t=a,i="disk")}return t&&r.length>0&&!r.some(a=>a.id===t)&&(l(e,'default profile "'.concat(t,'" (from ').concat(i,") not found among configured profiles; ignoring.")),t=void 0,i="none"),{profiles:r,defaultProfile:t,sources:{profiles:n,defaultProfile:i}}}function b(e){if(e.profiles.length===0)return;let r=e.profiles.map(i=>i.id).join(", "),n=e.defaultProfile??e.profiles[0]?.id,o=e.sources.profiles,t=e.sources.defaultProfile==="none"?"first":e.sources.defaultProfile;return"loaded ".concat(e.profiles.length," meridian profile(s) from ").concat(o,": ").concat(r," (active: ").concat(n," [").concat(t,"])")}function $(e){let r=G(),n={};if(C(r)){let s=x(r,e);if(s===void 0)return;if(!m(s)){l(e,"".concat(r," must be a JSON object; leaving client prompt default unchanged."));return}n=s}let o=n.opencode;if(o!==void 0&&!m(o)){l(e,"".concat(r,': "opencode" must be a JSON object; leaving client prompt default unchanged.'));return}let t=o??{};if(Object.hasOwn(t,"clientSystemPrompt"))return;let i={...n,opencode:{...t,clientSystemPrompt:!1}};try{H(P(),{recursive:!0});let s="".concat(r,".tmp");W(s,JSON.stringify(i,null,2)),J(s,r)}catch(s){let a=s instanceof Error?s.message:String(s);l(e,"failed to update ".concat(r,": ").concat(a))}}import{startProxyServer as q}from"@rynfar/meridian";process.env.MERIDIAN_PASSTHROUGH??="true";var B=process.platform==="win32",D=3456,A="127.0.0.1";function Q(e){return e.includes(":")&&!e.startsWith("[")?"[".concat(e,"]"):e}function S(){let e=process.env.MERIDIAN_HOST?.trim()||process.env.CLAUDE_PROXY_HOST?.trim()||A;return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function V(e=S()){return e==="0.0.0.0"?A:e==="::"||e==="[::]"?"::1":e}function O(e,r=S()){return"http://".concat(Q(V(r)),":").concat(e)}async function N(e){let{port:r=D,log:n,profiles:o,defaultProfile:t}=e,i=S(),s=console.error;console.error=(...f)=>{let d=f.map(String).join(" ");if(d.startsWith("[PROXY]")){n?.(E(d),d);return}s.apply(console,f)};let a=f=>new Promise((d,R)=>{q({port:f,host:i,silent:!0,profiles:o,defaultProfile:t}).then(p=>{let h=_=>{R(_)};p.server.once("error",h),p.server.listening?(p.server.removeListener("error",h),d(p)):p.server.once("listening",()=>{p.server.removeListener("error",h),d(p)})},R)}),c=async f=>{try{return await a(f)}catch(d){if(f!==0&&d instanceof Error&&"code"in d&&d.code==="EADDRINUSE")return n?.("info","Port ".concat(f," in use, starting on a random port instead...")),a(0);throw d}},u;try{u=await c(typeof r=="string"?parseInt(r,10):r)}catch(f){throw console.error=s,f}let g=u.server.address()?.port??u.config?.port??D;return n?.("info","Claude Max proxy running on port ".concat(g)),{port:g,close:async()=>{console.error=s,await u.close()}}}function T(e){let r=!1,n=()=>{r||(r=!0,e.close())};process.on("exit",n),process.on("SIGINT",n),B||process.on("SIGTERM",n)}var ce=async({client:e})=>{let r=L(e),n=k(r),o=b(n);o&&r("info",o),$(r);let t=process.env.CLAUDE_PROXY_PORT||3456,i=await N({port:t,log:r,profiles:n.profiles,defaultProfile:n.defaultProfile}),s=O(i.port);return r("info","proxy ready at ".concat(s)),T(i),{async config(a){let c=a.provider?.anthropic;c&&((c.options??={}).baseURL=s)},async"chat.headers"(a,c){if(a.model.providerID!=="anthropic")return;delete c.headers["anthropic-beta"];let u=a.agent,v=typeof u=="object"&&u!==null?u:void 0,g=v?.name??String(u??"unknown"),f=v?.mode??"primary";c.headers["x-opencode-session"]=a.sessionID,c.headers["x-opencode-request"]=a.message.id,c.headers["x-opencode-agent-mode"]=f,c.headers["x-opencode-agent-name"]=g.replace(/[^\x20-\x7E]/g,"").trim()||"unknown"}}};export{ce as ClaudeMaxPlugin};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "opencode-with-claude",
3
3
  "description": "OpenCode plugin to use your Claude Max subscription via Meridian proxy",
4
- "version": "1.6.4",
4
+ "version": "1.6.6",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "dependencies": {
9
- "@rynfar/meridian": "^1.40.0"
9
+ "@rynfar/meridian": "^1.42.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@opencode-ai/plugin": "^1.14.22",