This document explains how authentication works in J-Code.
J-Code auto-imports existing local credentials and can also run built-in OAuth login flows.
Credentials are stored locally:
- J-Code Claude OAuth (if logged in via
jcode login --provider claude):~/.jcode/auth.json - Claude Code CLI:
~/.claude/.credentials.json - OpenCode (optional):
~/.local/share/opencode/auth.json - OpenAI/Codex:
~/.codex/auth.json
Relevant code:
- Claude provider:
src/provider/claude.rs - OpenAI login + refresh:
src/auth/oauth.rs - OpenAI credentials parsing:
src/auth/codex.rs - OpenAI requests:
src/provider/openai.rs
- Run
jcode login --provider claude(recommended), orjcode loginand choose Claude. - Alternative: run
claude(orclaude setup-token) and J-Code will auto-import~/.claude/.credentials.json. - Verify with
jcode --provider claude run "Say hello from jcode".
Credential discovery order is:
~/.jcode/auth.json~/.claude/.credentials.json~/.local/share/opencode/auth.json
These environment variables control the Claude Code CLI provider:
JCODE_CLAUDE_CLI_PATH(default:claude)JCODE_CLAUDE_CLI_MODEL(default:claude-opus-4-5-20251101)JCODE_CLAUDE_CLI_PERMISSION_MODE(default:bypassPermissions)JCODE_CLAUDE_CLI_PARTIAL(set to0to disable partial streaming)
Set JCODE_USE_DIRECT_API=1 to bypass the CLI and use the Anthropic Messages API.
This requires tokens that Anthropic permits for direct API access (API keys, or
OAuth tokens explicitly allowed for API usage).
Claude Code OAuth tokens can be used directly against the Messages API, but only
if the request matches the Claude Code "OAuth contract". jcode handles this
automatically when JCODE_USE_DIRECT_API=1 and Claude OAuth credentials are
present.
Required behaviors (applied by the Anthropic provider):
- Use the Messages endpoint with
?beta=true. - Send
User-Agent: claude-cli/1.0.0. - Send
anthropic-beta: oauth-2025-04-20,claude-code-20250219. - Prepend the system blocks with the Claude Code identity line as the first
block:
You are Claude Code, Anthropic's official CLI for Claude.
Tool name allow-list: Claude OAuth requests reject certain tool names. jcode remaps tool names on the wire and maps them back on responses so native tools continue to work. The mapping is:
bash→shell_execread→file_readwrite→file_writeedit→file_editglob→file_globgrep→file_greptask→task_runnertodoread→todo_readtodowrite→todo_write
Notes:
- If the OAuth token expires, refresh via the Claude OAuth refresh endpoint.
- Without the identity line and allow-listed tool names, the API will reject OAuth requests even if the token is otherwise valid.
- Run
jcode login --provider openai. - Your browser opens to the OpenAI OAuth page. The local callback listens on
http://localhost:9876/callback. - After login, tokens are saved to
~/.codex/auth.json.
J-Code uses the Responses API. If you have a ChatGPT subscription (refresh token or id_token present), requests go to:
https://chatgpt.com/backend-api/codex/responseswith headers:originator: codex_cli_rschatgpt-account-id: <from token>
Otherwise it uses:
https://api.openai.com/v1/responses
- Claude 401/auth errors: run
jcode login --provider claude. - 401/403: re-run
jcode login --provider openai. - Callback issues: make sure port 9876 is free and the browser can reach
http://localhost:9876/callback.
J-Code also supports experimental CLI-backed providers:
--provider cursor--provider copilot--provider antigravity
These use each provider's local CLI session/auth and shell out in print mode.
- Login:
jcode login --provider cursor(runscursor-agent login) - Env vars:
JCODE_CURSOR_CLI_PATH(default:cursor-agent)JCODE_CURSOR_MODEL(default:gpt-5)
- Login:
jcode login --provider copilot(runscopilot -i /login, orgh copilot -- -i /loginifcopilotis not on PATH) - Env vars:
JCODE_COPILOT_CLI_PATH(optional override for CLI path)JCODE_COPILOT_MODEL(default:claude-sonnet-4)
- Login:
jcode login --provider antigravity(runs<cli> login) - Env vars:
JCODE_ANTIGRAVITY_CLI_PATH(default:antigravity)JCODE_ANTIGRAVITY_MODEL(default:default)JCODE_ANTIGRAVITY_PROMPT_FLAG(default:-p)JCODE_ANTIGRAVITY_MODEL_FLAG(default:--model)