Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Fail safely when FCC is running during installation (#1182)
Ali Khokharfa39a1d45a5f
diff --git a/pyproject.toml b/pyproject.tomlindex 9ef30c7c..8de4e657 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "4.8.7"+version = "4.8.8"description = "Local proxy connecting coding agents to OpenAI-compatible AI providers"readme = "README.md"requires-python = ">=3.14.0"diff --git a/scripts/install.ps1 b/scripts/install.ps1index 88da2540..cc5eee78 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -20,6 +20,14 @@ $ClaudeInstallUrl = "https://claude.ai/install.ps1"$CodexInstallUrl = "https://chatgpt.com/codex/install.ps1"$PiInstallUrl = "https://pi.dev/install.ps1"$UvInstallUrl = "https://astral.sh/uv/install.ps1"+$FccCommands = @(+ "fcc-server",+ "fcc-claude",+ "fcc-codex",+ "fcc-pi",+ "fcc-init",+ "free-claude-code"+)function Show-Usage {@"@@ -186,6 +194,20 @@ function Add-PiBinDirectories {}}+function Assert-NoFccProcessesRunning {+ $running = @()+ foreach ($commandName in $FccCommands) {+ $processes = @(Get-Process -Name $commandName -ErrorAction SilentlyContinue)+ foreach ($process in $processes) {+ $running += "$commandName (PID $($process.Id))"+ }+ }++ if ($running.Count -gt 0) {+ throw "Free Claude Code is still running ($($running -join ', ')). Stop those processes, then rerun the installer."+ }+}+function Invoke-DownloadedPowerShellInstaller {param([string] $Url,@@ -448,6 +470,7 @@ function Get-PackageSpec {}function Install-FreeClaudeCode {+ Assert-NoFccProcessesRunning$packageSpec = Get-PackageSpec$arguments = @("tool",@@ -533,6 +556,9 @@ if ((-not [string]::IsNullOrWhiteSpace($TorchBackend)) -and (-not ($VoiceLocal -Add-KnownBinDirectories+Write-Step "Checking for running Free Claude Code processes"+Assert-NoFccProcessesRunning+Write-Step "Ensuring Claude Code is installed"Ensure-ClaudeCodediff --git a/scripts/install.sh b/scripts/install.shindex 3ee85951..42805e77 100644--- a/scripts/install.sh+++ b/scripts/install.sh@@ -8,6 +8,7 @@ CLAUDE_INSTALL_URL="https://claude.ai/install.sh"CODEX_INSTALL_URL="https://chatgpt.com/codex/install.sh"PI_INSTALL_URL="https://pi.dev/install.sh"UV_INSTALL_URL="https://astral.sh/uv/install.sh"+FCC_COMMANDS="fcc-server fcc-claude fcc-codex fcc-pi fcc-init free-claude-code"dry_run=0voice_nim=0@@ -123,6 +124,53 @@ add_pi_bin_directories() {fi}+fcc_process_ids() {+ command_name=$1++ if command -v pgrep >/dev/null 2>&1; then+ {+ pgrep -x "$command_name" 2>/dev/null || true+ pgrep -f "(^|/)${command_name}([[:space:]]|$)" 2>/dev/null || true+ } | sort -nu+ return 0+ fi++ ps -A -o pid= -o args= 2>/dev/null |+ awk -v command_name="$command_name" '+ BEGIN {+ pattern = "(^|/)" command_name "([[:space:]]|$)"+ }+ {+ process_id = $1+ sub(/^[[:space:]]*[0-9]+[[:space:]]+/, "")+ if ($0 ~ pattern) {+ print process_id+ }+ }+ ' || true+}++assert_no_fcc_processes_running() {+ running=""+ for command_name in $FCC_COMMANDS; do+ process_ids=$(fcc_process_ids "$command_name")+ [ -n "$process_ids" ] || continue++ for process_id in $process_ids; do+ process="$command_name (PID $process_id)"+ if [ -n "$running" ]; then+ running="$running, $process"+ else+ running=$process+ fi+ done+ done++ if [ -n "$running" ]; then+ fail "Free Claude Code is still running ($running). Stop those processes, then rerun the installer."+ fi+}+require_command() {if [ "$dry_run" -eq 0 ] && ! command -v "$1" >/dev/null 2>&1; thenfail "$1 is required. Install it first, then rerun this installer."@@ -426,6 +474,7 @@ package_spec() {}install_free_claude_code() {+ assert_no_fcc_processes_runningspec=$(package_spec)if [ -n "$torch_backend" ]; then@@ -469,6 +518,9 @@ parse_args "$@"validate_argsadd_known_bin_directories+step "Checking for running Free Claude Code processes"+assert_no_fcc_processes_running+step "Checking installation prerequisites"require_command curlrequire_command bashdiff --git a/scripts/uninstall.sh b/scripts/uninstall.shindex a9b9b54f..03ec07df 100644--- a/scripts/uninstall.sh+++ b/scripts/uninstall.sh@@ -91,20 +91,34 @@ add_known_uv_paths() {hash -r 2>/dev/null || true}-is_fcc_command_running() {+fcc_process_ids() {command_name=$1if command -v pgrep >/dev/null 2>&1; then- if pgrep -x "$command_name" >/dev/null 2>&1; then- return 0- fi- if pgrep -f "(^|/)${command_name}( |$)" >/dev/null 2>&1; then- return 0- fi- return 1+ {+ pgrep -x "$command_name" 2>/dev/null || true+ pgrep -f "(^|/)${command_name}([[:space:]]|$)" 2>/dev/null || true+ } | sort -nu+ return 0fi- ps -A -o comm= 2>/dev/null | grep -qx "$command_name"+ ps -A -o pid= -o args= 2>/dev/null |+ awk -v command_name="$command_name" '+ BEGIN {+ pattern = "(^|/)" command_name "([[:space:]]|$)"+ }+ {+ process_id = $1+ sub(/^[[:space:]]*[0-9]+[[:space:]]+/, "")+ if ($0 ~ pattern) {+ print process_id+ }+ }+ ' || true+}++is_fcc_command_running() {+ [ -n "$(fcc_process_ids "$1")" ]}assert_no_fcc_processes_running() {diff --git a/tests/scripts/test_installers.py b/tests/scripts/test_installers.pyindex 7c800523..12487162 100644--- a/tests/scripts/test_installers.py+++ b/tests/scripts/test_installers.py@@ -6,6 +6,15 @@ from pathlib import Pathimport pytest+FCC_COMMANDS = (+ "fcc-server",+ "fcc-claude",+ "fcc-codex",+ "fcc-pi",+ "fcc-init",+ "free-claude-code",+)+def _repo_root() -> Path:return Path(__file__).resolve().parents[2]@@ -71,6 +80,9 @@ def _posix_uv_command(version: str) -> str:return f"""#!/bin/shecho "uv:$*" >> "$CALL_LOG"if [ "${{1:-}}" = "--version" ]; then+ if [ "${{FCC_RUNNING_PHASE:-}}" = "late" ]; then+ : > "$FCC_PROCESS_MARKER"+ fiif [ "$FAIL_STEP" = "uv-verify" ]; thenexit 32fi@@ -128,6 +140,22 @@ class PosixHarness:def add_uv(self, version: str) -> None:_write_executable(self.bin_dir / "uv", _posix_uv_command(version))+ def use_process_list_fallback(self, process_line: str) -> None:+ fallback_bin = self.root / "fallback-bin"+ fallback_bin.mkdir()+ _write_executable(+ fallback_bin / "ps",+ """#!/bin/sh+printf '%s\n' "$FCC_PS_OUTPUT"+""",+ )+ awk = shutil.which("awk", path=self.env["PATH"])+ if awk is None:+ pytest.skip("awk is required for the POSIX process fallback scenario")+ shutil.copy2(awk, fallback_bin / "awk")+ self.env["FCC_PS_OUTPUT"] = process_line+ self.env["PATH"] = str(fallback_bin)+def run(self, *args: str, fail_step: str = "") -> subprocess.CompletedProcess[str]:env = self.env | {"FAIL_STEP": fail_step}return subprocess.run(@@ -157,6 +185,19 @@ def posix_harness(tmp_path: Path) -> PosixHarness:for path in (bin_dir, fixtures, tool_bin, home):path.mkdir(parents=True)+ _write_executable(+ bin_dir / "pgrep",+ """#!/bin/sh+[ -n "${FCC_RUNNING_COMMAND:-}" ] || exit 1+if [ "${FCC_RUNNING_PHASE:-early}" = "late" ] && [ ! -e "$FCC_PROCESS_MARKER" ]; then+ exit 1+fi+case "$*" in+ *"$FCC_RUNNING_COMMAND"*) printf '4242\n'; exit 0 ;;+ *) exit 1 ;;+esac+""",+ )_write_executable(bin_dir / "curl","""#!/bin/sh@@ -261,6 +302,9 @@ fi"CALL_LOG": str(log),"FAKE_FIXTURES": str(fixtures),"FAKE_TOOL_BIN": str(tool_bin),+ "FCC_PROCESS_MARKER": str(tmp_path / "fcc-process-ready"),+ "FCC_RUNNING_COMMAND": "",+ "FCC_RUNNING_PHASE": "early","FAIL_STEP": "",})@@ -482,6 +526,68 @@ def test_install_sh_rejects_invalid_options_before_mutation(assert posix_harness.calls() == [][email protected]("command_name", FCC_COMMANDS)+def test_install_sh_rejects_running_fcc_before_mutation(+ posix_harness: PosixHarness,+ command_name: str,+) -> None:+ posix_harness.env["FCC_RUNNING_COMMAND"] = command_name++ result = posix_harness.run()++ assert result.returncode != 0+ assert posix_harness.calls() == []+ assert f"{command_name} (PID 4242)" in result.stderr+++def test_install_sh_rechecks_for_fcc_process_before_tool_replacement(+ posix_harness: PosixHarness,+) -> None:+ posix_harness.add_client("claude")+ posix_harness.add_client("codex")+ posix_harness.add_client("pi")+ posix_harness.add_uv("0.11.16")+ posix_harness.env["FCC_RUNNING_COMMAND"] = "fcc-server"+ posix_harness.env["FCC_RUNNING_PHASE"] = "late"++ result = posix_harness.run()++ assert result.returncode != 0+ assert "fcc-server (PID 4242)" in result.stderr+ assert not any(call.startswith("uv:tool install") for call in posix_harness.calls())+++def test_install_sh_ignores_similarly_named_process(+ posix_harness: PosixHarness,+) -> None:+ posix_harness.env["FCC_RUNNING_COMMAND"] = "fcc-server-helper"++ result = posix_harness.run()++ assert result.returncode == 0, result.stderr+++ ("command_name", "process_args"),+ (+ ("free-claude-code", "/home/user/.local/bin/free-claude-code"),+ ("fcc-server", "/usr/bin/python3 /home/user/.local/bin/fcc-server"),+ ),+)+def test_install_sh_process_fallback_reads_full_command_line(+ posix_harness: PosixHarness,+ command_name: str,+ process_args: str,+) -> None:+ posix_harness.use_process_list_fallback(f"4242 {process_args}")++ result = posix_harness.run()++ assert result.returncode != 0+ assert posix_harness.calls() == []+ assert f"{command_name} (PID 4242)" in result.stderr++def _powershells() -> tuple[str, ...]:candidates = (shutil.which("pwsh"), shutil.which("powershell"))return tuple(dict.fromkeys(path for path in candidates if path is not None))@@ -523,6 +629,7 @@ if "%1"=="tool" if "%2"=="update-shell" goto update_shellif "%1"=="tool" if "%2"=="dir" if "%3"=="--bin" goto tool_binexit /b 59:version+if "%FCC_RUNNING_PHASE%"=="late" type nul > "%FCC_PROCESS_MARKER%"if "%FAIL_STEP%"=="uv-verify" exit /b 52echo uv {version}exit /b 0@@ -703,6 +810,25 @@ function Invoke-RestMethod {}Copy-Item -LiteralPath $source -Destination $OutFile -Force}+function Get-Process {+ [CmdletBinding()]+ param([string[]] $Name)++ if ([string]::IsNullOrWhiteSpace($env:FCC_RUNNING_COMMAND)) {+ return+ }+ if (+ $env:FCC_RUNNING_PHASE -eq "late" -and+ -not (Test-Path -LiteralPath $env:FCC_PROCESS_MARKER)+ ) {+ return+ }+ foreach ($requestedName in $Name) {+ if ($requestedName -eq $env:FCC_RUNNING_COMMAND) {+ [pscustomobject] @{ Id = 4242; ProcessName = $requestedName }+ }+ }+}$installer = [scriptblock]::Create([IO.File]::ReadAllText($env:FCC_INSTALLER))& $installer @args""",@@ -724,6 +850,9 @@ $installer = [scriptblock]::Create([IO.File]::ReadAllText($env:FCC_INSTALLER))"FAKE_FIXTURES": str(fixtures),"FAKE_TOOL_BIN": str(tool_bin),"FCC_INSTALLER": str(_repo_root() / "scripts" / "install.ps1"),+ "FCC_PROCESS_MARKER": str(tmp_path / "fcc-process-ready"),+ "FCC_RUNNING_COMMAND": "",+ "FCC_RUNNING_PHASE": "early","FAIL_STEP": "",})@@ -955,11 +1084,56 @@ def test_install_ps1_voice_flags_only_change_fcc_spec()[email protected]("command_name", FCC_COMMANDS)+def test_install_ps1_rejects_running_fcc_before_mutation(+ powershell_harness: PowerShellHarness,+ command_name: str,+) -> None:+ powershell_harness.env["FCC_RUNNING_COMMAND"] = command_name++ result = powershell_harness.run()++ assert result.returncode != 0+ assert powershell_harness.calls() == []+ assert f"{command_name} (PID 4242)" in result.stderr+++def test_install_ps1_rechecks_for_fcc_process_before_tool_replacement(+ powershell_harness: PowerShellHarness,+) -> None:+ powershell_harness.add_client("claude")+ powershell_harness.add_client("codex")+ powershell_harness.add_client("pi")+ powershell_harness.add_uv("0.11.16")+ powershell_harness.env["FCC_RUNNING_COMMAND"] = "fcc-server"+ powershell_harness.env["FCC_RUNNING_PHASE"] = "late"++ result = powershell_harness.run()++ assert result.returncode != 0+ assert "fcc-server (PID 4242)" in result.stderr+ assert not any(+ call.startswith("uv:tool install") for call in powershell_harness.calls()+ )+++def test_install_ps1_ignores_similarly_named_process(+ powershell_harness: PowerShellHarness,+) -> None:+ powershell_harness.env["FCC_RUNNING_COMMAND"] = "fcc-server-helper"++ result = powershell_harness.run()++ assert result.returncode == 0, result.stderr++def test_installers_use_native_clients_and_single_python_selection() -> None:shell = (_repo_root() / "scripts" / "install.sh").read_text(encoding="utf-8")powershell = (_repo_root() / "scripts" / "install.ps1").read_text(encoding="utf-8")for text in (shell, powershell):+ for command_name in FCC_COMMANDS:+ assert command_name in textassert "@anthropic-ai/claude-code" not in textassert "@openai/codex" not in textassert "@earendil-works/pi-coding-agent" not in textdiff --git a/tests/scripts/test_uninstallers.py b/tests/scripts/test_uninstallers.pyindex ebe2287c..33f333af 100644--- a/tests/scripts/test_uninstallers.py+++ b/tests/scripts/test_uninstallers.py@@ -66,6 +66,22 @@ class PosixUninstallHarness:for name in FCC_COMMANDS:(self.tool_bin / name).unlink(missing_ok=True)+ def use_process_list_fallback(self, process_line: str) -> None:+ fallback_bin = self.home.parent / "fallback-bin"+ fallback_bin.mkdir()+ _write_executable(+ fallback_bin / "ps",+ """#!/bin/sh+printf '%s\n' "$FCC_PS_OUTPUT"+""",+ )+ awk = shutil.which("awk", path=self.env["PATH"])+ if awk is None:+ pytest.skip("awk is required for the POSIX process fallback scenario")+ shutil.copy2(awk, fallback_bin / "awk")+ self.env["FCC_PS_OUTPUT"] = process_line+ self.env["PATH"] = str(fallback_bin)+@pytest.fixturedef posix_uninstall_harness(tmp_path: Path) -> PosixUninstallHarness:@@ -237,6 +253,28 @@ def test_uninstall_sh_rejects_invalid_options_before_mutation(assert posix_uninstall_harness.calls() == []+ ("command_name", "process_args"),+ (+ ("free-claude-code", "/home/user/.local/bin/free-claude-code"),+ ("fcc-server", "/usr/bin/python3 /home/user/.local/bin/fcc-server"),+ ),+)+def test_uninstall_sh_process_fallback_reads_full_command_line(+ posix_uninstall_harness: PosixUninstallHarness,+ command_name: str,+ process_args: str,+) -> None:+ posix_uninstall_harness.use_process_list_fallback(f"4242 {process_args}")++ result = posix_uninstall_harness.run()++ assert result.returncode != 0+ assert posix_uninstall_harness.fcc_home.exists()+ assert posix_uninstall_harness.calls() == []+ assert command_name in result.stderr++@dataclassclass PowerShellUninstallHarness:home: Pathdiff --git a/uv.lock b/uv.lockindex 11bee666..1d2b1e92 100644--- a/uv.lock+++ b/uv.lock@@ -570,7 +570,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "4.8.7"+version = "4.8.8"source = { editable = "." }dependencies = [{ name = "aiohttp" },