# Where to Find the Entry Points for the OpenCodeReview Application

> Discover OpenCodeReview application entry points. Find the Go binary launch at cmd/opencodereview/main.go and the npm installation at bin/ocr.js.

- Repository: [Alibaba/open-code-review](https://github.com/alibaba/open-code-review)
- Tags: getting-started
- Published: 2026-08-04

---

**The OpenCodeReview application launches through [`cmd/opencodereview/main.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/main.go) for the native Go binary, while npm installations use [`bin/ocr.js`](https://github.com/alibaba/open-code-review/blob/main/bin/ocr.js) as a Node.js wrapper that forwards arguments to the compiled binary.**

The alibaba/open-code-review repository provides a native Go CLI with an optional Node.js wrapper for easy npm installation. Understanding where the entry points for the open-code-review application reside is essential for developers contributing to the codebase or integrating the tool into custom workflows. The application follows a standard Cobra CLI pattern with distinct launch paths for direct binary execution and package manager distribution.

## Go Binary Entry Point (cmd/opencodereview/main.go)

The primary entry point for the compiled application is [`cmd/opencodereview/main.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/main.go). This file contains the `main()` function that initializes core subsystems before delegating to the command router.

### Initialization Sequence

When the binary starts, [`main.go`](https://github.com/alibaba/open-code-review/blob/main/main.go) performs several critical setup operations:

1. It sets the LLM application version via `llm.AppVersion = Version`.
2. It initializes the embedded resource loader with `llm.InitEmbeddedLoader()`.
3. It starts telemetry collection using `telemetry.Init(ctx)`.
4. Finally, it executes the root Cobra command via `rootCmd.Execute()`.

### Main Function Implementation

```go
func main() {
    llm.AppVersion = Version
    llm.InitEmbeddedLoader()

    ctx := context.Background()
    if telemetry.Init(ctx) {
        defer telemetry.ShutdownWithTimeout(ctx, 5*time.Second)
    }

    if err := rootCmd.Execute(); err != nil {
        fmt.Fprintf(os.Stderr, "Error: %v\n", err)
        os.Exit(1)
    }
}

```

## CLI Command Structure (cmd/opencodereview/root.go)

The command hierarchy is defined in [`cmd/opencodereview/root.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/root.go), which constructs the top-level `ocr` command and registers all functional sub-commands.

### Root Command Definition

The `rootCmd` variable in [`root.go`](https://github.com/alibaba/open-code-review/blob/main/root.go) serves as the central hub that parses global flags, handles `--version` requests, and displays help text when invoked without arguments. During the package initialization phase, the `init()` function attaches all sub-commands to this root command.

### Sub-Command Registration

Individual features are implemented in separate files under `cmd/opencodereview/`:

- [`review_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/review_cmd.go) implements the `review` sub-command.
- [`scan_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/scan_cmd.go) implements the `scan` sub-command.
- [`delegate_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/delegate_cmd.go) and others provide additional functionality.

Each file defines its command structure and registers it with `rootCmd` during the `init()` phase.

## Node.js Wrapper for npm Distribution (bin/ocr.js)

For users installing via npm (`npm i -g @alibaba-group/open-code-review`), the entry point shifts to [`bin/ocr.js`](https://github.com/alibaba/open-code-review/blob/main/bin/ocr.js). This wrapper abstracts the Go build process and provides a seamless JavaScript interface to the native binary.

### Binary Resolution and Execution

The wrapper uses [`scripts/platform.js`](https://github.com/alibaba/open-code-review/blob/main/scripts/platform.js) to locate the appropriate compiled binary for the current operating system. It then forwards all CLI arguments using `child_process.spawnSync`:

```javascript
const result = spawnSync(binaryPath, process.argv.slice(2), {
  stdio: "inherit",
  env: process.env,
});
process.exit(result.status ?? (result.error ? 1 : 0));

```

This design allows users to run `ocr review` or `ocr scan` commands without manually managing Go dependencies or compilation steps.

## Complete Execution Flow

The full launch path varies by installation method.

**Direct Go Build:**

```bash
go build -o ocr ./cmd/opencodereview
./ocr --help

```

**npm Installation:**

```bash
npm i -g @alibaba-group/open-code-review
ocr review --path ./src

```

The execution chain follows this pattern:

```

npm install → bin/ocr.js (Node wrapper) → resolves native binary → binary executes main.go → rootCmd → requested sub-command

```

## Summary

- The **Go entry point** is located at [`cmd/opencodereview/main.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/main.go), which initializes LLM components and telemetry before executing the root command.
- **Command routing** happens in [`cmd/opencodereview/root.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/root.go), where the `ocr` CLI and all sub-commands (review, scan, session) are defined.
- **Sub-command implementations** reside in individual files like [`review_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/review_cmd.go) and [`scan_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/scan_cmd.go) within the `cmd/opencodereview/` directory.
- The **npm wrapper entry point** at [`bin/ocr.js`](https://github.com/alibaba/open-code-review/blob/main/bin/ocr.js) locates the native binary and forwards arguments, enabling distribution without requiring Go toolchain installation.
- Both paths ultimately converge on the same Cobra command structure defined in the Go source code.

## Frequently Asked Questions

### What is the main entry point when building OpenCodeReview from source?

When compiling from source, the entry point is [`cmd/opencodereview/main.go`](https://github.com/alibaba/open-code-review/blob/main/cmd/opencodereview/main.go). This file contains the `main()` function that sets the application version, initializes the embedded loader, starts telemetry, and invokes `rootCmd.Execute()` to begin command processing.

### How does the npm package execute the Go binary without requiring users to install Go?

The npm package includes a pre-compiled native binary and a Node.js wrapper script at [`bin/ocr.js`](https://github.com/alibaba/open-code-review/blob/main/bin/ocr.js). When users run the `ocr` command, the wrapper locates the platform-specific binary using [`scripts/platform.js`](https://github.com/alibaba/open-code-review/blob/main/scripts/platform.js) and spawns it with `child_process.spawnSync()`, forwarding all arguments transparently.

### Where are the sub-commands like `review` and `scan` defined in the codebase?

Sub-commands are defined in separate files within the `cmd/opencodereview/` directory. For example, [`review_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/review_cmd.go) implements the review functionality and [`scan_cmd.go`](https://github.com/alibaba/open-code-review/blob/main/scan_cmd.go) handles scanning operations. Each file registers its command with the root command during the `init()` phase in [`root.go`](https://github.com/alibaba/open-code-review/blob/main/root.go).

### Can I run the OpenCodeReview CLI without using the npm wrapper?

Yes, you can build and run the Go binary directly. Clone the repository, run `go build -o ocr ./cmd/opencodereview`, and execute `./ocr` with your desired sub-commands. This approach bypasses the Node.js wrapper entirely and is useful for development or environments without Node.js installed.