Background International Classification of Diseases (ICD) codes are widely used for reimbursement, health-service planning, and disease surveillance. Automated systems can identify diagnoses and supporting evidence across clinical documents. Yet coding is more than finding diagnoses. Decisions based on isolated information may not fully reflect the evolving clinical picture during admission. Provisional, superseded, or conflicting diagnoses can therefore persist in the final code set, complicating review and correction. We therefore developed and evaluated Clinico, a coding agent that organises evidence by time and clinical relationships to adjudicate diagnoses and update their status during admission. Methods We did a retrospective multicentre study with internal and external validation using inpatient records from two Shanghai hospitals. Routine coder-finalised codes served as references. Using 5,000 development stays, we refined Clinico's prompts and workflow without fine-tuning model parameters. We compared Clinico with three prespecified comparators, two trained on 80,340 stays. Clinico maintained an evidence-linked diagnostic ledger across each admission and reconciled related or conflicting claims before finalising the code set and selecting the principal diagnosis. The primary outcome was principal-diagnosis exact-match agreement; complete code-set micro-F1 was the key secondary outcome. Findings Evaluation included 5,000 internal and 4,109 external test stays. Principal-diagnosis exact-match agreement was 83.6% (95% CI 82.6-84.6) internally and 52.0% (50.5-53.5) externally; the next-highest observed estimates were 74.7% and 31.5%. Complete code-set micro-F1 was 90.6% (95% CI 90.2-91.0) internally and 42.6% (42.0-43.2) externally; the next-highest observed estimates were 90.3% and 25.5%. Interpretation In both hospital test sets, Clinico had the highest observed estimates of principal-diagnosis agreement and complete code-set micro-F1 among evaluated methods. Its longitudinal adjudication process links decisions to source evidence, allowing them to be checked against the record. Prospective studies should assess its effects in clinical workflows using independently adjudicated references. Funding None.