Code Scanning
recon scan walks a repository and finds HTTP and RPC routes, the request and response types (DTOs) they use, and the exact file:line of each handler. Use it to see which endpoints your code exposes, to link .http requests to their handlers, and as the input for drift detection.
Scan a repository
Section titled “Scan a repository”Run it from the workspace root, or pass a directory:
recon scan✓ Scanned 4 file(s): 7 route(s), 3 DTO(s) (axum, fastapi, nextjs, openapi) POST /v2/enrollments [fastapi] py/main.py:10 GET /v1/students [axum] server/src/routes.rs:16 DELETE /v1/students/{id} [axum] server/src/routes.rs:17 GET /v1/students/{id} [axum] server/src/routes.rs:17 GET /admin/stats [axum] server/src/routes.rs:18 GET /v1/courses [openapi] specs/openapi.yaml:6 GET /api/courses/{id} [nextjs] web/app/api/courses/[id]/route.ts:7This workspace has an axum router in server/src/routes.rs, a FastAPI handler in py/main.py, a Next.js route handler in web/app/api/courses/[id]/route.ts, and an OpenAPI file in specs/openapi.yaml. The axum file contains:
pub fn router() -> Router { Router::new() .route("/v1/students", get(list_students)) .route("/v1/students/{id}", get(get_student).delete(delete_student)) .nest("/admin", Router::new().route("/stats", get(stats)))}Link requests to handlers
Section titled “Link requests to handlers”Add --sync to write the handler location into your .http files and to create requests for routes you have not covered yet:
recon scan --sync✓ Scanned 4 file(s): 7 route(s), 3 DTO(s) (axum, fastapi, nextjs, openapi)...Sync: 1 existing updated, 6 new route(s) writtenThe List Students request matched GET /v1/students, so it gained a # @handler line:
### List Students (PII Airlock + Twin-Run Drift Demo)### List Students# @name List Students# @folder Campus SIS# @handler server/src/routes.rs:16# @assert status == 200# @assert jsonpath $.students[0].program == MDivGET {{base_url}}/v1/studentsThe other six routes went into collections/discovered.http:
### create_enrollment# @name create_enrollment# @folder Code (fastapi)# @handler py/main.py:10# @assert status in 200..299POST {{base_url}}/v2/enrollmentsContent-Type: application/json
{ "course": "", "student_id": ""}
### delete_student# @name delete_student# @folder Code (axum)# @handler server/src/routes.rs:17# @assert status in 200..299DELETE {{base_url}}/v1/students/{id}...A second recon scan --sync changes nothing:
{"added_new": 0, "modified_files": [], "updated_existing": 0}What gets scanned
Section titled “What gets scanned”Recon walks the directory recursively.
- It honours
.gitignorefiles in the repository. It does not read your global Git ignore file. - Hidden files and directories are included.
- These directories are always skipped:
.git,node_modules,target,dist,build,_build,.recon,vendor,.next,.venv,__pycache__. - Files larger than 1,048,576 bytes (1 MiB) are skipped.
- Files that are not valid UTF-8 are skipped.
- Files are picked by extension. The match is case-insensitive.
| Extensions | Scanner |
|---|---|
ts, tsx, js, jsx, mts, cts, mjs, cjs |
TypeScript and JavaScript |
py |
Python |
rs |
Rust |
go |
Go |
ex, exs |
Elixir and Phoenix |
rb |
Ruby and Rails |
mo |
Mo and Arvo |
yaml, yml, json, graphql, gql, proto |
Spec files |
files_scanned counts every file with a supported extension that Recon could read, even if it held no routes. Every .json and .yaml file in the tree counts, including capsules and contracts.
After scanning, Recon removes duplicate routes with the same method, path, file and line. Routes are sorted by file, line, path and method. DTOs are sorted by file, line and name.
Path normalisation
Section titled “Path normalisation”Every route path is converted to one form so that paths from different frameworks can be compared. The original string is kept in raw_path.
- A
#fragment and a?query are removed. - A
scheme://host:portprefix is removed. - A leading template variable such as
{{base_url}}is removed. - Empty segments are dropped. The result starts with
/. - Each segment is converted:
| Written as | Becomes |
|---|---|
[id], [...slug], [[...slug]] |
{id}, {slug} |
<id>, <int:id> |
{id} |
:id, :id(\d+) |
{id} (text from ( on is dropped) |
{id}, {id:int}, {*rest} |
{id}, {rest} |
Two paths match when they have the same number of segments and each pair of segments is equal, or one of them is a {param} or a {{template}} segment. {{base_url}}/v1/students matches /v1/students. /bills/{id}/pay does not match /bills/42.
Scanners
Section titled “Scanners”TypeScript and JavaScript
Section titled “TypeScript and JavaScript”Files ending in .tsx or .jsx are parsed with the TSX grammar. All other script files use the TypeScript grammar, including .js.
Next.js App Router. A file whose name starts with route. (for example route.ts) and that sits below a directory named app is a route handler. The path is the directories between app and the file. Route groups such as (marketing) are dropped. Each exported function or const named after an HTTP verb (GET, POST and so on) becomes a route with framework nextjs.
Method calls. Any call of the form something.get('/path', handler) becomes a route. This works for get, post, put, patch, delete, del, head and options. The first argument must be a string that starts with / or is empty. The handler name is recorded only when the second argument is a plain identifier. If the file calls .basePath('/prefix'), the first such prefix is added to every route in the file.
The framework label comes from the file contents, checked in this order:
| Condition | Framework |
|---|---|
Contains from 'hono', from "hono" or new Hono |
hono |
Contains fastify or Fastify |
fastify |
Contains express |
express |
| Otherwise | typescript |
Fastify route objects. fastify.route({ method: 'GET', url: '/v1/users' }) becomes a route with framework fastify. path works in place of url.
DTOs. Interfaces, object type aliases and const X = z.object({ ... }) Zod schemas. A field marked ?: or with an optional type is not required. For Zod fields, .optional() or .nullable() makes the field not required. Zod types map to number (or integer with .int()), boolean, array, object, or string for anything else.
Python
Section titled “Python”| Pattern | Framework | Notes |
|---|---|---|
@x.route("/p", methods=[...]) |
flask |
Defaults to GET when methods is absent. |
@x.get("/p"), @x.post("/p") and other verbs |
fastapi |
|
path(...), re_path(...), url(...) |
django |
Always GET. The second argument is the handler. Calls containing include( are skipped. |
For decorated functions:
response_dtocomes from aresponse_model=argument, or else from the return annotation.list[...],List[...]andOptional[...]are unwrapped. Primitive types are ignored.request_dtois the type of the first parameter that is notself,cls,requestorreq, has noDepends(, and has a non-primitive type starting with an uppercase letter.auth_hintisFastAPI Dependswhen the parameters containDepends(.
DTOs are classes that inherit from something containing BaseModel or Schema, and classes decorated with @dataclass. A field is required when it has no default (a default of Field(...) still counts as required) and its type is not optional.
Attribute macros. #[get("/p")], #[post("/p")] and the other verbs, and #[route("/p", method = "GET")], become routes with framework actix. When the macro arguments contain data = or format =, the framework is rocket. The line is the attribute’s line.
axum. Router chains are read inside function bodies.
.route("/p", ...)and.route_service("/p", ...)add routes..nest("/prefix", ...)and.nest_service(...)add a path prefix to the inner router..merge(...)is followed.- Method handlers are recognised as
get(h),routing::post(h), the_serviceand_handlerforms, chained calls such asget(a).delete(b), and.to(h). - Each method handler becomes its own route, at the line of the handler call.
- A route with no recognised method handler becomes
GET.
DTOs. Structs that are pub or that derive Serialize, Deserialize or JsonSchema, and that have named fields.
- A field
#[serde(rename = "x")]sets the wire name. - A struct
#[serde(rename_all = "...")]is honoured forcamelCase,lowercaseandUPPERCASE. Other casings leave names unchanged. - Fields with
#[serde(skip)]orskip_serializingare left out. - A field is not required when its type is
Option<...>or its attributes containdefault.
The framework comes from the file’s imports: go-chi/chi gives chi, gin-gonic/gin gives gin, labstack/echo gives echo, and anything else gives net/http.
- Calls such as
r.Get("/p", h)orr.GET("/p", h)with a string first argument. HandleFuncandHandle. The pattern may include a method, as in"POST /v1/items". Without one the route isGET.- chi
r.Route("/prefix", func(r chi.Router) { ... })nests routes. chir.Method("GET", "/p", h)is supported. g := r.Group("/prefix")and.With(...)assignments set a prefix for calls on that variable.
DTOs are struct types. The json:"name" tag sets the wire name, json:"-" skips the field, and omitempty or a pointer type makes the field not required.
Elixir and Phoenix
Section titled “Elixir and Phoenix”scope "/p"(orscope path: "/p") adds a prefix.pipe_through :apisetsauth_hinttopipe_through ...for routes in that scope.get "/p", Controller, :actionand the other verbs. The handler isController.action.live "/p", ...becomesGET.resources "/items", Controllercreatesindex(GET /items),show(GET /items/:id),create(POST),update(PATCH) anddelete(DELETE).only:andexcept:filter the list. Nested resources use/:{singular}_id, where the singular form drops a trailings. NoPUT,neworeditroutes are generated.
DTOs come from Ecto schema "table" and embedded_schema blocks and Ash attributes blocks. An Ecto DTO is named after the table, singularised and in PascalCase (student_records becomes StudentRecord). Without a table name it takes the module name. Only field calls are read, and every Ecto field is marked not required. In Ash, an attribute with allow_nil?: false is required, and uuid_primary_key adds a field.
Ruby and Rails
Section titled “Ruby and Rails”Every .rb file is scanned with the routes rules.
namespace :admin(orpath:),scopeanddrawadd prefixes.resources :itemscreatesindex,show,create,update(PATCH) anddestroy(DELETE).resource :item(singular) has noindex, and its item path is the base path.only:,except:,path:andcontroller:are honoured. The handler iscontroller#action. Nested resources use/:{singular}_id.match "/p", via: [:get, :post]. Withoutvia:the route isGET.get "/p", to: "c#a"andget "/p" => "c#a".
DTOs are classes with attribute :name, Type calls. A type that contains Optional makes the field not required.
Mo and Arvo
Section titled “Mo and Arvo”The .mo scanner reads files line by line. ## starts a comment, and so does # outside a quoted string.
- Inside an
api ... endblock, lines likeget "/path" Handlers.listbecome routes with frameworkarvo, at their source line. auth Namesetsauth_hintfor the following routes.scope "/p"adds a prefix.if,caseandforblocks are tracked so that theirendlines do not close theapiblock.struct Name ... enddefines a DTO fromfield: Typelines. Optional types make a field not required.fnandpub fnsignatures link handlers to DTOs. The request DTO is a parameter namedinput,bodyorpayload, or else the first uppercase type that is not in a fixed skip list (Api.Request,Sqlite.Database,SecureRandom,Clock,Env,ReadFiles,Int,Text,Bool,Float,Member,Option(Member),Option(Text),Option(Int)). The response DTO is the first type insideResult(...), unless it isApi.ResponseorUnit.- After all files are read, handlers are linked to DTOs defined in other
.mofiles. Only DTO names that the scan found are linked.
Spec files
Section titled “Spec files”OpenAPI and Swagger. A YAML or JSON file with a top-level openapi or swagger key. Each path and verb becomes a route with framework openapi. The handler name is the operationId. The request DTO comes from a $ref (or items.$ref) in the application/json request body. The response DTO comes from the 200 or 201 application/json response. The line is the first line in the file that contains the path string. Schemas with properties under components/schemas or definitions become DTOs.
MCP tool manifests. A YAML or JSON file with a top-level tools array. Each tool becomes POST /mcp/{name} with framework mcp.
GraphQL. type, input and extend type blocks. Each field of Query, Mutation or Subscription becomes POST /graphql/{field} with handler Type.field and the field’s return type as response_dto. Other types become DTOs. A ! makes a field required.
Protocol Buffers. rpc Name (Req) returns (Res) inside a service becomes POST /{package.Service}/{Name} with framework protobuf and handler Service.Name. Messages become DTOs. optional makes a field not required. repeated makes it an array.
A YAML or JSON file that does not parse, or that has none of these keys, is skipped without a warning.
Type mapping
Section titled “Type mapping”Each DTO field has a raw_type (as written) and a logical_type. Optional wrappers such as Option<T>, Optional[T], T | None and T? are removed first. Then the first matching rule applies:
| Logical type | Matches |
|---|---|
array |
Starts with Vec<, List<, List[, List(, Array< or [], ends with [], or contains repeated |
object |
Starts with HashMap<, BTreeMap<, IndexMap<, Map(, Map[, Dict[ or Record<, or is object, json, value or map |
integer |
i8 to i128, isize, u8 to u128, usize, int, int32, int64, uint32, uint64, sint32, sint64, integer, bigint, smallint, serial |
number |
f32, f64, float, float32, float64, double, decimal, number, numeric |
boolean |
bool, boolean |
date |
date, naivedate |
timestamp |
Contains datetime, timestamp, naive_datetime or utc_datetime, or is time.time |
string |
str, string, text, char, uuid, email, &str, bytes, id, binary_id, or contains string or text |
any |
any, unknown, interface{} |
object |
Anything else, such as a named struct |
Matching ignores case.
Output model
Section titled “Output model”With --format json or --format agent, the command prints {"scan": ..., "sync": ...}. sync is null without --sync. Keys inside are sorted.
Scan report
Section titled “Scan report”| Field | Description |
|---|---|
root |
The directory that was scanned. |
files_scanned |
Number of supported files read. |
frameworks_detected |
Sorted, distinct framework labels of the routes found. |
routes |
Array of routes. |
dtos |
Array of DTOs. |
warnings |
Non-fatal problems, such as a parser error in one file. |
{ "auth_hint": "FastAPI Depends", "framework": "fastapi", "handler_name": "create_enrollment", "id": "post-v2-enrollments-main:10", "location": { "file": "py/main.py", "line": 10, "symbol": "create_enrollment" }, "method": "POST", "path": "/v2/enrollments", "raw_path": "/v2/enrollments", "request_dto": "EnrollmentIn", "response_dto": "EnrollmentIn"}| Field | Description |
|---|---|
id |
{method}-{path slug}-{file stem}:{line}. The method is lowercase. Non-alphanumeric characters in the path become -. An empty slug becomes root. |
method |
HTTP method. |
path |
Normalised path. |
raw_path |
The path as written in the source. |
framework |
One of axum, actix, rocket, arvo, nextjs, hono, express, fastify, typescript, fastapi, flask, django, chi, gin, echo, net/http, phoenix, rails, openapi, graphql, protobuf, mcp. |
location |
file (relative, with / separators), line (1-based) and optional symbol. |
handler_name |
Handler or action name, when found. Omitted otherwise. |
auth_hint |
Auth or pipeline hint, when found. Omitted otherwise. |
request_dto, response_dto |
DTO names, when found. Omitted otherwise. |
{ "fields": [ { "logical_type": "string", "name": "student_id", "raw_type": "str", "required": true }, { "logical_type": "string", "name": "course", "raw_type": "str", "required": true } ], "language": "python", "location": { "file": "py/main.py", "line": 4, "symbol": "EnrollmentIn" }, "name": "EnrollmentIn"}language is one of rust, typescript, python, go, elixir, ruby, mo, openapi, graphql or protobuf.
--sync in detail
Section titled “--sync in detail”For each request in the workspace, Recon looks for a matching route:
- If the request already has a
# @handlertag and a route sits at that exactfile:line, that route matches. - Otherwise the first route with the same method and a matching path wins.
When the match gives a different file:line than the request has, Recon sets the tag and counts the request in updated_existing.
Each .http file that holds an updated request is written again in full from the parsed requests. Text that the parser does not keep is lost. In the example above, the free text after ### was replaced by the request name.
Then Recon adds every route that no request covers yet to {collections_dir}/discovered.http. A route is covered when a workspace request or an entry already in discovered.http has the same method and a matching path. Each new request has:
- A name equal to the handler name, or
METHOD pathwhen there is none. - A folder
Code ({framework}). - A
# @handlertag. - The URL
{{base_url}}followed by the normalised path. Path parameters stay as{id}. They are not Recon variables, so you need to edit them before you send the request. - The assertion
status in 200..299. - For
POST,PUT,PATCHandDELETE, a sample JSON body when the route has arequest_dtothat the scan found. Each field gets a placeholder:1for integers,1.0for numbers,false,[],{}, or""for anything else. AContent-Type: application/jsonheader is added with the body.
The sync object reports:
| Field | Description |
|---|---|
updated_existing |
Requests that received a new # @handler tag. |
added_new |
Requests added to discovered.http. |
generated_file |
Path of discovered.http when it was written. Omitted otherwise. |
modified_files |
Every .http file that was written. |
The # @handler directive
Section titled “The # @handler directive”The tag has the form # @handler path/to/file.rs:16. The file part is everything before the last :. The line must be a positive integer. Backslashes become /. Recon uses the tag to find the handler when it exports a capsule and when it matches requests during a later sync. See .http Request Files for the full directive list.
recon scan reference
Section titled “recon scan reference”recon scan [PATH] [--sync]| Argument | Default | Description |
|---|---|---|
PATH |
the --workspace directory |
Directory to scan. |
--sync |
off | Stamp # @handler tags and write discovered.http. Sync always uses the requests of the --workspace workspace, even when PATH points elsewhere. |
Human output prints a summary line, one line per route (method, path, [framework], file:line), and a Sync: line when --sync is set.
Errors and exit codes
Section titled “Errors and exit codes”recon scan exits 0 after a scan. A missing directory is not an error: the scan finds nothing and the reason is in warnings.
recon scan /nonexistent/path --format json{ "scan": { "dtos": [], "files_scanned": 0, "frameworks_detected": [], "root": "/nonexistent/path", "routes": [], "warnings": [ "walk warning: /nonexistent/path: IO error for operation on /nonexistent/path: No such file or directory (os error 2)" ] }, "sync": null}The human output for the same command is ✓ Scanned 0 file(s): 0 route(s), 0 DTO(s) (none), with no sign of the problem.
A per-file parser failure is added to warnings as file: parse error in ... and the scan continues. Errors while writing .http files during --sync stop the command with a scan I/O error at message and exit code 2.
Also available via
Section titled “Also available via”- MCP tool
recon_scan_codebasewith argumentspathandsync. See MCP Tools. - HTTP
POST /api/v1/scanwith{"path": "...", "sync": true}. Both fields are optional. The result is cached and used by the drift routes.GET /api/v1/routeslists routes. See HTTP API. - Web Studio command palette: “Scan Repository Codebase” and “Sync Code Routes to .http (# @handler)”.